Mercurial > code > home > repos > light9
comparison flax/KeyboardComposer.py @ 136:7e91c49fb2d6
whoops, forgot this one
author | dmcc |
---|---|
date | Sat, 14 Jun 2003 15:02:38 +0000 |
parents | 2ed9bfd1dd0e |
children | 304152488ed7 |
comparison
equal
deleted
inserted
replaced
135:5670f66845ce | 136:7e91c49fb2d6 |
---|---|
1 from __future__ import nested_scopes | 1 from __future__ import nested_scopes |
2 import sys | 2 import sys, time |
3 sys.path.append('..') | 3 sys.path.append('..') |
4 from Widgets.Fadable import Fadable | 4 from Widgets.Fadable import Fadable |
5 | 5 |
6 from Tix import * | 6 from Tix import * |
7 import math | 7 import math, atexit, pickle |
8 from Timeline import LevelFrame | 8 from Submaster import Submasters, sub_maxes |
9 | 9 import dmxclient |
10 Submaster = LevelFrame | 10 from uihelpers import toplevelat |
11 | 11 |
12 nudge_keys = { | 12 nudge_keys = { |
13 'up' : list('qwertyuiop'), | 13 'up' : list('qwertyuiop'), |
14 'down' : list('asdfghjkl') | 14 'down' : list('asdfghjkl') |
15 } | 15 } |
17 | 17 |
18 class SubScale(Scale, Fadable): | 18 class SubScale(Scale, Fadable): |
19 def __init__(self, master, *args, **kw): | 19 def __init__(self, master, *args, **kw): |
20 self.scale_var = kw.get('variable') or DoubleVar() | 20 self.scale_var = kw.get('variable') or DoubleVar() |
21 kw.update({'variable' : self.scale_var, | 21 kw.update({'variable' : self.scale_var, |
22 'from' : 100, 'to' : 0, 'showvalue' : 0, | 22 'from' : 1, 'to' : 0, 'showvalue' : 0, |
23 'sliderlength' : 10}) | 23 'sliderlength' : 30, 'res' : 0.01, |
24 'width' : 50}) | |
24 Scale.__init__(self, master, *args, **kw) | 25 Scale.__init__(self, master, *args, **kw) |
25 Fadable.__init__(self, var=self.scale_var) | 26 Fadable.__init__(self, var=self.scale_var, wheel_step=0.05) |
26 | 27 |
27 class SubmasterTk(Frame): | 28 class SubmasterTk(Frame): |
28 def __init__(self, master, name, current_level): | 29 def __init__(self, master, name, current_level): |
29 Frame.__init__(self, master) | 30 Frame.__init__(self, master, bd=1, relief='raised') |
30 self.slider_var = DoubleVar() | 31 self.slider_var = DoubleVar() |
31 self.slider_var.set(current_level) | 32 self.slider_var.set(current_level) |
32 self.scale = SubScale(self, variable=self.slider_var, width=20) | 33 self.scale = SubScale(self, variable=self.slider_var, width=20) |
33 textlabel = Label(self, text=name) | 34 textlabel = Label(self, text=name) |
34 textlabel.pack(side=TOP) | 35 textlabel.pack(side=TOP) |
36 | 37 |
37 class KeyboardComposer(Frame): | 38 class KeyboardComposer(Frame): |
38 def __init__(self, root, submasters, current_sub_levels=None): | 39 def __init__(self, root, submasters, current_sub_levels=None): |
39 Frame.__init__(self, root) | 40 Frame.__init__(self, root) |
40 self.submasters = submasters | 41 self.submasters = submasters |
41 self.current_sub_levels = current_sub_levels or {} | 42 self.current_sub_levels = {} |
42 | 43 if current_sub_levels: |
44 self.current_sub_levels = current_sub_levels | |
45 else: | |
46 try: | |
47 self.current_sub_levels = \ | |
48 pickle.load(file('.keyboardcomposer.savedlevels')) | |
49 except IOError: | |
50 pass | |
51 | |
52 self.draw_ui() | |
53 self.send_levels_loop() | |
54 def draw_ui(self): | |
43 self.rows = [] # this holds Tk Frames for each row | 55 self.rows = [] # this holds Tk Frames for each row |
44 self.slider_vars = {} # this holds subname:sub Tk vars | 56 self.slider_vars = {} # this holds subname:sub Tk vars |
45 self.slider_table = {} # this holds coords:sub Tk vars | 57 self.slider_table = {} # this holds coords:sub Tk vars |
46 self.current_row = 0 | 58 self.current_row = 0 |
47 | 59 |
48 self.make_key_hints() | 60 self.make_key_hints() |
49 self.draw_sliders() | 61 self.draw_sliders() |
50 self.highlight_row(self.current_row) | 62 self.highlight_row(self.current_row) |
51 self.rows[self.current_row].focus() | 63 self.rows[self.current_row].focus() |
64 | |
65 self.refreshbutton = Button(self, text="Refresh", command=self.refresh) | |
66 self.refreshbutton.pack(side=BOTTOM) | |
67 self.stop_frequent_update_time = 0 | |
52 def make_key_hints(self): | 68 def make_key_hints(self): |
53 keyhintrow = Frame(self) | 69 keyhintrow = Frame(self) |
54 | 70 |
55 col = 0 | 71 col = 0 |
56 for upkey, downkey in zip(nudge_keys['up'], | 72 for upkey, downkey in zip(nudge_keys['up'], |
57 nudge_keys['down']): | 73 nudge_keys['down']): |
58 # what a hack! | 74 # what a hack! |
59 downkey = downkey.replace('semicolon', ';') | 75 downkey = downkey.replace('semicolon', ';') |
76 upkey, downkey = (upkey.upper(), downkey.upper()) | |
60 | 77 |
61 # another what a hack! | 78 # another what a hack! |
62 keylabel = Label(keyhintrow, text='%s\n%s' % (upkey, downkey), | 79 keylabel = Label(keyhintrow, text='%s\n%s' % (upkey, downkey), |
63 width=3, font=('Arial', 12), bg='red', fg='white') | 80 width=8, font=('Arial', 12), bg='red', fg='white', anchor='c') |
64 keylabel.pack(side=LEFT, expand=1, fill=X) | 81 keylabel.pack(side=LEFT, expand=1, fill=X) |
65 col += 1 | 82 col += 1 |
66 | 83 |
67 keyhintrow.pack(fill=X, expand=0) | 84 keyhintrow.pack(fill=X, expand=0) |
68 self.keyhints = keyhintrow | 85 self.keyhints = keyhintrow |
97 self.unhighlight_row(old_row) | 114 self.unhighlight_row(old_row) |
98 self.highlight_row(self.current_row) | 115 self.highlight_row(self.current_row) |
99 row = self.rows[self.current_row] | 116 row = self.rows[self.current_row] |
100 self.keyhints.pack_configure(before=row) | 117 self.keyhints.pack_configure(before=row) |
101 def got_nudger(self, number, direction, full=0): | 118 def got_nudger(self, number, direction, full=0): |
102 print "got_nudger", number, direction, full | |
103 subtk = self.slider_table[(self.current_row, number)] | 119 subtk = self.slider_table[(self.current_row, number)] |
104 if direction == 'up': | 120 if direction == 'up': |
105 if full: | 121 if full: |
106 subtk.scale.fade(100) | 122 subtk.scale.fade(1) |
107 else: | 123 else: |
108 subtk.scale.increase() | 124 subtk.scale.increase() |
109 else: | 125 else: |
110 if full: | 126 if full: |
111 subtk.scale.fade(0) | 127 subtk.scale.fade(0) |
112 else: | 128 else: |
113 subtk.scale.decrease() | 129 subtk.scale.decrease() |
130 # self.maybe_update() | |
131 def maybe_update(self, dur=1.05): | |
132 now = time.time() | |
133 if now > self.stop_frequent_update_time: | |
134 self.stop_frequent_update_time = now + dur | |
135 self.send_frequent_updates() | |
136 else: | |
137 self.stop_frequent_update_time = now + dur | |
114 def draw_sliders(self): | 138 def draw_sliders(self): |
115 self.tk_focusFollowsMouse() | 139 self.tk_focusFollowsMouse() |
116 | 140 |
117 rowcount = -1 | 141 rowcount = -1 |
118 col = 0 | 142 col = 0 |
119 for sub in self.submasters: | 143 for sub in self.submasters.get_all_subs(): |
120 if col == 0: # make new row | 144 if col == 0: # make new row |
121 row = self.make_row() | 145 row = self.make_row() |
122 rowcount += 1 | 146 rowcount += 1 |
123 current_level = self.current_sub_levels.get(sub.name, 0) | 147 current_level = self.current_sub_levels.get(sub.name, 0) |
124 subtk = self.draw_sub_slider(row, col, sub.name, current_level) | 148 subtk = self.draw_sub_slider(row, col, sub.name, current_level) |
125 self.slider_table[(rowcount, col)] = subtk | 149 self.slider_table[(rowcount, col)] = subtk |
126 col += 1 | 150 col += 1 |
127 col %= 10 | 151 col %= 10 |
152 | |
153 subtk.slider_var.trace('w', lambda x, y, z: self.send_levels()) | |
128 def make_row(self): | 154 def make_row(self): |
129 row = Frame(self, bd=2) | 155 row = Frame(self, bd=2) |
130 row.pack(expand=1, fill=BOTH) | 156 row.pack(expand=1, fill=BOTH) |
131 self.setup_key_nudgers(row) | 157 self.setup_key_nudgers(row) |
132 self.rows.append(row) | 158 self.rows.append(row) |
145 row = self.rows[row] | 171 row = self.rows[row] |
146 row['bg'] = '#d9d9d9' | 172 row['bg'] = '#d9d9d9' |
147 def get_levels(self): | 173 def get_levels(self): |
148 return dict([(name, slidervar.get()) | 174 return dict([(name, slidervar.get()) |
149 for name, slidervar in self.slider_vars.items()]) | 175 for name, slidervar in self.slider_vars.items()]) |
176 def get_dmx_list(self): | |
177 scaledsubs = [self.submasters.get_sub_by_name(sub) * level \ | |
178 for sub, level in self.get_levels().items()] | |
179 | |
180 maxes = sub_maxes(*scaledsubs) | |
181 return maxes.get_dmx_list() | |
182 def save(self): | |
183 pickle.dump(self.get_levels(), | |
184 file('.keyboardcomposer.savedlevels', 'w')) | |
185 def send_frequent_updates(self): | |
186 """called when we get a fade -- send events as quickly as possible""" | |
187 if time.time() <= self.stop_frequent_update_time: | |
188 self.send_levels() | |
189 self.after(10, self.send_frequent_updates) | |
190 def send_levels(self): | |
191 print self.submasters.get_sub_by_name('frontwhite') | |
192 levels = self.get_dmx_list() | |
193 dmxclient.outputlevels(levels) | |
194 def send_levels_loop(self): | |
195 self.send_levels() | |
196 self.after(1000, self.send_levels_loop) | |
197 def refresh(self): | |
198 self.save() | |
199 self.submasters = Submasters() | |
200 self.current_sub_levels = \ | |
201 pickle.load(file('.keyboardcomposer.savedlevels')) | |
202 for r in self.rows: | |
203 r.destroy() | |
204 self.keyhints.destroy() | |
205 self.refreshbutton.destroy() | |
206 self.draw_ui() | |
150 | 207 |
151 if __name__ == "__main__": | 208 if __name__ == "__main__": |
152 reds = Submaster('reds', {'red1' : 20, 'red2' : 30, 'red3' : 80}) | 209 s = Submasters() |
153 blues = Submaster('blues', {'blue1' : 60, 'blue2' : 80, 'blue3' : 20}) | |
154 | |
155 subs = [] | |
156 for scenename in 'warmers house god spot explosion booth stageleft stageright donkey elvis sun fiddler satan lola bed treehouse motel6 deadmics suck burninggels firelights sodacan lighting homestar strongbad coachz pompom marzipan bubs thecheat'.split(): | |
157 subs.append(Submaster(scenename, {'dummy' : 20})) | |
158 | 210 |
159 root = Tk() | 211 root = Tk() |
160 root.wm_geometry('400x400') | 212 tl = toplevelat("Keyboard Composer", existingtoplevel=root) |
161 kc = KeyboardComposer(root, subs) | 213 kc = KeyboardComposer(tl, s) |
162 kc.pack(fill=BOTH, expand=1) | 214 kc.pack(fill=BOTH, expand=1) |
163 mainloop() | 215 atexit.register(kc.save) |
216 try: | |
217 mainloop() | |
218 except KeyboardInterrupt: | |
219 tl.destroy() | |
220 sys.exit() |