comparison light8/Xfader.py @ 0:45b12307c695

Initial revision
author drewp
date Wed, 03 Jul 2002 09:37:57 +0000
parents
children f974a462133f
comparison
equal deleted inserted replaced
-1:000000000000 0:45b12307c695
1 from Tix import *
2 from __future__ import division
3
4 class Xfader(Canvas):
5 def __init__(self, scalelevelsIn):
6 global scalelevels
7 scalelevels=scalelevelsIn
8 self.checkbuttons={}
9 self.startcoord=None
10 def sub2(self,a,b):
11 return ( (a[0]-b[0]), (a[1]-b[1]))
12 def down(self,ev):
13 global scalelevels
14 self.startcoord=(ev.x,-ev.y)
15 self.startlevels = dict([(k,v.get()) for k,v in scalelevels.items()])
16 # find the channel names of the selected subs
17 self.onchannel = {
18 'x':[x for x in scalelevels.keys() if self.checkbuttons[x]['x'].get()],
19 'y':[x for x in scalelevels.keys() if self.checkbuttons[x]['y'].get()]
20 }
21
22
23 #self.create_line(0,0,100,100,tag='transient')
24
25 def getoriglevel(self,subname):
26 return self.startlevels[subname]
27 def up(self,ev):
28 self.startcoord=None
29 self.delete('transient')
30 # self.clearallbuttons()
31 def moved(self,ev):
32 if self.startcoord is None:
33 return
34 pos=(ev.x,-ev.y)
35 deltas= self.sub2(pos,self.startcoord)
36 for axis,delta in zip(('x','y'),deltas):
37 onchan=self.onchannel[axis]
38 for subn in onchan:
39 newlev = self.getoriglevel(subn) + 1.0*delta/75
40 newlev = int(newlev*1000)/1000.0
41 newlev = min(1.0,max(newlev,0.0))
42 scalelevels[subn].set( newlev )
43 def width(self):
44 return int(self['width'])
45 def height(self):
46 return int(self['height'])
47 def setupwidget(self,parent):
48 Canvas.__init__(self,parent,width=150,height=150,bg="grey40")
49 self.pack(side='bottom')
50 self.create_rectangle(5,5,self.width()-5,self.height()-5)
51 self.create_line(0,self.height()/2,150,self.height()/2)
52 self.create_line(self.width()/2,0,self.width()/2,self.height())
53 self.bind("<ButtonPress-1>",self.down)
54 self.bind("<ButtonRelease-1>",self.up)
55 self.bind("<B1-Motion>",self.moved)
56
57 def registerbutton(self,subname,axis,checkvar):
58 if subname not in self.checkbuttons:
59 self.checkbuttons[subname]={}
60 self.checkbuttons[subname][axis]=checkvar
61 def clearallbuttons(self, axis='both'):
62 for cb in self.checkbuttons.values():
63 if axis == 'both':
64 for a in cb.values():
65 a.set(0)
66 else:
67 cb[axis].set(0)
68 def grab(self,axis):
69 self.clearallbuttons(axis)
70 for n,sv in scalelevels.items():
71 if sv.get() and n != 'blacklight':
72 self.checkbuttons[n][axis].set(1)
73
74