changeset 713:1064aceb158e

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
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 12 Jun 2012 06:11:20 +0000
parents d3dd982c3e32
children 1b1e6dc6cc74
files light9/curvecalc/curve.py light9/curvecalc/curvecalc.glade light9/curvecalc/curveview.py
diffstat 3 files changed, 37 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/light9/curvecalc/curve.py	Tue Jun 12 06:10:48 2012 +0000
+++ b/light9/curvecalc/curve.py	Tue Jun 12 06:11:20 2012 +0000
@@ -67,8 +67,10 @@
     __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)
--- a/light9/curvecalc/curvecalc.glade	Tue Jun 12 06:10:48 2012 +0000
+++ b/light9/curvecalc/curvecalc.glade	Tue Jun 12 06:11:20 2012 +0000
@@ -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>
--- a/light9/curvecalc/curveview.py	Tue Jun 12 06:10:48 2012 +0000
+++ b/light9/curvecalc/curveview.py	Tue Jun 12 06:11:20 2012 +0000
@@ -42,6 +42,7 @@
     def release(self,ev):
         pts = self.pts
         pts.sort()
+        finalPoints = pts[:]
 
         dx = .01
         to_remove = []
@@ -56,6 +57,7 @@
 
         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 @@
             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 @@
         else:
             self.select_press(event)
 
-            
-
     def playPause(self):
         """
         user has pressed ctrl-p over a curve view, possibly this
@@ -224,6 +226,18 @@
             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 @@
         
     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 @@
     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