Mercurial > code > home > repos > light9
annotate flax/dmxchanedit.py @ 207:2fdf1b0b0431 end of cvs imports
testing darcs
author | drewp@bigasterisk.com |
---|---|
date | Sun, 10 Apr 2005 07:30:41 +0000 |
parents | 3905d3c92aaa |
children |
rev | line source |
---|---|
0 | 1 """ |
2 | |
3 widget to show all dmx channel levels and allow editing. levels might | |
4 not actually match what dmxserver is outputting. | |
5 | |
6 """ | |
7 from __future__ import nested_scopes,division | |
8 import Tkinter as tk | |
9 import sys | |
10 sys.path.append("../light8") | |
11 import Patch | |
12 from uihelpers import make_frame, colorlabel, eventtoparent | |
201 | 13 from dispatch import dispatcher |
0 | 14 |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
15 stdfont = ('Arial', 12) |
0 | 16 |
17 class Onelevel(tk.Frame): | |
18 """a name/level pair""" | |
19 def __init__(self, parent, channelnum): | |
20 """channelnum is 1..68, like the real dmx""" | |
21 tk.Frame.__init__(self,parent) | |
22 | |
23 self.channelnum=channelnum | |
24 self.currentlevel=0 # the level we're displaying, 0..1 | |
25 | |
26 # 3 widgets, left-to-right: | |
27 | |
28 # channel number -- will turn yellow when being altered | |
29 self.num_lab = tk.Label(self, text=str(channelnum), | |
30 width=3, bg='grey40', | |
31 fg='white', font=stdfont, | |
32 padx=0, pady=0, bd=0, height=1) | |
33 self.num_lab.pack(side='left') | |
34 | |
35 # text description of channel | |
36 self.desc_lab=tk.Label(self, text=Patch.get_channel_name(channelnum), | |
167 | 37 width=14, font=stdfont, anchor='w', |
0 | 38 padx=0, pady=0, bd=0, |
39 height=1, bg='black', fg='white') | |
40 self.desc_lab.pack(side='left') | |
41 | |
42 # current level of channel, shows intensity with color | |
43 self.level_lab = tk.Label(self, width=3, bg='lightBlue', | |
44 font=stdfont, anchor='e', | |
45 padx=1, pady=0, bd=0, height=1) | |
46 self.level_lab.pack(side='left') | |
47 | |
48 self.setlevel(0) | |
49 self.setupmousebindings() | |
50 | |
51 def setupmousebindings(self): | |
52 def b1down(ev): | |
53 self.desc_lab.config(bg='cyan') | |
54 self._start_y=ev.y | |
55 self._start_lev=self.currentlevel | |
56 def b1motion(ev): | |
57 delta=self._start_y-ev.y | |
58 self.changelevel(self._start_lev+delta*.005) | |
59 def b1up(ev): | |
60 self.desc_lab.config(bg='black') | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
61 def b3up(ev): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
62 self.changelevel(0.0) |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
63 def b3down(ev): |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
64 self.changelevel(1.0) |
0 | 65 |
66 # make the buttons work in the child windows | |
67 for w in self.winfo_children(): | |
68 for e,func in (('<ButtonPress-1>',b1down), | |
69 ('<B1-Motion>',b1motion), | |
205
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
70 ('<ButtonRelease-1>',b1up), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
71 ('<ButtonRelease-3>', b3up), |
3905d3c92aaa
twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents:
201
diff
changeset
|
72 ('<ButtonPress-3>', b3down)): |
0 | 73 w.bind(e,func) |
74 # w.bind(e,lambda ev,e=e: eventtoparent(ev,e)) | |
75 | |
76 def colorlabel(self): | |
77 """color the level label based on its own text (which is 0..100)""" | |
78 txt=self.level_lab['text'] or "0" | |
79 lev=float(txt)/100 | |
80 low=(80,80,180) | |
81 high=(255,55,050) | |
82 out = [int(l+lev*(h-l)) for h,l in zip(high,low)] | |
83 col="#%02X%02X%02X" % tuple(out) | |
84 self.level_lab.config(bg=col) | |
85 | |
86 def setlevel(self,newlev): | |
87 """the main program is telling us to change our | |
88 display. newlev is 0..1""" | |
89 self.currentlevel=newlev | |
90 newlev="%d"%(newlev*100) | |
91 olddisplay=self.level_lab.cget('text') | |
92 if newlev!=olddisplay: | |
93 self.level_lab.config(text=newlev) | |
94 self.colorlabel() | |
95 | |
96 def getlevel(self): | |
97 """returns currently displayed level, 0..1""" | |
98 return self.currentlevel | |
99 | |
100 def changelevel(self,newlev): | |
101 | |
102 """the user is adjusting the level on this widget. the main | |
103 program needs to hear about it. then the main program will | |
104 call setlevel()""" | |
105 | |
106 dispatcher.send("levelchanged",channel=self.channelnum,newlevel=newlev) | |
107 | |
108 class Levelbox(tk.Frame): | |
109 def __init__(self, parent, num_channels=68): | |
110 tk.Frame.__init__(self,parent) | |
111 | |
112 self.levels = [] # Onelevel objects | |
113 | |
114 frames = (make_frame(self), make_frame(self)) | |
115 | |
116 for channel in range(1, num_channels+1): | |
117 | |
118 # frame for this channel | |
119 f = Onelevel(frames[channel > (num_channels/2)],channel) | |
120 | |
121 self.levels.append(f) | |
122 f.pack(side='top') | |
123 | |
124 #dispatcher.connect(setalevel,"setlevel") | |
125 | |
126 def setlevels(self,newlevels): | |
127 """sets levels to the new list of dmx levels (0..1). list can | |
128 be any length""" | |
129 for l,newlev in zip(self.levels,newlevels): | |
130 l.setlevel(newlev) |