Changeset - e0c227168519
[Not reviewed]
default
0 2 0
dmcc - 21 years ago 2003-07-08 08:09:12

- LabelledScales allow for optional formatters
- LabelledScales allow for optional formatters
- more recoloring
- cuelist supports wheel scrolling now
- remove old inefficient cue redrawer
- basic geometry
- share changes to the dummy cuelist
2 files changed with 72 insertions and 46 deletions:
0 comments (0 inline, 0 general)
flax/CueFaders.py
Show inline comments
 
@@ -6,46 +6,59 @@ from TLUtility import enumerate
 

	
 
cue_state_indicator_colors = {
 
             # bg       fg
 
    'prev' : ('blue',   'white'),
 
    'cur' :  ('yellow', 'black'),
 
    'next' : ('red',    'white'),
 
}
 

	
 
class LabelledScale(Tk.Frame):
 
    """Scale with two labels: a name and current value"""
 
    def __init__(self, master, label, **opts):
 
        Tk.Frame.__init__(self, master, bd=2, relief='raised', bg='black')
 
        self.labelformatter = opts.get('labelformatter')
 
        try:
 
            del opts['labelformatter']
 
        except KeyError:
 
            pass
 

	
 
        opts.setdefault('variable', Tk.DoubleVar())
 
        opts.setdefault('showvalue', 0)
 

	
 
        self.normaltrough = opts.get('troughcolor', 'black')
 
        self.flashtrough = opts.get('flashtroughcolor', 'red')
 
        del opts['flashtroughcolor']
 
        try:
 
            del opts['flashtroughcolor']
 
        except KeyError:
 
            pass
 

	
 
        self.scale_var = opts['variable']
 
        self.scale = Tk.Scale(self, **opts)
 
        self.scale.pack(side='top', expand=1, fill='both')
 
        self.name = Tk.Label(self, text=label, bg='black', fg='white')
 
        self.name.pack(side='bottom')
 
        self.scale_value = Tk.Label(self, width=6, bg='black', fg='white')
 
        self.scale_value = Tk.Label(self, bg='black', fg='white')
 
        self.scale_value.pack(side='bottom')
 
        self.scale_var.trace('w', self.update_value_label)
 
        self.update_value_label()
 
        self.disabled = (self.scale['state'] == 'disabled')
 
    def set_label(self, label):
 
        self.name['text'] = label
 
    def update_value_label(self, *args):
 
        val = self.scale_var.get() * 100
 
        self.scale_value['text'] = "%0.2f" % val
 
        if self.labelformatter:
 
            format = self.labelformatter(val)
 
        else:
 
            format = "%0.2f" % val
 
        self.scale_value['text'] = format
 
        if val != 0:
 
            self.scale['troughcolor'] = self.flashtrough
 
        else:
 
            self.scale['troughcolor'] = self.normaltrough
 
    def disable(self):
 
        if not self.disabled:
 
            self.scale['state'] = 'disabled'
 
            self.scale_var.set(0)
 
            self.disabled = 1
 
    def enable(self):
 
        if self.disabled:
 
            self.scale['state'] = 'normal'
 
@@ -92,24 +105,26 @@ class TimedGoButton(Tk.Frame):
 
        else:
 
            self.scale_to_fade.scale_var.set(self.end_level)
 
    def disable(self):
 
        if not self.disabled:
 
            self.button['state'] = 'disabled'
 
            self.disabled = 1
 
    def enable(self):
 
        if self.disabled:
 
            self.button['state'] = 'normal'
 
            self.disabled = 0
 
    def set_time(self, time):
 
        self.timer_var.set(time)
 
    def get_time(self):
 
        return self.timer_var.get()
 

	
 
class CueFader(Tk.Frame):
 
    def __init__(self, master, cuelist):
 
        Tk.Frame.__init__(self, master, bg='black')
 
        self.cuelist = cuelist
 
        self.auto_shift = Tk.IntVar()
 
        self.auto_shift.set(1)
 

	
 
        # this is a mechanism to stop Tk from autoshifting too much.
 
        # if this variable is true, the mouse button is down.  we don't want
 
        # to shift until they release it.  when it is released, we will
 
        # set it to false and then call autoshift.
 
