comparison light8/Fader.py @ 54:3011c1028eb7

Cue math error fixed. Cue math error fixed. Bad cues in ConfigDummy fixed, not fixed in Config yet. Cue fader back in rsn. Oh yeah.
author dmcc
date Mon, 08 Jul 2002 15:50:00 +0000
parents 032b2b67bc10
children e04f7b552bcd
comparison
equal deleted inserted replaced
53:032b2b67bc10 54:3011c1028eb7
7 # stopped - no cue is loaded or cue is stopped 7 # stopped - no cue is loaded or cue is stopped
8 # running - cue is running, not complete 8 # running - cue is running, not complete
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
13 def get_selection(listbox):
14 'Given a listbox, returns first selection as integer'
15 selection = int(listbox.curselection()[0]) # blech
16 return selection
12 17
13 class Fader(Frame): 18 class Fader(Frame):
14 'User interface for cue fader' 19 'User interface for cue fader'
15 def __init__(self, master, cues, scalelevels): 20 def __init__(self, master, cues, scalelevels):
16 self.master = master 21 self.master = master
38 self.cuetimeelapse.set('0s') 43 self.cuetimeelapse.set('0s')
39 self.cuetimeleft = StringVar() # time left 44 self.cuetimeleft = StringVar() # time left
40 self.cuetimeleft.set('0s') 45 self.cuetimeleft.set('0s')
41 46
42 buttonframe = Frame(self) 47 buttonframe = Frame(self)
48 topframe = Frame(self) # to contain cue list and infoframe
49 infoframe = Frame(topframe)
50 topframe.pack()
43 51
44 self.listbox = ScrolledListBox(buttonframe, 52 self.listbox = ScrolledListBox(topframe,
45 command=self.update_selection) 53 command=self.update_selection)
46 self.listbox.listbox.configure({'exportselection' : 0, 54 self.listbox.listbox.configure({'exportselection' : 0,
47 'selectmode' : EXTENDED}) 55 'selectmode' : EXTENDED})
48 for c in self.cues: 56 for c in self.cues:
49 self.listbox.listbox.insert(END, c.name) 57 self.listbox.listbox.insert(END, c.name)
50 self.listbox.pack(side=TOP) 58 self.listbox.pack(side=LEFT)
51 self.listbox.listbox.bind("<<ListboxSelect>>", self.update_selection, 59 self.listbox.listbox.bind("<<ListboxSelect>>", self.update_selection,
52 add=1) 60 add=1)
53 Button(buttonframe, text="Go", command=self.go, font=stdfont, 61 Button(buttonframe, text="Go", command=self.go, font=stdfont,
54 bg='green').pack(side=LEFT) 62 bg='green').pack(side=LEFT)
55 Button(buttonframe, text="Stop", command=self.stop, font=stdfont, 63 Button(buttonframe, text="Stop", command=self.stop, font=stdfont,
56 bg='red').pack(side=LEFT) 64 bg='red').pack(side=LEFT)
57 Button(buttonframe, text="Prev", command=self.prev, 65 Button(buttonframe, text="Prev", command=self.prev,
58 font=stdfont).pack(side=LEFT) 66 font=stdfont).pack(side=LEFT)
59 Button(buttonframe, text="Next", command=self.next, 67 nextbutton = Button(buttonframe, text="Next", command=self.next,
60 font=stdfont).pack(side=LEFT) 68 font=stdfont)
69 # Button(buttonframe, text="Load", command=self.mark_start, bg='grey80',
70 # font=stdfont).pack(side=LEFT)
61 71
62 infoframe = Frame(self)
63 Label(infoframe, textvariable=self.cuename, 72 Label(infoframe, textvariable=self.cuename,
64 font=('Arial', 12), bg='lightBlue').grid(columnspan=4, sticky=NE+SW) 73 font=('Arial', 12), bg='lightBlue').grid(columnspan=4, sticky=NE+SW)
65 74
66 Label(infoframe, text="Length", font=stdfont, 75 Label(infoframe, text="Length", font=stdfont,
67 bg='lightPink').grid(row=1, sticky=NE+SW) 76 bg='lightPink').grid(row=1, sticky=NE+SW)
68 Label(infoframe, textvariable=self.cuelength, 77 Label(infoframe, textvariable=self.cuelength,
69 font=stdfont).grid(row=1, column=1, columnspan=3, sticky=NE+SW) 78 font=stdfont).grid(row=1, column=1, columnspan=3, sticky=NE+SW)
70 79
71 Label(infoframe, text="Target", font=stdfont, 80 Label(infoframe, text="Target", font=stdfont,
72 bg='lightPink', wraplength=50).grid(row=2, sticky=NE+SW) 81 bg='lightPink').grid(row=2, sticky=NE+SW)
73 Label(infoframe, textvariable=self.cuetarget, 82 Label(infoframe, textvariable=self.cuetarget,
74 font=stdfont).grid(row=2, column=1, columnspan=3, sticky=NE+SW) 83 font=stdfont, wraplength=250).grid(row=2, column=1, columnspan=3,
84 sticky=NE+SW)
75 85
76 Label(infoframe, text="Status", font=stdfont, 86 Label(infoframe, text="Status", font=stdfont,
77 bg='lightPink').grid(row=3, sticky=NE+SW) 87 bg='lightPink').grid(row=3, sticky=NE+SW)
78 Label(infoframe, textvariable=self.cuestatus, 88 Label(infoframe, textvariable=self.cuestatus,
79 font=stdfont).grid(row=3, column=1, columnspan=3, sticky=NE+SW) 89 font=stdfont).grid(row=3, column=1, columnspan=3, sticky=NE+SW)
92 bg='lightPink').grid(row=5, column=0, sticky=NE+SW) 102 bg='lightPink').grid(row=5, column=0, sticky=NE+SW)
93 self.percentlabel = Label(infoframe, 103 self.percentlabel = Label(infoframe,
94 font=stdfont) 104 font=stdfont)
95 self.percentlabel.grid(row=5, column=1, columnspan=3, sticky=NE+SW) 105 self.percentlabel.grid(row=5, column=1, columnspan=3, sticky=NE+SW)
96 106
97 s = Scale(infoframe, variable=self.cuepercent, 107 # s = Scale(infoframe, variable=self.cuepercent,
108 s = Scale(buttonframe, variable=self.cuepercent,
98 showvalue=0, length=220, 109 showvalue=0, length=220,
99 width=18, sliderlength=30, 110 width=18, sliderlength=30,
100 to=100,res=.1,from_=0,bd=1, font=stdfont, 111 to=100,res=.1,from_=0,bd=1, font=stdfont,
101 orient='horiz') 112 orient='horiz')
102 s.grid(row=6, columnspan=4, sticky='ew') 113 # s.grid(row=6, columnspan=4, sticky='ew')
114 nextbutton.pack(side=RIGHT)
115 s.pack(side=RIGHT, expand=1, fill=X)
103 116
104 infoframe.pack(side=RIGHT, fill=BOTH, expand=1) 117 infoframe.pack(side=RIGHT, fill=BOTH, expand=1)
105 buttonframe.pack(side=BOTTOM) 118 buttonframe.pack(side=BOTTOM, expand=1, fill=X)
106 119
107 self.listbox.listbox.select_set(0) 120 self.listbox.listbox.select_set(0)
108 self.update_selection() 121 self.update_selection()
122 def mark_start(self):
123 self.time_start = time()
124 startlevels = dict([(k, v.get()) for k, v in self.scalelevels.items()])
125 # print "going to mark with", startlevels
126 self.current.start(startlevels, self.time_start)
109 def update_percent(self, *args): 127 def update_percent(self, *args):
110 if self.cuestatus.get() != 'running': 128 if self.cuestatus.get() != 'running':
111 self.cuestatus.set("running") 129 self.cuestatus.set("running")
112 self.time_start = time() 130 self.mark_start()
113 startlevels = dict([(k, v.get())
114 for k, v in self.scalelevels.items()])
115 self.current.start(startlevels, self.time_start)
116 131
117 percent = self.cuepercent.get() 132 percent = self.cuepercent.get()
118 self.percentlabel.config(text='%.1f%%' % percent) 133 self.percentlabel.config(text='%.1f%%' % percent)
119 percent /= 100 134 percent /= 100
120 135
121 elapsed = percent * self.current.dur 136 elapsed = percent * self.current.dur
122 self.cuetimeelapse.set('%.1fs' % elapsed) 137 self.cuetimeelapse.set('%.1fs' % elapsed)
123 self.cuetimeleft.set('%.1fs' % (self.current.dur - elapsed)) 138 self.cuetimeleft.set('%.1fs' % (self.current.dur - elapsed))
139
124 newlevels = self.current.get_levels(self.time_start + elapsed) 140 newlevels = self.current.get_levels(self.time_start + elapsed)
141 # print "newlevels", newlevels
125 for ch, lev in newlevels.items(): 142 for ch, lev in newlevels.items():
126 try: 143 try:
127 self.scalelevels[ch].set(lev / 100.0) 144 self.scalelevels[ch].set(lev)
128 except KeyError: 145 except KeyError:
129 pass 146 pass
130 147
131 def update_selection(self, *args): 148 def update_selection(self, *args):
132 selection = int(self.listbox.listbox.curselection()[0]) # blech 149 self.cuestatus.set('stopped')
150 selection = get_selection(self.listbox.listbox)
133 self.current = self.cues[selection] 151 self.current = self.cues[selection]
134 self.cuename.set(self.current.name) 152 self.cuename.set(self.current.name)
135 self.cuelength.set(self.current.dur) 153 self.cuelength.set(self.current.dur)
136 target = ', '.join(['%s -> %.1f' % (n, lev) 154 target = ', '.join(['%s -> %.2f' % (n, lev)
137 for n, lev in self.current.get_end_levels().items()]) 155 for n, lev in self.current.get_end_levels().items()])
138 self.cuetarget.set(target) 156 self.cuetarget.set(target)
139 self.cuetimeelapse.set('0s') 157 self.cuetimeelapse.set('0s')
140 self.cuetimeleft.set('%.1fs' % self.current.dur) 158 self.cuetimeleft.set('%.1fs' % self.current.dur)
141 self.cuepercent.set(0) 159 self.cuepercent.set(0)
142 def go(self): 160 def go(self):
143 self.update_selection() 161 self.update_selection()
144 self.cuestatus.set("running") 162 self.cuestatus.set("running")
145 self.time_start = time() 163 self.mark_start()
146 startlevels = dict([(k, v.get()) for k, v in self.scalelevels.items()])
147 self.current.start(startlevels, self.time_start)
148 self.running_loop() 164 self.running_loop()
149 def stop(self): 165 def stop(self):
150 self.cuestatus.set('stopped') 166 self.cuestatus.set('stopped')
151 def prev(self): 167 def prev(self):
152 self.cuestatus.set('stopped') 168 self.stop()
153 selection = int(self.listbox.listbox.curselection()[0]) # blech 169 selection = get_selection(self.listbox.listbox)
154 if selection != 0: 170 if selection != 0:
155 self.listbox.listbox.select_clear(selection) 171 self.listbox.listbox.select_clear(selection)
156 self.listbox.listbox.select_set(selection - 1) 172 self.listbox.listbox.select_set(selection - 1)
157 self.update_selection() 173 self.update_selection()
174 self.mark_start()
158 def next(self): 175 def next(self):
159 self.cuestatus.set('stopped') 176 self.stop()
160 selection = int(self.listbox.listbox.curselection()[0]) # blech 177 selection = get_selection(self.listbox.listbox)
161 if selection != self.listbox.listbox.size() - 1: 178 if selection != self.listbox.listbox.size() - 1:
162 self.listbox.listbox.select_clear(selection) 179 self.listbox.listbox.select_clear(selection)
163 self.listbox.listbox.select_set(selection + 1) 180 self.listbox.listbox.select_set(selection + 1)
164 self.update_selection() 181 self.update_selection()
182 self.mark_start()
165 def running_loop(self): 183 def running_loop(self):
166 if self.cuestatus.get() == 'stopped': 184 if self.cuestatus.get() == 'stopped':
167 return 185 return
168 curtime = time() 186 curtime = time()
169 elapsed = (curtime - self.time_start) 187 elapsed = (curtime - self.time_start)
188
170 if elapsed > self.current.dur: 189 if elapsed > self.current.dur:
171 self.cuestatus.set('finished') 190 self.cuestatus.set('stopped')
172 self.cuepercent.set(100) 191 self.cuepercent.set(100)
173 192
174 # advance cues if okay 193 # advance cues if okay
175 self.next() 194 self.next()
176 return 195 return