Mercurial > code > home > repos > light9
annotate flax/CueFaders.py @ 181:ccd635df77a9
- commit latest cue and sub changes
- commit latest cue and sub changes
- CueFaders: show sub levels everywhere, update TODO section
author | dmcc |
---|---|
date | Fri, 11 Jul 2003 16:04:13 +0000 |
parents | ce362534d133 |
children | 74a34c677588 |
rev | line source |
---|---|
0 | 1 from __future__ import division, nested_scopes |
2 import Tix as Tk | |
3 import time | |
4 from TreeDict import TreeDict, allow_class_to_be_pickled | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
5 from TLUtility import enumerate |
168 | 6 import Submaster, dmxclient |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
7 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
8 cue_state_indicator_colors = { |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
9 # bg fg |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
10 'prev' : ('blue', 'white'), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
11 'cur' : ('yellow', 'black'), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
12 'next' : ('red', 'white'), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
13 } |
0 | 14 |
178 | 15 # TODO |
181 | 16 # FIXE pause fades, set new time to be remaining about of time in the fade so |
178 | 17 # fade can continue properly |
181 | 18 # FIXE make fades work properly: the set_next / prev bug |
178 | 19 # WONT find cue by page ("not necessawy!") |
20 # WONT CueFader controls KeyboardController? unlikely | |
176 | 21 |
0 | 22 class LabelledScale(Tk.Frame): |
23 """Scale with two labels: a name and current value""" | |
24 def __init__(self, master, label, **opts): | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
25 Tk.Frame.__init__(self, master, bd=2, relief='raised', bg='black') |
163 | 26 self.labelformatter = opts.get('labelformatter') |
27 try: | |
28 del opts['labelformatter'] | |
29 except KeyError: | |
30 pass | |
31 | |
0 | 32 opts.setdefault('variable', Tk.DoubleVar()) |
33 opts.setdefault('showvalue', 0) | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
34 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
35 self.normaltrough = opts.get('troughcolor', 'black') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
36 self.flashtrough = opts.get('flashtroughcolor', 'red') |
163 | 37 try: |
38 del opts['flashtroughcolor'] | |
39 except KeyError: | |
40 pass | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
41 |
0 | 42 self.scale_var = opts['variable'] |
43 self.scale = Tk.Scale(self, **opts) | |
44 self.scale.pack(side='top', expand=1, fill='both') | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
45 self.name = Tk.Label(self, text=label, bg='black', fg='white') |
0 | 46 self.name.pack(side='bottom') |
163 | 47 self.scale_value = Tk.Label(self, bg='black', fg='white') |
0 | 48 self.scale_value.pack(side='bottom') |
49 self.scale_var.trace('w', self.update_value_label) | |
50 self.update_value_label() | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
51 self.disabled = (self.scale['state'] == 'disabled') |
0 | 52 def set_label(self, label): |
53 self.name['text'] = label | |
54 def update_value_label(self, *args): | |
55 val = self.scale_var.get() * 100 | |
163 | 56 if self.labelformatter: |
57 format = self.labelformatter(val) | |
58 else: | |
59 format = "%0.2f" % val | |
60 self.scale_value['text'] = format | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
61 if val != 0: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
62 self.scale['troughcolor'] = self.flashtrough |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
63 else: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
64 self.scale['troughcolor'] = self.normaltrough |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
65 def disable(self): |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
66 if not self.disabled: |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
67 self.scale['state'] = 'disabled' |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
68 self.scale_var.set(0) |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
69 self.disabled = 1 |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
70 def enable(self): |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
71 if self.disabled: |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
72 self.scale['state'] = 'normal' |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
73 self.disabled = 0 |
0 | 74 |
75 class TimedGoButton(Tk.Frame): | |
76 """Go button, fade time entry, and time fader""" | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
77 def __init__(self, master, name, scale_to_fade, **kw): |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
78 Tk.Frame.__init__(self, master, bg='black') |
0 | 79 self.name = name |
80 self.scale_to_fade = scale_to_fade | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
81 self.button = Tk.Button(self, text=name, command=self.start_fade, **kw) |
0 | 82 self.button.pack(fill='both', expand=1, side='left') |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
83 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
84 self.timer_var = Tk.DoubleVar() |
168 | 85 self.timer_entry = Tk.Control(self, step=0.5, min=0, integer=0, |
86 variable=self.timer_var, selectmode='immediate') | |
87 for widget in (self.timer_entry, self.timer_entry.entry, | |
88 self.timer_entry.incr, self.timer_entry.decr, self.button, self): | |
89 widget.bind("<4>", self.wheelscroll) | |
90 widget.bind("<5>", self.wheelscroll) | |
91 self.timer_entry.entry.configure(width=5, bg='black', fg='white') | |
0 | 92 self.timer_entry.pack(fill='y', side='left') |
168 | 93 self.timer_var.set(2) |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
94 self.disabled = (self.button['state'] == 'disabled') |
178 | 95 self.start_time = 0 |
167 | 96 self.fading = 0 |
178 | 97 self.last_after_key = 0 |
179 | 98 def manual_override(self, *args): |
99 self.end_fade() | |
168 | 100 def wheelscroll(self, event): |
101 """Mouse wheel increments or decrements timer.""" | |
102 if event.num == 4: # scroll up | |
103 self.timer_entry.increment() | |
104 else: # scroll down | |
105 self.timer_entry.decrement() | |
0 | 106 def start_fade(self, end_level=1): |
178 | 107 self.last_start_time = self.start_time |
0 | 108 self.start_time = time.time() |
109 self.start_level = self.scale_to_fade.scale_var.get() | |
110 self.end_level = end_level | |
178 | 111 |
112 if self.fading == 1: # if we're already fading | |
113 self.fading = 'paused' | |
179 | 114 # new fade should be as long as however much was left |
115 self.fade_length = self.fade_length - \ | |
116 (time.time() - self.last_start_time) | |
117 self.button['text'] = 'Unpause' | |
118 self.after_cancel(self.last_after_key) | |
178 | 119 else: |
120 try: | |
121 fade_time = float(self.timer_var.get()) | |
122 except ValueError: | |
123 # since we use a TixControl now, i don't think we need to worry | |
124 # about validation any more. | |
125 print ">>> Can't fade -- bad time", self.timer_var.get() | |
126 return | |
127 | |
179 | 128 # if we're not already fading, we get our time from the entry |
178 | 129 if self.fading != 'paused': |
130 self.fade_length = fade_time | |
179 | 131 |
178 | 132 self.button['text'] = 'Pause' |
133 self.fading = 1 | |
134 self.do_fade() | |
0 | 135 def do_fade(self): |
136 diff = time.time() - self.start_time | |
137 if diff < self.fade_length: | |
138 percent = diff / self.fade_length | |
139 newlevel = self.start_level + \ | |
140 (percent * (self.end_level - self.start_level)) | |
141 self.scale_to_fade.scale_var.set(newlevel) | |
142 | |
143 if newlevel != self.end_level: | |
178 | 144 self.last_after_key = self.after(10, self.do_fade) |
167 | 145 else: |
178 | 146 self.end_fade() |
0 | 147 else: |
148 self.scale_to_fade.scale_var.set(self.end_level) | |
178 | 149 self.end_fade() |
150 def end_fade(self): | |
151 self.button['text'] = self.name | |
152 self.fading = 0 | |
153 self.after_cancel(self.last_after_key) | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
154 def disable(self): |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
155 if not self.disabled: |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
156 self.button['state'] = 'disabled' |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
157 self.disabled = 1 |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
158 def enable(self): |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
159 if self.disabled: |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
160 self.button['state'] = 'normal' |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
161 self.disabled = 0 |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
162 def set_time(self, time): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
163 self.timer_var.set(time) |
163 | 164 def get_time(self): |
165 return self.timer_var.get() | |
167 | 166 def is_fading(self): |
167 return self.fading | |
0 | 168 |
169 class CueFader(Tk.Frame): | |
170 def __init__(self, master, cuelist): | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
171 Tk.Frame.__init__(self, master, bg='black') |
0 | 172 self.cuelist = cuelist |
168 | 173 self.cuelist.set_fader(self) |
174 | |
175 self.last_levels_sent = 0 | |
176 self.current_dmx_levels = [0] * 68 | |
177 self.after(0, self.send_dmx_levels_loop) # start DMX sending loop | |
0 | 178 |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
179 # this is a mechanism to stop Tk from autoshifting too much. |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
180 # if this variable is true, the mouse button is down. we don't want |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
181 # to shift until they release it. when it is released, we will |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
182 # set it to false and then call autoshift. |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
183 self.no_shifts_until_release = 0 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
184 |
0 | 185 self.scales = {} |
186 self.shift_buttons = {} | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
187 self.go_buttons = {} |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
188 |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
189 topframe = Tk.Frame(self, bg='black') |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
190 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
191 self.set_prev_button = Tk.Button(topframe, text='Set Prev', |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
192 command=lambda: cuelist.set_selection_as_prev(), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
193 fg='white', bg='blue') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
194 self.set_prev_button.pack(side='left') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
195 |
168 | 196 self.auto_shift = Tk.IntVar() |
197 self.auto_shift.set(1) | |
198 | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
199 self.auto_shift_checkbutton = Tk.Checkbutton(topframe, |
155 | 200 variable=self.auto_shift, text='Autoshift', |
163 | 201 command=self.toggle_autoshift, bg='black', fg='white', |
202 highlightbackground='black') | |
203 self.auto_shift_checkbutton.pack(fill='both', side='left') | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
204 |
168 | 205 self.auto_load_times = Tk.IntVar() |
206 self.auto_load_times.set(1) | |
207 | |
208 self.auto_load_times_checkbutton = Tk.Checkbutton(topframe, | |
209 variable=self.auto_load_times, text='Autoload Times', | |
176 | 210 bg='black', fg='white', |
168 | 211 highlightbackground='black') |
212 self.auto_load_times_checkbutton.pack(fill='both', side='left') | |
213 | |
176 | 214 self.mute = Tk.IntVar() |
215 self.mute.set(0) | |
216 | |
217 self.mutebutton = Tk.Checkbutton(topframe, | |
218 variable=self.mute, text='Mute', | |
219 bg='black', fg='white', | |
220 highlightbackground='black', | |
221 command=self.send_dmx_levels) | |
222 self.mutebutton.pack(fill='both', side='left') | |
223 | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
224 self.set_next_button = Tk.Button(topframe, text='Set Next', |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
225 command=lambda: cuelist.set_selection_as_next(), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
226 fg='white', bg='red') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
227 self.set_next_button.pack(side='left') |
155 | 228 |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
229 topframe.pack(side='top') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
230 |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
231 faderframe = Tk.Frame(self, bg='black') |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
232 self.direction_info = (('Prev', 1, 0, 'left', 'blue'), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
233 ('Next', 0, 1, 'right', 'red')) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
234 for name, start, end, side, color in self.direction_info: |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
235 frame = Tk.Frame(self, bg='black') |
0 | 236 scale = LabelledScale(frame, name, from_=start, to_=end, |
163 | 237 res=0.0001, orient='horiz', flashtroughcolor=color, |
238 labelformatter=lambda val, name=name: self.get_scale_desc(val, | |
239 name)) | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
240 scale.pack(fill='x', expand=0) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
241 go = TimedGoButton(frame, 'Go %s' % name, scale, bg=color, |
178 | 242 fg='white', width=10) |
0 | 243 go.pack(fill='both', expand=1) |
244 frame.pack(side=side, fill='both', expand=1) | |
245 | |
155 | 246 shift = Tk.Button(frame, text="Shift %s" % name, state='disabled', |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
247 command=lambda name=name: self.shift(name), fg=color, |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
248 bg='black') |
155 | 249 |
0 | 250 self.scales[name] = scale |
251 self.shift_buttons[name] = shift | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
252 self.go_buttons[name] = go |
0 | 253 |
254 scale.scale_var.trace('w', \ | |
255 lambda x, y, z, name=name, scale=scale: self.xfade(name, scale)) | |
168 | 256 go.timer_var.trace('w', |
257 lambda x, y, z, scale=scale: scale.update_value_label()) | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
258 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
259 def button_press(event, name=name, scale=scale): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
260 self.no_shifts_until_release = 1 # prevent shifts until release |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
261 def button_release(event, name=name, scale=scale): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
262 self.no_shifts_until_release = 0 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
263 self.autoshift(name, scale) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
264 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
265 scale.scale.bind("<ButtonPress>", button_press) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
266 scale.scale.bind("<ButtonRelease>", button_release) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
267 faderframe.pack(side='bottom', fill='both', expand=1) |
168 | 268 |
269 self.current_dir = 'Next' | |
167 | 270 self.cues_as_subs = {} |
168 | 271 self.update_cue_cache() |
272 def reload_cue_times(self): | |
273 prev, cur, next = self.cuelist.get_current_cues() | |
274 self.go_buttons['Next'].set_time(next.time) | |
178 | 275 def update_cue_cache(self, compute_dmx_levels=1): |
168 | 276 """Rebuilds subs from the current cues. As this is expensive, we don't |
277 do it unless necessary (i.e. whenever we shift or a cue is edited)""" | |
178 | 278 # print "update_cue_cache" |
168 | 279 # load the subs to fade between |
280 for cue, name in zip(self.cuelist.get_current_cues(), | |
281 ('Prev', 'Cur', 'Next')): | |
282 self.cues_as_subs[name] = cue.get_levels_as_sub() | |
178 | 283 if compute_dmx_levels: |
284 self.compute_dmx_levels() | |
168 | 285 def compute_dmx_levels(self): |
286 """Compute the DMX levels to send. This should get called whenever the | |
287 DMX levels could change: either during a crossfade or when a cue is | |
288 edited. Since this is called when we know that a change might occur, | |
289 we will send the new levels too.""" | |
290 cur_sub = self.cues_as_subs.get('Cur') | |
291 if cur_sub: | |
292 scale = self.scales[self.current_dir] | |
293 scale_val = scale.scale_var.get() | |
294 | |
295 other_sub = self.cues_as_subs[self.current_dir] | |
296 current_levels_as_sub = cur_sub.crossfade(other_sub, scale_val) | |
297 self.current_dmx_levels = current_levels_as_sub.get_dmx_list() | |
298 self.send_dmx_levels() | |
178 | 299 |
300 # print "compute_dmx_levels: fade at", scale_val | |
301 # print "between", cur_sub.name, | |
302 # print "and", other_sub.name | |
303 # print | |
176 | 304 def send_dmx_levels(self, *args): |
168 | 305 # print "send_dmx_levels", self.current_dmx_levels |
176 | 306 if self.mute.get(): |
307 dmxclient.outputlevels([0] * 68) | |
308 else: | |
309 dmxclient.outputlevels(self.current_dmx_levels) | |
168 | 310 self.last_levels_sent = time.time() |
311 def send_dmx_levels_loop(self): | |
312 diff = time.time() - self.last_levels_sent | |
313 if diff >= 2: # too long since last send | |
314 self.send_dmx_levels() | |
315 self.after(200, self.send_dmx_levels_loop) | |
316 else: | |
317 self.after(int((2 - diff) * 100), self.send_dmx_levels_loop) | |
163 | 318 def get_scale_desc(self, val, name): |
168 | 319 """Returns a description to the TimedGoButton""" |
163 | 320 go_button = self.go_buttons.get(name) |
321 if go_button: | |
322 time = go_button.get_time() | |
323 return "%0.2f%%, %0.1fs left" % (val, time - ((val / 100.0) * time)) | |
324 else: | |
325 return "%0.2f%%" % val | |
155 | 326 def toggle_autoshift(self): |
327 for name, button in self.shift_buttons.items(): | |
328 if not self.auto_shift.get(): | |
329 button.pack(side='bottom', fill='both', expand=1) | |
330 else: | |
331 button.pack_forget() | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
332 def shift(self, name): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
333 # to prevent overshifting |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
334 if self.no_shifts_until_release: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
335 return |
178 | 336 # print "shift", name |
155 | 337 |
178 | 338 self.cuelist.shift((-1, 1)[name == 'Next']) |
339 self.update_cue_cache(compute_dmx_levels=0) | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
340 for scale_name, scale in self.scales.items(): |
178 | 341 # print "shift: setting scale to 0", scale_name |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
342 scale.scale.set(0) |
179 | 343 self.go_buttons[scale_name].manual_override() |
178 | 344 self.update_cue_cache(compute_dmx_levels=1) |
167 | 345 |
168 | 346 if self.auto_load_times.get(): |
347 self.reload_cue_times() | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
348 def autoshift(self, name, scale): |
0 | 349 scale_val = scale.scale_var.get() |
350 | |
351 if scale_val == 1: | |
155 | 352 if self.auto_shift.get(): |
0 | 353 self.shift(name) |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
354 def xfade(self, name, scale): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
355 if self.auto_shift.get(): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
356 self.autoshift(name, scale) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
357 scale_val = scale.scale_var.get() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
358 else: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
359 scale_val = scale.scale_var.get() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
360 if scale_val == 1: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
361 self.shift_buttons[name]['state'] = 'normal' |
151
990a9474d0e7
early cue stuff. the CueList will supply the CueFader with the cues to
dmcc
parents:
0
diff
changeset
|
362 else: |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
363 # disable any dangerous shifting |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
364 self.shift_buttons[name]['state'] = 'disabled' |
0 | 365 |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
366 d = self.opposite_direction(name) |
0 | 367 if scale_val != 0: |
368 # disable illegal three part crossfades | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
369 self.scales[d].disable() |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
370 self.go_buttons[d].disable() |
0 | 371 else: |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
372 # undo above work |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
373 self.scales[d].enable() |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
374 self.go_buttons[d].enable() |
167 | 375 |
168 | 376 self.current_dir = name |
377 self.compute_dmx_levels() | |
158
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
378 def opposite_direction(self, d): |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
379 if d == 'Next': |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
380 return 'Prev' |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
381 else: |
5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
dmcc
parents:
157
diff
changeset
|
382 return 'Next' |
0 | 383 |
384 class Cue: | |
385 """A Cue has a name, a time, and any number of other attributes.""" | |
167 | 386 def __init__(self, name, time=3, sub_levels='', **attrs): |
0 | 387 self.name = name |
388 self.time = time | |
167 | 389 self.sub_levels = sub_levels |
0 | 390 self.__dict__.update(attrs) |
391 def __repr__(self): | |
392 return "<Cue %s, length %s>" % (self.name, self.time) | |
167 | 393 def get_levels_as_sub(self): |
394 """Get this Cue as a combined Submaster, normalized. This method | |
395 should not be called constantly, since it is somewhat expensive. It | |
396 will reload the submasters from disk, combine all subs together, and | |
397 then compute the normalized form.""" | |
398 subdict = {} | |
168 | 399 for line in self.sub_levels.split(','): |
400 try: | |
167 | 401 line = line.strip() |
168 | 402 if not line: |
403 continue | |
167 | 404 sub, scale = line.split(':') |
405 sub = sub.strip() | |
406 scale = float(scale) | |
407 subdict[sub] = scale | |
168 | 408 except ValueError: |
409 print "Parsing error for '%s' in %s" % (self.sub_levels, self) | |
167 | 410 |
411 s = Submaster.Submasters() | |
412 newsub = Submaster.sub_maxes(*[s[sub] * scale | |
413 for sub, scale in subdict.items()]) | |
414 return newsub.get_normalized_copy() | |
0 | 415 |
416 empty_cue = Cue('empty') | |
417 | |
418 allow_class_to_be_pickled(Cue) | |
419 | |
420 class CueList: | |
421 """Persistent list of Cues""" | |
422 def __init__(self, filename): | |
423 self.filename = filename | |
424 self.treedict = TreeDict() | |
425 try: | |
426 self.treedict.load(filename) | |
427 except IOError: | |
428 self.treedict.cues = [] | |
429 self.cues = self.treedict.cues | |
167 | 430 self.current_cue_index = -1 |
431 self.next_pointer = 0 | |
0 | 432 self.prev_pointer = None |
433 | |
434 import atexit | |
435 atexit.register(self.save) | |
436 def add_cue(self, cue, index=None): | |
437 """Adds a Cue object to the list. If no index is specified, | |
438 the cue will be added to the end.""" | |
439 index = index or len(self.cues) | |
440 self.cues.insert(index, cue) | |
441 def shift(self, diff): | |
442 """Shift through cue history""" | |
443 old_index = self.current_cue_index | |
444 self.current_cue_index = None | |
445 if diff < 0: # if going backwards | |
446 if self.prev_pointer: # use a prev pointer if we have one | |
447 self.current_cue_index = self.prev_pointer | |
448 self.next_pointer = old_index | |
449 self.prev_pointer = None | |
450 else: | |
451 if self.next_pointer: # use a next pointer if we have one | |
452 self.current_cue_index = self.next_pointer | |
453 self.next_pointer = None | |
454 self.prev_pointer = old_index | |
455 if not self.current_cue_index: | |
456 self.current_cue_index = old_index + diff | |
457 def set_next(self, index): | |
458 self.next_pointer = index | |
459 def set_prev(self, index): | |
460 self.prev_pointer = index | |
461 def bound_index(self, index): | |
168 | 462 if not self.cues or index < 0: |
0 | 463 return None |
464 else: | |
168 | 465 return min(index, len(self.cues) - 1) |
0 | 466 def get_current_cue_indices(self): |
168 | 467 """Returns a list of the indices of three cues: the previous cue, |
468 the current cue, and the next cue.""" | |
0 | 469 cur = self.current_cue_index |
470 return [self.bound_index(index) for index in | |
471 (self.prev_pointer or cur - 1, | |
472 cur, | |
473 self.next_pointer or cur + 1)] | |
474 def get_current_cues(self): | |
168 | 475 """Returns a list of three cues: the previous cue, the current cue, |
476 and the next cue.""" | |
0 | 477 return [self.get_cue_by_index(index) |
478 for index in self.get_current_cue_indices()] | |
479 def get_cue_by_index(self, index): | |
168 | 480 try: |
0 | 481 return self.cues[self.bound_index(index)] |
168 | 482 except TypeError: |
0 | 483 return empty_cue |
484 def __del__(self): | |
485 self.save() | |
151
990a9474d0e7
early cue stuff. the CueList will supply the CueFader with the cues to
dmcc
parents:
0
diff
changeset
|
486 def save(self): |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
487 print "Saving cues to", self.filename |
151
990a9474d0e7
early cue stuff. the CueList will supply the CueFader with the cues to
dmcc
parents:
0
diff
changeset
|
488 self.treedict.save(self.filename) |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
489 def reload(self): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
490 # TODO: we probably will need to make sure that indices still make |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
491 # sense, etc. |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
492 self.treedict.load(self.filename) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
493 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
494 class TkCueList(CueList, Tk.Frame): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
495 def __init__(self, master, filename): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
496 CueList.__init__(self, filename) |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
497 Tk.Frame.__init__(self, master, bg='black') |
168 | 498 self.fader = None |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
499 |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
500 self.edit_tl = Tk.Toplevel() |
168 | 501 self.editor = CueEditron(self.edit_tl, |
502 changed_callback=self.cue_changed) | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
503 self.editor.pack(fill='both', expand=1) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
504 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
505 def edit_cue(index): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
506 index = int(index) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
507 self.editor.set_cue_to_edit(self.cues[index]) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
508 |
181 | 509 self.columns = ('name', 'time', 'page', 'cuenum', 'desc', 'sub_levels') |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
510 self.scrolled_hlist = Tk.ScrolledHList(self, |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
511 options='hlist.columns %d hlist.header 1' % len(self.columns)) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
512 self.hlist = self.scrolled_hlist.hlist |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
513 self.hlist.configure(fg='white', bg='black', |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
514 command=self.select_callback, browsecmd=edit_cue) |
163 | 515 self.hlist.bind("<4>", self.wheelscroll) |
516 self.hlist.bind("<5>", self.wheelscroll) | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
517 self.scrolled_hlist.pack(fill='both', expand=1) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
518 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
519 boldfont = self.tk.call('tix', 'option', 'get', |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
520 'bold_font') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
521 header_style = Tk.DisplayStyle('text', refwindow=self, |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
522 anchor='center', padx=8, pady=2, font=boldfont) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
523 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
524 for count, header in enumerate(self.columns): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
525 self.hlist.header_create(count, itemtype='text', |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
526 text=header, style=header_style) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
527 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
528 self.cue_label_windows = {} |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
529 for count, cue in enumerate(self.cues): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
530 self.display_cue(count, cue) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
531 self.update_cue_indicators() |
168 | 532 def set_fader(self, fader): |
533 self.fader = fader | |
163 | 534 def wheelscroll(self, evt): |
535 """Perform mouse wheel scrolling""" | |
168 | 536 if evt.num == 4: # scroll down |
163 | 537 amount = -2 |
168 | 538 else: # scroll up |
539 amount = 2 | |
163 | 540 self.hlist.yview('scroll', amount, 'units') |
168 | 541 def cue_changed(self, cue): |
163 | 542 path = self.cues.index(cue) |
543 for col, header in enumerate(self.columns): | |
544 try: | |
545 text = getattr(cue, header) | |
546 except AttributeError: | |
547 text = '' | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
548 |
163 | 549 if col == 0: |
550 self.cue_label_windows[path]['text'] = text | |
551 else: | |
552 self.hlist.item_configure(path, col, text=text) | |
168 | 553 |
554 if cue in self.get_current_cues() and self.fader: | |
555 self.fader.update_cue_cache() | |
556 self.fader.reload_cue_times() | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
557 def display_cue(self, path, cue): |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
558 for col, header in enumerate(self.columns): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
559 try: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
560 text = getattr(cue, header) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
561 except AttributeError: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
562 text = '' |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
563 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
564 if col == 0: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
565 lab = Tk.Label(self.hlist, text=text, fg='white', bg='black') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
566 def select_and_highlight(event): |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
567 self.select_callback(path) |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
568 self.hlist.selection_clear() |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
569 self.hlist.selection_set(path) |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
570 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
571 lab.bind("<Double-1>", select_and_highlight) |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
572 self.hlist.add(path, itemtype='window', window=lab) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
573 self.cue_label_windows[path] = lab |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
574 else: |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
575 self.hlist.item_create(path, col, text=text) |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
576 def reset_cue_indicators(self, cue_indices=None): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
577 """If cue_indices is None, we'll reset all of them.""" |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
578 cue_indices = cue_indices or self.cue_label_windows.keys() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
579 for key in cue_indices: |
168 | 580 if key is None: |
581 continue | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
582 window = self.cue_label_windows[key] |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
583 window.configure(fg='white', bg='black') |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
584 def update_cue_indicators(self): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
585 states = dict(zip(self.get_current_cue_indices(), |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
586 ('prev', 'cur', 'next'))) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
587 |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
588 for count, state in states.items(): |
168 | 589 if count is None: |
590 continue | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
591 window = self.cue_label_windows[count] |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
592 bg, fg = cue_state_indicator_colors[state] |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
593 window.configure(bg=bg, fg=fg) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
594 def shift(self, diff): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
595 self.reset_cue_indicators(self.get_current_cue_indices()) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
596 CueList.shift(self, diff) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
597 self.update_cue_indicators() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
598 # try to see all indices, but next takes priority over all, and cur |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
599 # over prev |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
600 for index in self.get_current_cue_indices(): |
168 | 601 if index is not None: |
602 self.hlist.see(index) | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
603 def select_callback(self, index): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
604 new_next = int(index) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
605 self.set_next(new_next) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
606 def set_next(self, index): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
607 prev, cur, next = self.get_current_cue_indices() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
608 self.reset_cue_indicators((next,)) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
609 CueList.set_next(self, index) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
610 self.update_cue_indicators() |
178 | 611 |
612 if self.fader: # XXX this is untested | |
613 self.fader.update_cue_cache() | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
614 def set_prev(self, index): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
615 prev, cur, next = self.get_current_cue_indices() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
616 self.reset_cue_indicators((prev,)) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
617 CueList.set_prev(self, index) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
618 self.update_cue_indicators() |
178 | 619 |
620 if self.fader: # XXX this is untested | |
621 self.fader.update_cue_cache() | |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
622 def set_selection_as_prev(self): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
623 sel = self.hlist.info_selection() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
624 if sel: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
625 self.set_prev(int(sel[0])) |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
626 def set_selection_as_next(self): |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
627 sel = self.hlist.info_selection() |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
628 if sel: |
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
629 self.set_next(int(sel[0])) |
0 | 630 |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
631 class CueEditron(Tk.Frame): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
632 def __init__(self, master, changed_callback=None, cue=None): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
633 Tk.Frame.__init__(self, master, bg='black') |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
634 self.master = master |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
635 self.cue = cue |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
636 self.changed_callback = changed_callback |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
637 self.enable_callbacks = 1 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
638 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
639 self.setup_editing_forms() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
640 self.set_cue_to_edit(cue) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
641 def set_cue_to_edit(self, cue): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
642 if cue != self.cue: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
643 self.cue = cue |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
644 self.fill_in_cue_info() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
645 self.set_title() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
646 def set_title(self): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
647 try: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
648 self.master.title("Editing '%s'" % self.cue.name) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
649 except AttributeError: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
650 pass |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
651 def setup_editing_forms(self): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
652 self.variables = {} |
176 | 653 for row, field in enumerate(('name', 'time', 'page', 'cuenum', 'desc', |
168 | 654 'sub_levels')): |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
655 lab = Tk.Label(self, text=field, fg='white', bg='black') |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
656 lab.grid(row=row, column=0, sticky='nsew') |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
657 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
658 entryvar = Tk.StringVar() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
659 entry = Tk.Entry(self, fg='white', bg='black', |
176 | 660 textvariable=entryvar, insertbackground='white', |
178 | 661 highlightcolor='red') # TODO this red/black is backwards |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
662 entry.grid(row=row, column=1, sticky='nsew') |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
663 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
664 self.variables[field] = entryvar |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
665 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
666 def field_changed(x, y, z, field=field, entryvar=entryvar): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
667 if self.cue: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
668 setattr(self.cue, field, entryvar.get()) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
669 if self.enable_callbacks and self.changed_callback: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
670 self.changed_callback(self.cue) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
671 if field == 'name': |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
672 self.set_title() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
673 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
674 entryvar.trace('w', field_changed) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
675 self.columnconfigure(1, weight=1) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
676 def fill_in_cue_info(self): |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
677 self.enable_callbacks = 0 |
176 | 678 for row, field in enumerate(('name', 'time', 'page', 'cuenum', 'desc', |
168 | 679 'sub_levels')): |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
680 text = '' |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
681 if self.cue: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
682 try: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
683 text = getattr(self.cue, field) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
684 except AttributeError: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
685 pass |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
686 self.variables[field].set(text) |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
687 self.enable_callbacks = 1 |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
688 |
0 | 689 if __name__ == "__main__": |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
690 root = Tk.Tk() |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
691 root.title("ShowMaster 9000") |
178 | 692 root.geometry("600x670") |
171 | 693 cl = TkCueList(root, 'cues/dolly') |
161
0803fb42109d
we now have TkCueList, which is really cool. it doesn't provide editing
dmcc
parents:
158
diff
changeset
|
694 cl.pack(fill='both', expand=1) |
0 | 695 |
157 | 696 fader = CueFader(root, cl) |
697 fader.pack(fill='both', expand=1) | |
162
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
698 try: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
699 Tk.mainloop() |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
700 except KeyboardInterrupt: |
6c5753bad783
basic cue editing, darker colors, fade time selector is now a "TixControl"
dmcc
parents:
161
diff
changeset
|
701 root.destroy() |