@@ -119,41 +134,44 @@ class CueFader(Tk.Frame):
 
        self.shift_buttons = {}
 
        self.go_buttons = {}
 
        
 
        topframe = Tk.Frame(self, bg='black')
 

	
 
        self.set_prev_button = Tk.Button(topframe, text='Set Prev',
 
            command=lambda: cuelist.set_selection_as_prev(),
 
            fg='white', bg='blue')
 
        self.set_prev_button.pack(side='left')
 

	
 
        self.auto_shift_checkbutton = Tk.Checkbutton(topframe, 
 
            variable=self.auto_shift, text='Autoshift', 
 
            command=self.toggle_autoshift, bg='black', fg='white')
 
        self.auto_shift_checkbutton.pack(side='left')
 
            command=self.toggle_autoshift, bg='black', fg='white',
 
            highlightbackground='black')
 
        self.auto_shift_checkbutton.pack(fill='both', side='left')
 

	
 
        self.set_next_button = Tk.Button(topframe, text='Set Next',
 
            command=lambda: cuelist.set_selection_as_next(),
 
            fg='white', bg='red')
 
        self.set_next_button.pack(side='left')
 

	
 
        topframe.pack(side='top')
 

	
 
        faderframe = Tk.Frame(self, bg='black')
 
        self.direction_info = (('Prev', 1, 0, 'left', 'blue'),
 
                               ('Next', 0, 1, 'right', 'red'))
 
        for name, start, end, side, color in self.direction_info:
 
            frame = Tk.Frame(self, bg='black')
 
            scale = LabelledScale(frame, name, from_=start, to_=end, 
 
                res=0.0001, orient='horiz', flashtroughcolor=color)
 
                res=0.0001, orient='horiz', flashtroughcolor=color,
 
                labelformatter=lambda val, name=name: self.get_scale_desc(val, 
 
                                                                          name))
 
            scale.pack(fill='x', expand=0)
 
            go = TimedGoButton(frame, 'Go %s' % name, scale, bg=color, 
 
                fg='white')
 
            go.pack(fill='both', expand=1)
 
            frame.pack(side=side, fill='both', expand=1)
 
        
 
            shift = Tk.Button(frame, text="Shift %s" % name, state='disabled',
 
                command=lambda name=name: self.shift(name), fg=color, 
 
                bg='black')
 

	
 
            self.scales[name] = scale
 
            self.shift_buttons[name] = shift
 
@@ -162,24 +180,31 @@ class CueFader(Tk.Frame):
 
            scale.scale_var.trace('w', \
 
                lambda x, y, z, name=name, scale=scale: self.xfade(name, scale))
 

	
 
            def button_press(event, name=name, scale=scale):
 
                self.no_shifts_until_release = 1 # prevent shifts until release
 
            def button_release(event, name=name, scale=scale):
 
                self.no_shifts_until_release = 0
 
                self.autoshift(name, scale)
 

	
 
            scale.scale.bind("<ButtonPress>", button_press)
 
            scale.scale.bind("<ButtonRelease>", button_release)
 
        faderframe.pack(side='bottom', fill='both', expand=1)
 
    def get_scale_desc(self, val, name):
 
        go_button = self.go_buttons.get(name)
 
        if go_button:
 
            time = go_button.get_time()
 
            return "%0.2f%%, %0.1fs left" % (val, time - ((val / 100.0) * time))
 
        else:
 
            return "%0.2f%%" % val
 
    def toggle_autoshift(self):
 
        for name, button in self.shift_buttons.items():
 
            if not self.auto_shift.get():
 
                button.pack(side='bottom', fill='both', expand=1)
 
            else:
 
                button.pack_forget()
 
    def shift(self, name):
 
        # to prevent overshifting
 
        if self.no_shifts_until_release:
 
            return
 

	
 
        for scale_name, scale in self.scales.items():
 
