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