Mercurial > code > home > repos > light9
changeset 290:50ba9ec2b17e
you can now delete curve points
author | drewp@bigasterisk.com |
---|---|
date | Sat, 18 Jun 2005 06:09:28 +0000 |
parents | 3b73f0a58a54 |
children | 6c3b487e7bbc |
files | bin/curvecalc light9/curve.py |
diffstat | 2 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/curvecalc Sat Jun 18 01:45:05 2005 +0000 +++ b/bin/curvecalc Sat Jun 18 06:09:28 2005 +0000 @@ -347,7 +347,7 @@ root.bind("<Control-Key-r>", lambda evt: dispatcher.send('reload all subs')) create_status_lines(root) -for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse", +for helpline in ["Bindings: C-s save subterms; B1 drag point; C-B1 curve add point; S-B1 sketch points; Del point under mouse; 1..5 add point at time; Esc see current time; S-Esc see curtime to end; Mousewheel zoom; C-p play/pause music at mouse", "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; curvename(t) eval curve"]: tk.Label(root,text=helpline, font="Helvetica -12 italic", anchor='w').pack(side='top',fill='x')
--- a/light9/curve.py Sat Jun 18 01:45:05 2005 +0000 +++ b/light9/curve.py Sat Jun 18 06:09:28 2005 +0000 @@ -71,6 +71,11 @@ dot = max(-1,min(1,dot)) return math.degrees(math.acos(dot)) +def slope(p1,p2): + if p2[0] == p1[0]: + return 0 + return (p2[1] - p1[1]) / (p2[0] - p1[0]) + class Sketch: """a sketch motion on a curveview, with temporary points while you draw, and simplification when you release""" @@ -117,10 +122,6 @@ self.curveview.update_curve() - def slope(self,p1,p2): - if p2[0] == p1[0]: - return 0 - return (p2[1] - p1[1]) / (p2[0] - p1[0]) class Curveview(tk.Canvas): def __init__(self,master,curve,**kw): @@ -302,11 +303,26 @@ lambda ev,i=i: self.dotmotion(ev,i)) self.bind("<ButtonRelease-1>", lambda ev,i=i: self.dotrelease(ev,i)) + #self.tag_bind('handle%d' % i, "<Key-d>", + # lambda ev, i=i: self.remove_point_idx(i)) + self.dots[i]=dot + def delpoint(ev): + # had a hard time tag_binding to the points, so i trap at + # the widget level (which might be nice anyway when there + # are multiple pts selected) + tags = self.gettags(self.find_closest(ev.x, ev.y)) + try: + handletags = [t for t in tags if t.startswith('handle')] + i = int(handletags[0][6:]) + except IndexError: + return + self.remove_point_idx(i) + self.bind("<Key-Delete>", delpoint) + self.highlight_selected_dots() - def newpointatmouse(self, ev): p = self.world_from_screen(ev.x,ev.y) x, y = p @@ -319,6 +335,10 @@ self.unselect() self.curve.insert_pt(p) self.update_curve() + + def remove_point_idx(self, i): + self.curve.points.pop(i) + self.update_curve() def highlight_selected_dots(self): for i,d in self.dots.items():