Mercurial > code > home > repos > light9
annotate light8/rsn.py @ 34:411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
the famous you-are-in-the-process-of-changing-this-light indicator.
red = going up
blue = going down
also, a generic color fader in uihelpers.py -- unused (as of now)
author | dmcc |
---|---|
date | Sun, 07 Jul 2002 12:06:16 +0000 |
parents | d9a0f6c88b39 |
children | 3cbe7110d8f7 |
rev | line source |
---|---|
4 | 1 #!/usr/bin/env python |
0 | 2 from __future__ import nested_scopes |
3 | |
4 | 4 from Tkinter import * |
5 from time import sleep | |
6 from signal import * | |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
7 import sys, thread, cPickle, math |
4 | 8 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
9 import io |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
10 from uihelpers import * |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
11 from panels import * |
4 | 12 from Xfader import * |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
13 import stage |
0 | 14 |
15 if len(sys.argv) >= 2: | |
16 DUMMY = 0 | |
4 | 17 print "This is the real thing, baby" |
0 | 18 window_title = "Light 8.8 (On Air)" |
19 else: | |
20 DUMMY = 1 | |
4 | 21 print "Dummy mode" |
0 | 22 window_title = "Light 8.8 (Bogus)" |
23 | |
24 root = Tk() | |
25 root.wm_title(window_title) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
29
diff
changeset
|
26 root.wm_geometry('+462+470') |
19 | 27 root.tk_focusFollowsMouse() |
4 | 28 |
29 import Subs, Patch | |
0 | 30 |
4 | 31 def get_data(*args): |
32 Subs.reload_data(DUMMY) | |
33 Patch.reload_data(DUMMY) | |
34 print "Patch:", Patch.patch | |
35 print "Subs:", ', '.join(Subs.subs.keys()) | |
36 | |
37 get_data() | |
0 | 38 |
29
f595fdd4c548
minor cleanups, convert parallel port controller to a class
dmcc
parents:
28
diff
changeset
|
39 parportdmx = io.ParportDMX(DUMMY) |
4 | 40 |
26 | 41 class Lightboard: |
42 def __init__(self, master): | |
43 self.master = master | |
4 | 44 |
26 | 45 self.channel_levels = [] |
46 self.scalelevels = {} | |
47 self.oldlevels = [None] * 68 | |
48 | |
49 self.buildinterface() | |
50 self.load() | |
51 self.backgroundloop() | |
52 def buildinterface(self): | |
53 for w in self.master.winfo_children(): | |
54 w.destroy() | |
0 | 55 |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
29
diff
changeset
|
56 stage_tl = toplevelat(65,37) |
26 | 57 s = stage.Stage(stage_tl) |
58 stage.createlights(s) | |
59 s.pack() | |
60 | |
61 sub_tl = toplevelat(0,0) | |
30
e9d2e7754fd9
sideways subs, new x/y buttons (which don't draw right, but they work)
drewp
parents:
29
diff
changeset
|
62 effect_tl = toplevelat(462,4) |
4 | 63 |
26 | 64 self.xfader = Xfader(self.scalelevels) |
4 | 65 |
26 | 66 self.subpanels = Subpanels(sub_tl, effect_tl, self.scalelevels, Subs, |
67 self.xfader, self.changelevel) | |
68 | |
69 leveldisplay_tl = toplevelat(873,400) | |
70 leveldisplay_tl.bind('<Escape>', sys.exit) | |
16 | 71 |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
72 self.leveldisplay = Leveldisplay(leveldisplay_tl, self.channel_levels) |
26 | 73 |
74 Console() | |
4 | 75 |
26 | 76 # root frame |
33 | 77 controlpanel = Controlpanel(root, self.xfader, self.refresh, self.quit) |
4 | 78 |
26 | 79 xf=Frame(root) |
80 xf.pack(side='right') | |
81 | |
33 | 82 root.bind('<q>', self.quit) |
26 | 83 root.bind('<r>', self.refresh) |
33 | 84 leveldisplay_tl.bind('<q>', self.quit) |
26 | 85 leveldisplay_tl.bind('<r>', self.refresh) |
4 | 86 |
26 | 87 self.xfader.setupwidget(xf) |
88 controlpanel.pack() | |
89 | |
90 def refresh(self, *args): | |
91 'rebuild interface, reload data' | |
92 get_data() | |
93 self.buildinterface() | |
33 | 94 bindkeys(root,'<Escape>', self.quit) |
4 | 95 |
26 | 96 # this is called on a loop, and ALSO by the Scales |
97 def changelevel(self, *args): | |
98 'Amp trims slider' | |
99 | |
100 levels = [0] * 68 | |
101 for name, s in Subs.subs.items(): | |
102 newlevels = s.get_levels(level=self.scalelevels[name].get()) | |
103 for (ch, fadelev) in newlevels.items(): | |
104 levels[ch-1] = max(levels[ch-1], fadelev) | |
4 | 105 |
26 | 106 levels = [int(l) for l in levels] |
0 | 107 |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
108 for lev,lab,oldlev,numlab in zip(levels, self.channel_levels, |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
109 self.oldlevels, |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
110 self.leveldisplay.number_labels): |
26 | 111 if lev != oldlev: |
112 lab.config(text="%d" % lev) | |
113 colorlabel(lab) | |
34
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
114 if lev < oldlev: |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
115 numlab['bg'] = 'red' |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
116 else: |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
117 numlab['bg'] = 'blue' |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
118 else: |
411de8b46aef
the famous you-are-in-the-process-of-changing-this-light indicator.
dmcc
parents:
33
diff
changeset
|
119 numlab['bg'] = 'lightPink' |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
120 |
26 | 121 self.oldlevels = levels[:] |
122 | |
29
f595fdd4c548
minor cleanups, convert parallel port controller to a class
dmcc
parents:
28
diff
changeset
|
123 parportdmx.sendlevels(levels) |
4 | 124 |
26 | 125 def load(self): |
126 try: | |
127 filename = '/tmp/light9.prefs' | |
128 if DUMMY: | |
129 filename += '.dummy' | |
130 print "Loading from", filename | |
131 file = open(filename, 'r') | |
132 p = cPickle.load(file) | |
133 for s, v in p.scalelevels.items(): | |
134 try: | |
135 self.scalelevels[s].set(v) | |
136 except: | |
137 print "Couldn't set %s -> %s" % (s, v) | |
28 | 138 for name, substate in p.substate.items(): |
139 try: | |
140 Subs.subs[name].set_state(substate) | |
141 except: | |
142 print "Couldn't set sub %s state" % name | |
143 except IOError: | |
144 print "IOError: Couldn't load prefs (%s)" % filename | |
145 except EOFError: | |
146 print "EOFrror: Couldn't load prefs (%s)" % filename | |
29
f595fdd4c548
minor cleanups, convert parallel port controller to a class
dmcc
parents:
28
diff
changeset
|
147 except: |
f595fdd4c548
minor cleanups, convert parallel port controller to a class
dmcc
parents:
28
diff
changeset
|
148 print "BigTrouble: Couldn't load prefs (%s)" % filename |
26 | 149 def make_sub(self, name): |
150 i = 1 | |
151 if not name: | |
152 print "Enter sub name in console." | |
153 return | |
0 | 154 |
26 | 155 st = '' |
156 linebuf = 'subs["%s"] = {' % name | |
157 for l in self.oldlevels: | |
158 if l: | |
159 if len(linebuf) > 60: | |
160 st += linebuf + '\n ' | |
161 linebuf = '' | |
0 | 162 |
26 | 163 linebuf += ' "%s" : %d,' % (Patch.get_channel_name(i), l) |
164 i += 1 | |
165 st += linebuf + '}\n' | |
166 if DUMMY: | |
167 filename = 'ConfigDummy.py' | |
168 else: | |
169 filename = 'Config.py' | |
170 f = open(filename, 'a') | |
171 f.write(st) | |
172 f.close() | |
173 print 'Added sub:', st | |
174 self.refresh() | |
175 def backgroundloop(self, *args): | |
176 self.master.after(50, self.backgroundloop, ()) | |
177 self.changelevel() | |
178 def quit(self, *args): | |
28 | 179 self.save() |
180 root.destroy() | |
181 sys.exit() | |
182 def save(self, *args): | |
26 | 183 filename = '/tmp/light9.prefs' |
184 if DUMMY: | |
185 filename += '.dummy' | |
186 print "Saving to", filename | |
187 file = open(filename, 'w') | |
28 | 188 try: |
189 cPickle.dump(Pickles(self.scalelevels, Subs.subs.items()), file) | |
190 except cPickle.UnpickleableError: | |
191 print "UnpickleableError! There's yer problem." | |
4 | 192 |
193 class Pickles: | |
28 | 194 def __init__(self, scalelevels, subs=None): |
4 | 195 self.scalelevels = dict([(name, lev.get()) |
28 | 196 for name, lev in scalelevels.items()]) |
197 self.substate = dict([(name, subobj.get_state()) | |
198 for name, subobj in subs]) | |
29
f595fdd4c548
minor cleanups, convert parallel port controller to a class
dmcc
parents:
28
diff
changeset
|
199 # print "substate", self.substate |
4 | 200 |
26 | 201 mr_lightboard = Lightboard(root) |
4 | 202 |
26 | 203 signal(SIGINT, mr_lightboard.quit) |
204 bindkeys(root,'<Escape>', mr_lightboard.quit) | |
4 | 205 |
206 root.mainloop() # Receiver switches main |