diff --git a/light8/panels.py b/light8/panels.py --- a/light8/panels.py +++ b/light8/panels.py @@ -5,7 +5,6 @@ from Tix import * from uihelpers import * import Patch from FlyingFader import FlyingFader -import Pmw stdfont = ('Arial', 8) monofont = ('Courier', 8) @@ -22,16 +21,16 @@ class Controlpanel(Frame): ('Clear X', lambda: xfader.clearallbuttons('x')), ('On -> Y', lambda: xfader.grab('y')), ('Clear Y', lambda: xfader.clearallbuttons('y'))): - # ('Jostle', jostle_cb)): Button(controlpanel, text=txt, command=cmd).pack(side='top', fill='x') + # jostle button Checkbutton(controlpanel, text="Jostle", command=jostle_cb).pack(side=TOP, fill=X) class Console: def __init__(self,lightboard): print "Light 8: Everything's under control" - t=toplevelat('console', lightboard.windowpos) + t=toplevelat('console') self.frame = Frame(t) self.entry=Entry(self.frame) self.entry.pack(expand=1, fill='x') @@ -80,6 +79,142 @@ class Leveldisplay: # channel_levels is an output - changelevel will use it to access # these labels +class ExtSliderMapper(Frame): + def __init__(self, parent, sliderlevels, sliderinput, filename='slidermapping', + numsliders=4): + 'Slider levels is scalelevels, sliderinput is an ExternalInput object' + Frame.__init__(self, parent) + self.parent = parent + self.sliderlevels = sliderlevels + self.sliderinput = sliderinput + self.filename = filename + self.numsliders = numsliders + self.file = None + + # self.setup() + def setup(self): + self.subnames = self.sliderlevels.keys() + self.subnames.sort() + self.presets = {} + self.load_presets() + + self.current_mapping_name = StringVar() + self.current_mapping = [] + self.attached = [] + self.levels_read = [] + for i in range(self.numsliders): + self.current_mapping.append(StringVar()) + self.attached.append(BooleanVar()) + self.levels_read.append(DoubleVar()) + + self.reallevellabels = [] + self.draw_interface() + def load_presets(self): + self.file = open(self.filename, 'r') + lines = self.file.readlines() + for l in lines: + tokens = l[:-1].split('\t') + name = tokens.pop(0) + self.presets[name] = tokens + self.file.close() + def save_presets(self): + self.file = open(self.filename, 'w') + self.file.seek(0) + preset_names = self.presets.keys() + preset_names.sort() + for p in preset_names: + s = '\t'.join([p] + self.presets[p]) + '\n' + self.file.write(s) + self.file.close() + def load_scalelevels(self): + for m, rll in zip(self.current_mapping, self.reallevellabels): + try: + v = self.sliderlevels[m.get()] + rll.configure(textvariable=v) + except KeyError: + pass + + def get_levels(self): + 'To be called by changelevels, I think' + if not self.current_mapping_name: return {} + if not self.sliderinput: return {} + + self.load_scalelevels() + + rawlevels = self.sliderinput.get_levels() + for rawlev, levlabvar in zip(rawlevels, self.levels_read): + levlabvar.set(rawlev) + outputlevels = {} + return dict([(name.get(), lev) + for name, lev, att in zip(self.current_mapping, + rawlevels, + self.attached) + if att.get()]) + + def draw_interface(self): + self.reallevellabels = [] + subchoiceframe = Frame(self) + for i, mapping, isattached, lev in zip(range(self.numsliders), + self.current_mapping, + self.attached, + self.levels_read): + f = Frame(subchoiceframe) + # Label(f, text="Slider %d" % (i+1)).pack(side=LEFT) + c = ComboBox(f, variable=mapping) + for s in self.subnames: + c.slistbox.listbox.insert(END, s) + c.entry.configure(width=12) + statframe = Frame(f) + Checkbutton(statframe, variable=isattached, + text="Attached").grid(columnspan=2, sticky=W) + Label(statframe, text="Input", fg='red').grid(row=1, sticky=W) + Label(statframe, textvariable=lev, fg='red', width=5).grid(row=1, column=1) + Label(statframe, text="Real").grid(row=2, sticky=W) + l = Label(statframe, text="N/A", width=5) + l.grid(row=2, column=1) + self.reallevellabels.append(l) + statframe.pack(side=BOTTOM, expand=1, fill=X) + c.pack() + f.pack(side=LEFT) + subchoiceframe.pack() + + presetframe = Frame(self) + Label(presetframe, text="Preset:").pack(side=LEFT) + self.presetcombo = ComboBox(presetframe, variable=self.current_mapping_name, + editable=1, command=self.apply_preset) + self.draw_presets() + self.presetcombo.pack(side=LEFT) + Button(presetframe, text="Add", padx=0, pady=0, + command=self.add_preset).pack(side=LEFT) + Button(presetframe, text="Delete", padx=0, pady=0, + command=self.delete_preset).pack(side=LEFT) + presetframe.pack(side=BOTTOM) + def apply_preset(self, preset): + if not preset: return + mapping = self.presets.get(preset) + if not mapping: return + for name, var, att in zip(mapping, self.current_mapping, self.attached): + var.set(name) + att.set(0) # detach all sliders + def delete_preset(self, *args): + del self.presets[self.current_mapping_name.get()] + self.presetcombo.slistbox.listbox.delete(0, END) + self.draw_presets() + self.save_presets() + def add_preset(self, *args): + self.presets[self.current_mapping_name.get()] = [m.get() + for m in self.current_mapping] + self.presetcombo.slistbox.listbox.delete(0, END) + self.draw_presets() + self.save_presets() + def draw_presets(self): + preset_names = self.presets.keys() + preset_names.sort() + for p in preset_names: + self.presetcombo.slistbox.listbox.insert(END, p) + + + class Subpanels: def __init__(self, scenesparent, effectsparent, scenes, lightboard, scalelevels, Subs, xfader, @@ -195,3 +330,11 @@ class Subpanels: xfader.registerbutton(name,axis,cvar) +if __name__ == '__main__': + print "testing external sliders" + root = Tk() + fakesliderlevels = dict([('sub%d' % n, DoubleVar()) for n in range(12)]) + esm = ExtSliderMapper(root, fakesliderlevels, None) + esm.pack() + + mainloop()