@@ -311,59 +336,59 @@ class TkCueList(CueList, Tk.Frame):
 
        self.editor.pack(fill='both', expand=1)
 

	
 
        def edit_cue(index):
 
            index = int(index)
 
            self.editor.set_cue_to_edit(self.cues[index])
 
            
 
        self.columns = ('name', 'time', 'page', 'desc')
 
        self.scrolled_hlist = Tk.ScrolledHList(self,
 
            options='hlist.columns %d hlist.header 1' % len(self.columns))
 
        self.hlist = self.scrolled_hlist.hlist
 
        self.hlist.configure(fg='white', bg='black', 
 
            command=self.select_callback, browsecmd=edit_cue)
 
        self.hlist.bind("<4>", self.wheelscroll)
 
        self.hlist.bind("<5>", self.wheelscroll)
 
        self.scrolled_hlist.pack(fill='both', expand=1)
 

	
 
        boldfont = self.tk.call('tix', 'option', 'get', 
 
            'bold_font')
 
        header_style = Tk.DisplayStyle('text', refwindow=self,
 
            anchor='center', padx=8, pady=2, font=boldfont)
 

	
 
        for count, header in enumerate(self.columns):
 
            self.hlist.header_create(count, itemtype='text',
 
                text=header, style=header_style)
 

	
 
        self.cue_label_windows = {}
 
        for count, cue in enumerate(self.cues):
 
            self.display_cue(count, cue)
 
        self.update_cue_indicators()
 

	
 
    def wheelscroll(self, evt):
 
        """Perform mouse wheel scrolling"""
 
        amount = 2
 
        if evt.num == 4:
 
            amount = -2
 
        self.hlist.yview('scroll', amount, 'units')
 
    def redraw_cue(self, cue):
 
        if 0:
 
            # TODO: this is really inefficient
 
            self.hlist.delete_all()
 
            for count, cue in enumerate(self.cues):
 
                self.display_cue(count, cue)
 
            self.update_cue_indicators()
 
        else:
 
            path = self.cues.index(cue)
 
            for col, header in enumerate(self.columns):
 
                try:
 
                    text = getattr(cue, header)
 
                except AttributeError:
 
                    text = ''
 
        path = self.cues.index(cue)
 
        for col, header in enumerate(self.columns):
 
            try:
 
                text = getattr(cue, header)
 
            except AttributeError:
 
                text = ''
 

	
 
                if col == 0:
 
                    self.cue_label_windows[path]['text'] = text
 
                else:
 
                    self.hlist.item_configure(path, col, text=text)
 
            if col == 0:
 
                self.cue_label_windows[path]['text'] = text
 
            else:
 
                self.hlist.item_configure(path, col, text=text)
 
    def display_cue(self, path, cue):
 
        for col, header in enumerate(self.columns):
 
            try:
 
                text = getattr(cue, header)
 
            except AttributeError:
 
                text = ''
 

	
 
            if col == 0:
 
                lab = Tk.Label(self.hlist, text=text, fg='white', bg='black')
 
                def select_and_highlight(event):
 
                    self.select_callback(path)
 
                    self.hlist.selection_clear()
 
@@ -467,21 +492,22 @@ class CueEditron(Tk.Frame):
 
            text = ''
 
            if self.cue:
 
                try:
 
                    text = getattr(self.cue, field)
 
                except AttributeError:
 
                    pass
 
            self.variables[field].set(text)
 
        self.enable_callbacks = 1
 

	
 
if __name__ == "__main__":
 
    root = Tk.Tk()
 
    root.title("ShowMaster 9000")
 
    root.geometry("500x555")
 
    cl = TkCueList(root, 'cues/cuelist1')
 
    cl.pack(fill='both', expand=1)
 

	
 
    fader = CueFader(root, cl)
 
    fader.pack(fill='both', expand=1)
 
    try:
 
        Tk.mainloop()
 
    except KeyboardInterrupt:
 
        root.destroy()
flax/cues/cuelist1
Show inline comments
 
<?xml version="1.0"?>
 
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
 
<PyObject family="obj" type="builtin_wrapper"  class="_EmptyClass">
 
<attr name="__toplevel__" family="map" type="__compound__" extra="None TreeDict" id="138329300" >
 
