Changeset - 1064aceb158e
[Not reviewed]
default
0 3 0
Drew Perttula - 13 years ago 2012-06-12 06:11:20
drewp@bigasterisk.com
point deleting. when you add new points by c-click or sketch, they're immediately selected. c-click now always adds the point on the existing curve
Ignore-this: 3ba2223d46f73d348229ae0017add2ee
3 files changed with 37 insertions and 12 deletions:
0 comments (0 inline, 0 general)
light9/curvecalc/curve.py
Show inline comments
 
@@ -67,8 +67,10 @@ class Curve(object):
 
    __call__=eval
 

	
 
    def insert_pt(self,new_pt):
 
        """returns index of new point"""
 
        i = bisect(self.points,(new_pt[0],None))
 
        self.points.insert(i,new_pt)
 
        return i
 

	
 
    def indices_between(self, x1, x2, beyond=0):
 
        leftidx = max(0, bisect(self.points, (x1,None)) - beyond)
light9/curvecalc/curvecalc.glade
Show inline comments
 
@@ -92,6 +92,18 @@
 
                        <property name="use_stock">True</property>
 
                      </object>
 
                    </child>
 
                    <child>
 
                      <object class="GtkImageMenuItem" id="imagemenuitem6">
 
                        <property name="label">gtk-delete</property>
 
                        <property name="visible">True</property>
 
                        <property name="can_focus">False</property>
 
                        <property name="use_action_appearance">False</property>
 
                        <property name="use_underline">True</property>
 
                        <property name="use_stock">True</property>
 
                        <accelerator key="Delete" signal="activate"/>
 
                        <signal name="activate" handler="onDelete" swapped="no"/>
 
                      </object>
 
                    </child>
 
                  </object>
 
                </child>
 
              </object>
 
@@ -241,7 +253,7 @@
 
                        <property name="visible">True</property>
 
                        <property name="can_focus">False</property>
 
                        <property name="use_action_appearance">False</property>
 
                        <property name="label" translatable="yes">Delete (del)</property>
 
                        <property name="label" translatable="yes">Delete</property>
 
                        <property name="use_underline">True</property>
 
                      </object>
 
                    </child>
light9/curvecalc/curveview.py
Show inline comments
 
@@ -42,6 +42,7 @@ class Sketch:
 
    def release(self,ev):
 
        pts = self.pts
 
        pts.sort()
 
        finalPoints = pts[:]
 

	
 
        dx = .01
 
        to_remove = []
 
@@ -56,6 +57,7 @@ class Sketch:
 

	
 
        for i in to_remove:
 
            self.curveview.curve.points.remove(pts[i])
 
            finalPoints.remove(pts[i])
 

	
 
        # the simplified curve may now be too far away from some of
 
        # the points, so we'll put them back. this has an unfortunate
 
@@ -64,8 +66,10 @@ class Sketch:
 
            p = pts[i]
 
            if abs(self.curveview.curve(p[0]) - p[1]) > .1:
 
                self.curveview.add_point(p)
 
                finalPoints.append(p)
 
            
 
        self.curveview.update_curve()
 
        self.curveview.select_points(finalPoints)
 

	
 
class Curveview(object):
 
    """
 
@@ -164,8 +168,6 @@ class Curveview(object):
 
        else:
 
            self.select_press(event)
 

	
 
            
 

	
 
    def playPause(self):
 
        """
 
        user has pressed ctrl-p over a curve view, possibly this
 
@@ -224,6 +226,18 @@ class Curveview(object):
 
            self.selected_points[:] = []
 
            self.highlight_selected_dots()
 

	
 
    def select_points(self, pts):
 
        """set selection to the given point values (tuples, not indices)"""
 
        idxs = []
 
        for p in pts:
 
            idxs.append(self.curve.points.index(p))
 
        self.select_indices(idxs)
 

	
 
    def select_indices(self, idxs):
 
        """set selection to these point indices"""
 
        self.selected_points = idxs
 
        self.highlight_selected_dots()
 

	
 
    def select_press(self,ev):
 
        # todo: these select_ handlers are getting called on c-a-drag
 
        # zooms too. the dispatching should be more selective than
 
@@ -485,16 +499,14 @@ class Curveview(object):
 
        
 
    def new_point_at_mouse(self, ev):
 
        p = self.world_from_screen(ev.x,ev.y)
 
        x, y = p
 
        y = max(0, y)
 
        y = min(1, y)
 
        p = x, y
 
        self.add_point(p)
 
        x = p[0]
 
        y = self.curve.eval(x)
 
        self.add_point((x, y))
 

	
 
    def add_point(self, p):
 
        self.unselect()
 
        self.curve.insert_pt(p)
 
        i = self.curve.insert_pt(p)
 
        self.update_curve()
 
        self.select_indices([i])
 
        
 
    def remove_point_idx(self, *idxs):
 
        idxs = list(idxs)
 
@@ -539,8 +551,7 @@ class Curveview(object):
 
    def select_between(self,start,end):
 
        if start > end:
 
            start, end = end, start
 
        self.selected_points = self.curve.indices_between(start,end)
 
        self.highlight_selected_dots()
 
        self.select_indices(self.curve.indices_between(start,end))
 

	
 
    def onEnter(self, widget, event):
 
        self.entered = True
0 comments (0 inline, 0 general)