Mercurial > code > home > repos > light9
annotate light8/rsn.py @ 12:7adc65771676
big restructuring - moved lots of things (including most panels) to other files
author | drewp |
---|---|
date | Sun, 07 Jul 2002 06:16:11 +0000 |
parents | f974a462133f |
children | 7dbe8067acea |
rev | line source |
---|---|
4 | 1 #!/usr/bin/env python |
0 | 2 from __future__ import nested_scopes |
3 | |
4 | 4 from Tkinter import * |
5 from parport import * | |
6 from time import sleep | |
7 from signal import * | |
8 import sys, thread, cPickle | |
9 | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
10 import io |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
11 from uihelpers import * |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
12 from panels import * |
4 | 13 from Xfader import * |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
14 import stage |
0 | 15 |
16 if len(sys.argv) >= 2: | |
17 DUMMY = 0 | |
4 | 18 print "This is the real thing, baby" |
0 | 19 window_title = "Light 8.8 (On Air)" |
20 else: | |
21 DUMMY = 1 | |
4 | 22 print "Dummy mode" |
0 | 23 window_title = "Light 8.8 (Bogus)" |
24 | |
25 root = Tk() | |
26 root.wm_title(window_title) | |
4 | 27 root.wm_geometry('+447+373') |
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 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
39 io.init(DUMMY) |
4 | 40 |
41 channel_levels = [] | |
42 scalelevels = {} | |
43 fades = {} | |
44 | |
45 _oldlevels=[None] * 68 | |
0 | 46 |
4 | 47 def changelevel(*args): |
48 'Amp trims slider' | |
49 global _oldlevels | |
50 | |
51 levels = [0] * 68 | |
52 for name, s in Subs.subs.items(): | |
53 newlevels = s.get_levels(level=scalelevels[name].get()) | |
54 for (ch, fadelev) in newlevels.items(): | |
55 levels[ch-1] = max(levels[ch-1], fadelev) | |
56 | |
57 levels = [int(l) for l in levels] | |
58 | |
59 for lev,lab,oldlev in zip(levels, channel_levels, _oldlevels): | |
60 if lev != oldlev: | |
61 lab.config(text="%d" % lev) | |
62 colorlabel(lab) | |
63 | |
64 _oldlevels = levels[:] | |
65 | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
66 io.sendlevels(levels) |
4 | 67 |
68 def backgroundloop(*args): | |
69 root.after(50, backgroundloop, ()) | |
70 changelevel() | |
71 | |
72 buildinterface = None # temporary | |
73 def refresh(*args): | |
74 get_data() | |
75 buildinterface() | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
76 bindkeys(root,'<Escape>', quit) |
4 | 77 |
78 def quit(*args): | |
79 filename = '/tmp/light9.prefs' | |
80 if DUMMY: | |
81 filename += '.dummy' | |
82 print "Saving to", filename | |
83 file = open(filename, 'w') | |
84 cPickle.dump(Pickles(scalelevels), file) | |
85 root.destroy() | |
86 sys.exit() | |
0 | 87 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
88 |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
89 xfader=Xfader(scalelevels) |
4 | 90 |
91 | |
92 | |
93 def buildinterface(*args): | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
94 global channel_levels, _oldlevels, leveldisplay, xfader |
4 | 95 for w in root.winfo_children(): |
96 w.destroy() | |
97 | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
98 stage_tl=toplevelat(165,90) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
99 s=stage.Stage(stage_tl) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
100 stage.createlights(s) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
101 s.pack() |
0 | 102 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
103 sub_tl = toplevelat(0,0) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
104 effect_tl = toplevelat(0,352) |
4 | 105 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
106 Subpanels(sub_tl,effect_tl,scalelevels,Subs,xfader,changelevel) |
4 | 107 |
108 # def event_printer(evt): | |
109 # print dir(evt) | |
0 | 110 |
4 | 111 # sub_tl.bind('<b>', event_printer) |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
112 leveldisplay=toplevelat(873,400) |
4 | 113 leveldisplay.bind('<Escape>', sys.exit) |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
114 |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
115 Leveldisplay(leveldisplay,_oldlevels) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
116 |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
117 Console() |
0 | 118 |
4 | 119 # root frame |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
120 controlpanel = Controlpanel(root,xfader,refresh,quit) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
121 |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
122 xf=Frame(root) |
4 | 123 xf.pack(side='right') |
0 | 124 |
4 | 125 root.bind('<q>', quit) |
126 root.bind('<r>', refresh) | |
127 leveldisplay.bind('<q>', quit) | |
128 leveldisplay.bind('<r>', refresh) | |
129 | |
130 xfader.setupwidget(xf) | |
131 controlpanel.pack() | |
132 | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
133 |
4 | 134 buildinterface() |
135 | |
136 class Pickles: | |
137 def __init__(self, scalelevels): | |
138 self.scalelevels = dict([(name, lev.get()) | |
139 for name,lev in scalelevels.items()]) | |
140 | |
141 def load(): | |
142 try: | |
143 filename = '/tmp/light9.prefs' | |
144 if DUMMY: | |
145 filename += '.dummy' | |
146 print "Loading from", filename | |
147 file = open(filename, 'r') | |
148 p = cPickle.load(file) | |
149 for s, v in p.scalelevels.items(): | |
150 try: | |
151 scalelevels[s].set(v) | |
152 except: | |
153 print "Couldn't set %s -> %s" % (s, v) | |
154 except: | |
155 print "Couldn't load prefs (%s)" % filename | |
0 | 156 |
4 | 157 def make_sub(name): |
158 global _oldlevels | |
159 i = 1 | |
160 # name = console_entry.get() # read from console | |
161 if not name: | |
162 print "Enter sub name in console." | |
163 return | |
164 | |
165 st = '' | |
166 linebuf = 'subs["%s"] = {' % name | |
167 for l in _oldlevels: | |
168 if l: | |
169 if len(linebuf) > 60: | |
170 st += linebuf + '\n ' | |
171 linebuf = '' | |
172 | |
173 linebuf += ' "%s" : %d,' % (Patch.get_channel_name(i), l) | |
174 i += 1 | |
175 st += linebuf + '}\n' | |
176 if DUMMY: | |
177 filename = 'ConfigDummy.py' | |
178 else: | |
179 filename = 'Config.py' | |
180 f = open(filename, 'a') | |
181 f.write(st) | |
182 f.close() | |
183 print 'Added sub:', st | |
184 refresh() | |
185 | |
186 load() | |
187 signal(SIGINT, quit) | |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
188 bindkeys(root,'<Escape>', quit) |
4 | 189 |
12
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
190 # bindkeys(root,'<q>', quit) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
191 # bindkeys(root,'<r>', refresh) |
7adc65771676
big restructuring - moved lots of things (including most panels) to other files
drewp
parents:
4
diff
changeset
|
192 # bindkeys(root,'<s>', make_sub) |
4 | 193 backgroundloop() |
194 root.mainloop() # Receiver switches main | |
195 | |
196 while 1: | |
197 for lev in range(0,255,25)+range(255,0,-25): | |
198 sleep(.2) |