<attr name="__toplevel__" family="map" type="__compound__" extra="None TreeDict" id="138331628" >
 
  <entry>
 
    <key type="string" value="cues" />
 
    <val type="list" id="139739116" >
 
      <item type="PyObject" id="139739148" class="Cue">
 
    <val type="list" id="139721548" >
 
      <item type="PyObject" id="140191300" class="Cue">
 
        <attr name="desc" type="string" value="whoa - this works" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="tevya special" />
 
        <attr name="page" type="string" value="3.2" />
 
        <attr name="time" type="string" value="0" />
 
      </item>
 
      <item type="PyObject" id="140193340" class="Cue">
 
      <item type="PyObject" id="140191340" class="Cue">
 
        <attr name="desc" type="string" value="music flourish" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="lady luck" />
 
        <attr name="page" type="string" value="1.1.5" />
 
        <attr name="time" type="string" value="1" />
 
      </item>
 
      <item type="PyObject" id="139732196" class="Cue">
 
      <item type="PyObject" id="139672340" class="Cue">
 
        <attr name="desc" type="string" value="tevya: &quot;what&apos;s happening to the tradition?&quot;" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="dolly solo" />
 
        <attr name="page" type="string" value="1.2.10" />
 
        <attr name="time" type="string" value="2" />
 
      </item>
 
      <item type="PyObject" id="139670412" class="Cue">
 
      <item type="PyObject" id="140195900" class="Cue">
 
        <attr name="desc" type="string" value="the third cue" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 3" />
 
        <attr name="page" type="string" value="1.2.14" />
 
        <attr name="time" type="string" value="41" />
 
      </item>
 
      <item type="PyObject" id="139670188" class="Cue">
 
      <item type="PyObject" id="139671436" class="Cue">
 
        <attr name="time" type="string" value="42" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="heart" />
 
        <attr name="page" type="string" value="1.3.13" />
 
        <attr name="desc" type="string" value="&quot;you&apos;ve gotta have heart&quot;" />
 
      </item>
 
      <item type="PyObject" id="140189388" class="Cue">
 
      <item type="PyObject" id="139673348" class="Cue">
 
        <attr name="time" type="string" value="5" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="more musical refs" />
 
        <attr name="page" type="string" value="1.3.17" />
 
        <attr name="desc" type="string" value="etc." />
 
      </item>
 
      <item type="PyObject" id="139668940" class="Cue">
 
      <item type="PyObject" id="139671036" class="Cue">
 
        <attr name="time" type="string" value="6" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="rainbow shimmer" />
 
        <attr name="page" type="string" value="1.4.2" />
 
        <attr name="desc" type="string" value="curtain close" />
 
      </item>
 
      <item type="PyObject" id="139669364" class="Cue">
 
      <item type="PyObject" id="138625292" class="Cue">
 
        <attr name="time" type="string" value="7" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="fade up" />
 
        <attr name="page" type="string" value="2.1.1" />
 
        <attr name="desc" type="string" value="stage manager: &quot;worklights, please&quot;" />
 
      </item>
 
      <item type="PyObject" id="139669612" class="Cue">
 
      <item type="PyObject" id="140192780" class="Cue">
 
        <attr name="time" type="string" value="8" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="blackout" />
 
        <attr name="page" type="string" value="2.1.2" />
 
        <attr name="desc" type="string" value="&quot;lights out!&quot;" />
 
      </item>
 
      <item type="PyObject" id="140191124" class="Cue">
 
      <item type="PyObject" id="139661388" class="Cue">
 
        <attr name="time" type="string" value="4.2" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="sill" />
 
        <attr name="page" type="string" value="2.2.4" />
 
        <attr name="desc" type="string" value="another description" />
 
      </item>
 
      <item type="PyObject" id="139659252" class="Cue">
 
      <item type="PyObject" id="139661252" class="Cue">
 
        <attr name="desc" type="string" value="mr. cue 10" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="front only" />
 
        <attr name="page" type="string" value="2.7.3" />
 
        <attr name="time" type="string" value="10" />
 
      </item>
 
      <item type="PyObject" id="139668700" class="Cue">
 
      <item type="PyObject" id="140192452" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 11" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="11" />
 
      </item>
 
      <item type="PyObject" id="140191524" class="Cue">
 
      <item type="PyObject" id="139670252" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 12" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="12" />
 
      </item>
 
      <item type="PyObject" id="140192284" class="Cue">
 
      <item type="PyObject" id="139670324" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 13" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="13" />
 
      </item>
 
      <item type="PyObject" id="136493292" class="Cue">
 
      <item type="PyObject" id="139670436" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 14" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="14" />
 
      </item>
 
      <item type="PyObject" id="140192468" class="Cue">
 
      <item type="PyObject" id="139670548" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 15" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="15" />
 
      </item>
 
      <item type="PyObject" id="140183372" class="Cue">
 
      <item type="PyObject" id="139664044" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 16" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="16" />
 
      </item>
 
      <item type="PyObject" id="138407588" class="Cue">
 
      <item type="PyObject" id="140194148" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 17" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="17" />
 
      </item>
 
      <item type="PyObject" id="139668204" class="Cue">
 
      <item type="PyObject" id="140185996" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="some name" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="18" />
 
      </item>
 
      <item type="PyObject" id="140191596" class="Cue">
 
      <item type="PyObject" id="139662308" class="Cue">
 
        <attr name="desc" type="string" value="" />
 
        <attr name="some_attribute" type="numeric" value="3" />
 
        <attr name="name" type="string" value="cue 19" />
 
        <attr name="page" type="string" value="" />
 
        <attr name="time" type="string" value="19" />
 
      </item>
 
    </val>
 
  </entry>
 
</attr>
 
</PyObject>
0 comments (0 inline, 0 general)