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