Mercurial > code > home > repos > light9
comparison light8/Fader.py @ 53:032b2b67bc10
result of July 7th on-site editing
author | dmcc |
---|---|
date | Mon, 08 Jul 2002 14:31:20 +0000 |
parents | 065896b0913c |
children | 3011c1028eb7 |
comparison
equal
deleted
inserted
replaced
52:065896b0913c | 53:032b2b67bc10 |
---|---|
1 from Tix import * | 1 from Tix import * |
2 from time import time # time is on my side | 2 from time import time # time is on my side |
3 from util import subsetdict | 3 from util import subsetdict |
4 from FlyingFader import FlyingFader | |
4 | 5 |
5 # statuses are: | 6 # statuses are: |
6 # stopped - no cue is loaded | 7 # stopped - no cue is loaded or cue is stopped |
7 # running - cue is running, not complete | 8 # running - cue is running, not complete |
8 # halted - cue stops wherever it was, can't continue | |
9 # finished - cue is finished, next is loaded | 9 # finished - cue is finished, next is loaded |
10 | 10 |
11 stdfont = ('Arial', 10) | 11 stdfont = ('Arial', 10) |
12 | 12 |
13 class Fader(Frame): | 13 class Fader(Frame): |
14 'User interface for cue fader' | 14 'User interface for cue fader' |
15 def __init__(self, master, cues, scalelevels): | 15 def __init__(self, master, cues, scalelevels): |
16 self.master = master | 16 self.master = master |
17 self.cues = cues | 17 self.cues = cues |
18 self.scalelevels = scalelevels | 18 self.scalelevels = scalelevels |
19 self.time_start = 0 | |
19 self.init_layout() | 20 self.init_layout() |
21 self.stop() | |
20 def init_layout(self): | 22 def init_layout(self): |
21 Frame.__init__(self, self.master) | 23 Frame.__init__(self, self.master) |
22 | 24 |
23 # info variables | 25 # info variables |
24 self.cuename = StringVar() | 26 self.cuename = StringVar() |
29 self.cuestatus = StringVar() # text description | 31 self.cuestatus = StringVar() # text description |
30 self.cuestatus.set("stopped") | 32 self.cuestatus.set("stopped") |
31 | 33 |
32 self.cuepercent = DoubleVar() # percent complete | 34 self.cuepercent = DoubleVar() # percent complete |
33 self.cuepercent.set(0) | 35 self.cuepercent.set(0) |
34 self.cuetime = StringVar() # time left | 36 self.cuepercent.trace('w', self.update_percent) |
35 self.cuetime.set('0 / 0') | 37 self.cuetimeelapse = StringVar() # time elapsed |
38 self.cuetimeelapse.set('0s') | |
39 self.cuetimeleft = StringVar() # time left | |
40 self.cuetimeleft.set('0s') | |
36 | 41 |
37 buttonframe = Frame(self) | 42 buttonframe = Frame(self) |
38 | 43 |
39 self.listbox = ScrolledListBox(buttonframe) | 44 self.listbox = ScrolledListBox(buttonframe, |
40 self.listbox.listbox.configure({'exportselection' : 0}) | 45 command=self.update_selection) |
46 self.listbox.listbox.configure({'exportselection' : 0, | |
47 'selectmode' : EXTENDED}) | |
41 for c in self.cues: | 48 for c in self.cues: |
42 self.listbox.listbox.insert(END, c.name) | 49 self.listbox.listbox.insert(END, c.name) |
43 self.listbox.pack(side=TOP) | 50 self.listbox.pack(side=TOP) |
44 Button(buttonframe, text="Go", command=self.go).pack(side=LEFT) | 51 self.listbox.listbox.bind("<<ListboxSelect>>", self.update_selection, |
45 Button(buttonframe, text="Halt").pack(side=LEFT) | 52 add=1) |
46 Button(buttonframe, text="Clear").pack(side=LEFT) | 53 Button(buttonframe, text="Go", command=self.go, font=stdfont, |
54 bg='green').pack(side=LEFT) | |
55 Button(buttonframe, text="Stop", command=self.stop, font=stdfont, | |
56 bg='red').pack(side=LEFT) | |
57 Button(buttonframe, text="Prev", command=self.prev, | |
58 font=stdfont).pack(side=LEFT) | |
59 Button(buttonframe, text="Next", command=self.next, | |
60 font=stdfont).pack(side=LEFT) | |
47 | 61 |
48 infoframe = Frame(self) | 62 infoframe = Frame(self) |
49 Label(infoframe, textvariable=self.cuename, | 63 Label(infoframe, textvariable=self.cuename, |
50 font=('Arial', 12), bg='lightBlue').grid(columnspan=2, sticky=NE+SW) | 64 font=('Arial', 12), bg='lightBlue').grid(columnspan=4, sticky=NE+SW) |
51 | 65 |
52 Label(infoframe, text="Length", font=stdfont, | 66 Label(infoframe, text="Length", font=stdfont, |
53 bg='lightPink').grid(row=1, sticky=NE+SW) | 67 bg='lightPink').grid(row=1, sticky=NE+SW) |
54 Label(infoframe, textvariable=self.cuelength, | 68 Label(infoframe, textvariable=self.cuelength, |
55 font=stdfont).grid(row=1, column=1, sticky=NE+SW) | 69 font=stdfont).grid(row=1, column=1, columnspan=3, sticky=NE+SW) |
56 | 70 |
57 Label(infoframe, text="Target", font=stdfont, | 71 Label(infoframe, text="Target", font=stdfont, |
58 bg='lightPink', wraplength=50).grid(row=2, sticky=NE+SW) | 72 bg='lightPink', wraplength=50).grid(row=2, sticky=NE+SW) |
59 Label(infoframe, textvariable=self.cuetarget, | 73 Label(infoframe, textvariable=self.cuetarget, |
60 font=stdfont).grid(row=2, column=1, sticky=NE+SW) | 74 font=stdfont).grid(row=2, column=1, columnspan=3, sticky=NE+SW) |
61 | 75 |
62 Label(infoframe, text="Status", font=stdfont, | 76 Label(infoframe, text="Status", font=stdfont, |
63 bg='lightPink').grid(row=3, sticky=NE+SW) | 77 bg='lightPink').grid(row=3, sticky=NE+SW) |
64 Label(infoframe, textvariable=self.cuestatus, | 78 Label(infoframe, textvariable=self.cuestatus, |
65 font=stdfont).grid(row=3, column=1, sticky=NE+SW) | 79 font=stdfont).grid(row=3, column=1, columnspan=3, sticky=NE+SW) |
66 | 80 |
67 Label(infoframe, text="Time", font=stdfont, | 81 Label(infoframe, text="Time Elapsed", font=stdfont, |
68 bg='lightPink').grid(row=4, sticky=NE+SW) | 82 bg='lightPink').grid(row=4, sticky=NE+SW) |
69 Label(infoframe, textvariable=self.cuetime, | 83 Label(infoframe, textvariable=self.cuetimeelapse, |
70 font=stdfont).grid(row=4, column=1, sticky=NE+SW) | 84 font=stdfont).grid(row=4, column=1, sticky=NE+SW) |
71 | 85 |
86 Label(infoframe, text="Time Remain", font=stdfont, | |
87 bg='lightPink').grid(row=4, column=2, sticky=NE+SW) | |
88 Label(infoframe, textvariable=self.cuetimeleft, | |
89 font=stdfont).grid(row=4, column=3, sticky=NE+SW) | |
90 | |
72 Label(infoframe, text="Percent Complete", font=stdfont, | 91 Label(infoframe, text="Percent Complete", font=stdfont, |
73 bg='lightPink').grid(row=5, sticky=NE+SW) | 92 bg='lightPink').grid(row=5, column=0, sticky=NE+SW) |
74 Label(infoframe, textvariable=self.cuepercent, | 93 self.percentlabel = Label(infoframe, |
75 font=stdfont).grid(row=5, column=1, sticky=NE+SW) | 94 font=stdfont) |
95 self.percentlabel.grid(row=5, column=1, columnspan=3, sticky=NE+SW) | |
96 | |
97 s = Scale(infoframe, variable=self.cuepercent, | |
98 showvalue=0, length=220, | |
99 width=18, sliderlength=30, | |
100 to=100,res=.1,from_=0,bd=1, font=stdfont, | |
101 orient='horiz') | |
102 s.grid(row=6, columnspan=4, sticky='ew') | |
76 | 103 |
77 infoframe.pack(side=RIGHT, fill=BOTH, expand=1) | 104 infoframe.pack(side=RIGHT, fill=BOTH, expand=1) |
78 buttonframe.pack(side=BOTTOM) | 105 buttonframe.pack(side=BOTTOM) |
79 | 106 |
80 self.listbox.listbox.select_set(0) | 107 self.listbox.listbox.select_set(0) |
81 self.update_selection() | 108 self.update_selection() |
82 def update_selection(self): | 109 def update_percent(self, *args): |
110 if self.cuestatus.get() != 'running': | |
111 self.cuestatus.set("running") | |
112 self.time_start = time() | |
113 startlevels = dict([(k, v.get()) | |
114 for k, v in self.scalelevels.items()]) | |
115 self.current.start(startlevels, self.time_start) | |
116 | |
117 percent = self.cuepercent.get() | |
118 self.percentlabel.config(text='%.1f%%' % percent) | |
119 percent /= 100 | |
120 | |
121 elapsed = percent * self.current.dur | |
122 self.cuetimeelapse.set('%.1fs' % elapsed) | |
123 self.cuetimeleft.set('%.1fs' % (self.current.dur - elapsed)) | |
124 newlevels = self.current.get_levels(self.time_start + elapsed) | |
125 for ch, lev in newlevels.items(): | |
126 try: | |
127 self.scalelevels[ch].set(lev / 100.0) | |
128 except KeyError: | |
129 pass | |
130 | |
131 def update_selection(self, *args): | |
83 selection = int(self.listbox.listbox.curselection()[0]) # blech | 132 selection = int(self.listbox.listbox.curselection()[0]) # blech |
84 self.current = self.cues[selection] | 133 self.current = self.cues[selection] |
85 self.cuename.set(self.current.name) | 134 self.cuename.set(self.current.name) |
86 self.cuelength.set(self.current.dur) | 135 self.cuelength.set(self.current.dur) |
87 self.cuetarget.set(str(self.current.get_end_levels())) | 136 target = ', '.join(['%s -> %.1f' % (n, lev) |
137 for n, lev in self.current.get_end_levels().items()]) | |
138 self.cuetarget.set(target) | |
139 self.cuetimeelapse.set('0s') | |
140 self.cuetimeleft.set('%.1fs' % self.current.dur) | |
141 self.cuepercent.set(0) | |
88 def go(self): | 142 def go(self): |
89 print 'Fade to', self.current.name | 143 self.update_selection() |
90 self.cuestatus.set("running") | 144 self.cuestatus.set("running") |
91 self.time_start = time() | 145 self.time_start = time() |
92 startlevels = dict([(k, v.get()) for k, v in self.scalelevels.items()]) | 146 startlevels = dict([(k, v.get()) for k, v in self.scalelevels.items()]) |
93 self.current.start(startlevels, self.time_start) | 147 self.current.start(startlevels, self.time_start) |
94 self.running_loop() | 148 self.running_loop() |
149 def stop(self): | |
150 self.cuestatus.set('stopped') | |
151 def prev(self): | |
152 self.cuestatus.set('stopped') | |
153 selection = int(self.listbox.listbox.curselection()[0]) # blech | |
154 if selection != 0: | |
155 self.listbox.listbox.select_clear(selection) | |
156 self.listbox.listbox.select_set(selection - 1) | |
157 self.update_selection() | |
158 def next(self): | |
159 self.cuestatus.set('stopped') | |
160 selection = int(self.listbox.listbox.curselection()[0]) # blech | |
161 if selection != self.listbox.listbox.size() - 1: | |
162 self.listbox.listbox.select_clear(selection) | |
163 self.listbox.listbox.select_set(selection + 1) | |
164 self.update_selection() | |
95 def running_loop(self): | 165 def running_loop(self): |
166 if self.cuestatus.get() == 'stopped': | |
167 return | |
96 curtime = time() | 168 curtime = time() |
97 if (curtime - self.time_start) > self.current.dur: | 169 elapsed = (curtime - self.time_start) |
170 if elapsed > self.current.dur: | |
171 self.cuestatus.set('finished') | |
172 self.cuepercent.set(100) | |
173 | |
174 # advance cues if okay | |
175 self.next() | |
98 return | 176 return |
99 newlevels = self.current.get_levels(time()) | 177 |
100 print newlevels | 178 self.cuepercent.set(100 * elapsed / self.current.dur) |
101 self.after(30, self.running_loop) | 179 self.after(30, self.running_loop) |