Mercurial > code > home > repos > light9
comparison flax/zoomcontrol.py @ 205:3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
author | drewp |
---|---|
date | Sun, 10 Apr 2005 15:03:24 +0000 |
parents | 45b12307c695 |
children |
comparison
equal
deleted
inserted
replaced
204:186a66095036 | 205:3905d3c92aaa |
---|---|
1 from __future__ import division | 1 from __future__ import division |
2 import Tkinter as tk | 2 import Tkinter as tk |
3 from dispatch import dispatcher | 3 from dispatch import dispatcher |
4 | 4 |
5 class Zoomcontrol(object,tk.Canvas): | 5 class Zoomcontrol(object,tk.Canvas): |
6 | |
7 mintime=-5 | |
6 | 8 |
7 def maxtime(): | 9 def maxtime(): |
8 doc = "seconds at the right edge of the bar" | 10 doc = "seconds at the right edge of the bar" |
9 def fget(self): return self._maxtime | 11 def fget(self): return self._maxtime |
10 def fset(self, value): | 12 def fset(self, value): |
13 return locals() | 15 return locals() |
14 maxtime = property(**maxtime()) | 16 maxtime = property(**maxtime()) |
15 | 17 |
16 def start(): | 18 def start(): |
17 def fget(self): return self._start | 19 def fget(self): return self._start |
18 def fset(self,v): self._start = max(0,v) | 20 def fset(self,v): self._start = max(self.mintime,v) |
19 return locals() | 21 return locals() |
20 start = property(**start()) | 22 start = property(**start()) |
21 | 23 |
22 def end(): | 24 def end(): |
23 def fget(self): return self._end | 25 def fget(self): return self._end |
37 self.shade = self.create_rectangle(0,0,0,0,fill='gray70',outline=None) | 39 self.shade = self.create_rectangle(0,0,0,0,fill='gray70',outline=None) |
38 self.time = self.create_line(0,0,0,0,fill='red',width=2) | 40 self.time = self.create_line(0,0,0,0,fill='red',width=2) |
39 self.updatewidget() | 41 self.updatewidget() |
40 self.bind("<Configure>",self.updatewidget) | 42 self.bind("<Configure>",self.updatewidget) |
41 | 43 |
42 self.bind("<ButtonPress-1>",lambda ev: setattr(self,'lastx',ev.x)) | 44 if 0: |
43 self.tag_bind(self.leftbrack,"<B1-Motion>", | 45 # works, but you have to stay in the widget while you drag |
44 lambda ev: self.adjust('start',ev)) | 46 self.bind("<ButtonPress-1>",self.press) |
45 self.tag_bind(self.rightbrack,"<B1-Motion>", | 47 self.tag_bind(self.leftbrack,"<B1-Motion>", |
46 lambda ev: self.adjust('end',ev)) | 48 lambda ev: self.adjust(ev,'start')) |
47 self.tag_bind(self.shade,"<B1-Motion>", | 49 self.tag_bind(self.rightbrack,"<B1-Motion>", |
48 lambda ev: self.adjust('offset',ev)) | 50 lambda ev: self.adjust(ev,'end')) |
51 self.tag_bind(self.shade,"<B1-Motion>", | |
52 lambda ev: self.adjust(ev,'offset')) | |
53 else: | |
54 # works better | |
55 # bind to buttonpress wasnt working, but Enter is good enough | |
56 self.tag_bind(self.leftbrack,"<Enter>", | |
57 lambda ev: self.press(ev,'start')) | |
58 self.tag_bind(self.shade,"<Enter>", | |
59 lambda ev: self.press(ev,'offset')) | |
60 self.tag_bind(self.rightbrack,"<Enter>", | |
61 lambda ev: self.press(ev,'end')) | |
62 self.bind("<B1-Motion>",self.adjust) | |
63 self.bind("<ButtonRelease-1>",self.release) | |
64 | |
49 dispatcher.connect(lambda: (self.start,self.end),"zoom area",weak=0) | 65 dispatcher.connect(lambda: (self.start,self.end),"zoom area",weak=0) |
50 dispatcher.connect(self.input_time,"input time") | 66 dispatcher.connect(self.input_time,"input time") |
51 dispatcher.connect(lambda maxtime: (setattr(self,'maxtime',maxtime), | 67 dispatcher.connect(lambda maxtime: (setattr(self,'maxtime',maxtime+15), |
52 self.updatewidget()),"max time",weak=0) | 68 self.updatewidget()), |
69 "max time",weak=0) | |
70 dispatcher.connect(self.zoom_about_mouse,"zoom about mouse") | |
71 dispatcher.connect(self.see_time,"see time") | |
53 self.created=1 | 72 self.created=1 |
73 def zoom_about_mouse(self,t,factor): | |
74 self.start = t - factor*(t-self.start) | |
75 self.end = t + factor*(self.end-t) | |
76 self.updatewidget() | |
77 dispatcher.send("zoom changed") | |
78 def see_time(self,t): | |
79 margin = (self.end-self.start)*.5 # centering is nicest | |
80 if t<self.start: | |
81 self.offset-=(self.start-t)+margin | |
82 if t>self.end: | |
83 self.offset+=(t-self.end)+margin | |
84 self.updatewidget() | |
85 dispatcher.send("zoom changed") | |
86 | |
54 def input_time(self,val): | 87 def input_time(self,val): |
55 t=val | 88 t=val |
56 x=self.can_for_t(t) | 89 x=self.can_for_t(t) |
57 self.coords(self.time,x,0,x,self.winfo_height()) | 90 self.coords(self.time,x,0,x,self.winfo_height()) |
91 def press(self,ev,attr): | |
92 self.adjustingattr = attr | |
93 | |
94 def release(self,ev): | |
95 if hasattr(self,'adjustingattr'): del self.adjustingattr | |
96 if hasattr(self,'lastx'): del self.lastx | |
97 def adjust(self,ev,attr=None): | |
58 | 98 |
59 def adjust(self,attr,ev): | 99 if not hasattr(self,'adjustingattr'): |
100 return | |
101 attr = self.adjustingattr | |
102 | |
60 if not hasattr(self,'lastx'): | 103 if not hasattr(self,'lastx'): |
61 return | 104 self.lastx = ev.x |
62 new = self.can_for_t(getattr(self,attr)) + (ev.x - self.lastx) | 105 new = self.can_for_t(getattr(self,attr)) + (ev.x - self.lastx) |
63 self.lastx = ev.x | 106 self.lastx = ev.x |
64 setattr(self,attr,self.t_for_can(new)) | 107 setattr(self,attr,self.t_for_can(new)) |
65 self.updatewidget() | 108 self.updatewidget() |
66 dispatcher.send("zoom changed") | 109 dispatcher.send("zoom changed") |
75 self.end = self.start+d | 118 self.end = self.start+d |
76 return locals() | 119 return locals() |
77 offset = property(**offset()) | 120 offset = property(**offset()) |
78 | 121 |
79 def can_for_t(self,t): | 122 def can_for_t(self,t): |
80 return t/self.maxtime*(self.winfo_width()-30)+20 | 123 return (t-self.mintime)/(self.maxtime-self.mintime)*(self.winfo_width()-30)+20 |
81 def t_for_can(self,x): | 124 def t_for_can(self,x): |
82 return (x-20)/(self.winfo_width()-30)*self.maxtime | 125 return (x-20)/(self.winfo_width()-30)*(self.maxtime-self.mintime)+self.mintime |
83 | 126 |
84 def updatewidget(self,*args): | 127 def updatewidget(self,*args): |
85 """redraw pieces based on start/end""" | 128 """redraw pieces based on start/end""" |
86 if not hasattr(self,'created'): return | 129 if not hasattr(self,'created'): return |
87 y1,y2=3,self.winfo_height()-3 | 130 y1,y2=3,self.winfo_height()-3 |
88 lip = 6 | 131 lip = 6 |
89 scan = self.can_for_t(self.start) | 132 scan = self.can_for_t(self.start) |
90 ecan = self.can_for_t(self.end) | 133 ecan = self.can_for_t(self.end) |
91 self.coords(self.leftbrack,scan+lip,y1,scan,y1,scan,y2,scan+lip,y2) | 134 self.coords(self.leftbrack,scan+lip,y1,scan,y1,scan,y2,scan+lip,y2) |
92 self.coords(self.rightbrack,ecan-lip,y1,ecan,y1,ecan,y2,ecan-lip,y2) | 135 self.coords(self.rightbrack,ecan-lip,y1,ecan,y1,ecan,y2,ecan-lip,y2) |
93 self.coords(self.shade,scan+3,y1+lip,ecan-3,y2-lip) | 136 self.coords(self.shade,scan+5,y1+lip,ecan-5,y2-lip) |
94 self.delete("tics") | 137 self.delete("tics") |
95 lastx=-1000 | 138 lastx=-1000 |
96 for t in range(0,int(self.maxtime)): | 139 for t in range(0,int(self.maxtime)): |
97 x = self.can_for_t(t) | 140 x = self.can_for_t(t) |
98 if 0<x<self.winfo_width() and x-lastx>30: | 141 if 0<x<self.winfo_width() and x-lastx>30: |