changeset 200:f5d3492981ab

moved Zoomcontrol to another file
author drewp
date Wed, 16 Jun 2004 13:12:07 +0000
parents cde2ae379be0
children e4a711d9a338
files flax/curvecalc
diffstat 1 files changed, 2 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/flax/curvecalc	Wed Jun 16 13:01:53 2004 +0000
+++ b/flax/curvecalc	Wed Jun 16 13:12:07 2004 +0000
@@ -17,6 +17,7 @@
 import Submaster
 from TLUtility import make_attributes_from_args
 
+from zoomcontrol import Zoomcontrol
 
 class Curve:
     """curve does not know its name. see Curveset"""
@@ -27,7 +28,7 @@
         self.points = [(0,0),(1,1),(9,1),(10,0)]
         for x in range(11,500):
             self.points.append((x,.5))
-        
+
     def eval(self,t):
         i = bisect_left(self.points,(t,None))-1
 
@@ -299,108 +300,6 @@
                            l.config(text=sn+": "+tf(val)),
                            signame,weak=0)
 
-class Zoomcontrol(object,tk.Canvas):
-
-    def maxtime():
-        doc = "seconds at the right edge of the bar"
-        def fget(self): return self._maxtime
-        def fset(self, value):
-            self._maxtime = value
-            self.updatewidget()
-        return locals()
-    maxtime = property(**maxtime())
-    
-    def start():
-        def fget(self): return self._start
-        def fset(self,v): self._start = max(0,v)
-        return locals()
-    start = property(**start())
-
-    def end():
-        def fget(self): return self._end
-        def fset(self,v): self._end = min(self.maxtime,v)
-        return locals()
-    end = property(**end())
-        
-
-    def __init__(self,master,**kw):
-        self.maxtime=370
-        self.start=0
-        self.end=20
-        tk.Canvas.__init__(self,master,width=250,height=30,
-                           relief='raised',bd=1,bg='gray60',**kw)
-        self.leftbrack = self.create_line(0,0,0,0,0,0,0,0,width=5)
-        self.rightbrack = self.create_line(0,0,0,0,0,0,0,0,width=5)
-        self.shade = self.create_rectangle(0,0,0,0,fill='gray70',outline=None)
-        self.time = self.create_line(0,0,0,0,fill='red',width=2)
-        self.updatewidget()
-        self.bind("<Configure>",self.updatewidget)
-
-        self.bind("<ButtonPress-1>",lambda ev: setattr(self,'lastx',ev.x))
-        self.tag_bind(self.leftbrack,"<B1-Motion>",
-                      lambda ev: self.adjust('start',ev))
-        self.tag_bind(self.rightbrack,"<B1-Motion>",
-                      lambda ev: self.adjust('end',ev))
-        self.tag_bind(self.shade,"<B1-Motion>",
-                      lambda ev: self.adjust('offset',ev))
-        dispatcher.connect(lambda: (self.start,self.end),"zoom area",weak=0)
-        dispatcher.connect(self.input_time,"input time")
-        dispatcher.connect(lambda maxtime: (setattr(self,'maxtime',maxtime),
-                                            self.updatewidget()),"max time",weak=0)
-        self.created=1
-    def input_time(self,val):
-        t=val
-        x=self.can_for_t(t)
-        self.coords(self.time,x,0,x,self.winfo_height())
-
-    def adjust(self,attr,ev):
-        if not hasattr(self,'lastx'):
-            return
-        new = self.can_for_t(getattr(self,attr)) + (ev.x - self.lastx)
-        self.lastx = ev.x
-        setattr(self,attr,self.t_for_can(new))
-        self.updatewidget()
-        dispatcher.send("zoom changed")
-        
-    def offset():
-        doc = "virtual attr that adjusts start and end together"
-        def fget(self):
-            return self.start
-        def fset(self, value):
-            d = self.end-self.start
-            self.start = value
-            self.end = self.start+d
-        return locals()
-    offset = property(**offset())
-
-    def can_for_t(self,t):
-        return t/self.maxtime*(self.winfo_width()-30)+20
-    def t_for_can(self,x):
-        return (x-20)/(self.winfo_width()-30)*self.maxtime
-
-    def updatewidget(self,*args):
-        """redraw pieces based on start/end"""
-        if not hasattr(self,'created'): return
-        y1,y2=3,self.winfo_height()-3
-        lip = 6
-        scan = self.can_for_t(self.start)
-        ecan = self.can_for_t(self.end)
-        self.coords(self.leftbrack,scan+lip,y1,scan,y1,scan,y2,scan+lip,y2)
-        self.coords(self.rightbrack,ecan-lip,y1,ecan,y1,ecan,y2,ecan-lip,y2)
-        self.coords(self.shade,scan+3,y1+lip,ecan-3,y2-lip)
-        self.delete("tics")
-        lastx=-1000
-        for t in range(0,int(self.maxtime)):
-            x = self.can_for_t(t)
-            if 0<x<self.winfo_width() and x-lastx>30:
-                txt=str(t)
-                if lastx==-1000:
-                    txt=txt+"sec"
-                self.create_line(x,0,x,15,
-                                 tags=('tics',))
-                self.create_text(x,self.winfo_height()-1,anchor='s',
-                                 text=txt,tags=('tics',),font='6x13')
-                lastx = x
 
 #######################################################################
 root=tk.Tk()