Changeset - 29a8b23d8db5
[Not reviewed]
default
0 1 0
dmcc - 22 years ago 2002-07-13 03:23:35

ready for better scalelevel variable, checkbutton -> label
1 file changed with 23 insertions and 30 deletions:
0 comments (0 inline, 0 general)
light8/ExtSliderMapper.py
Show inline comments
 
@@ -10,49 +10,32 @@ class SliderMapping:
 
        self.sublevel.set(sublevel)
 
        self.synced = BooleanVar() # currently synced
 
        self.synced.set(synced)
 
        self.extlevel = DoubleVar() # external slider's input
 
        self.extlevel.set(extinputlevel)
 
        self.widgets = [] # list of widgets drawn
 
        self.sublabel = None # the label which represents a sub level.  we hold on to
 
                             # it so we can change its textvariable
 
        self.lastbgcolor = None # last background color drawn to avoid unnecessary
 
                                # updates
 
        self.ignoreunsync = 0   # whether to ignore the next request to unsync
 
                                # this is because we trace the slider variable, but
 
                                # we are also semi-responsible for setting it in
 
                                # Lightboard.changelevels.
 
    def ignorenextunync(self):
 
        print "skipping next unsync"
 
        self.ignoreunsync += 1
 
        self.sync()
 
        # self.color_bg()
 
        self.sublabel = None # the label which represents a sub level.  
 
                             # we hold on to it so we can change its 
 
                             # textvariable
 
        self.statuslabel = None # tells us sync status
 
        self.lastbgcolor = None # last background color drawn to avoid 
 
                                # unnecessary redraws
 
    def sync(self, *args):
 
        # print "syncing"
 
        self.synced.set(1)
 
        # self.color_bg()
 
        self.color_bg()
 
    def unsync(self, *args):
 
        if self.ignoreunsync > 0:
 
            print "skipped unsync", self.ignoreunsync
 
            self.synced.set(1)
 
            self.color_bg()
 
            self.ignoreunsync -= 1
 
            return 
 
        '''
 
        print "unsyncing"
 
        '''
 
        self.synced.set(0)
 
        # self.color_bg()
 
        self.color_bg()
 
    def issynced(self):
 
        return self.synced.get()
 
    def disconnect(self, *args):
 
        self.set_subname('disconnected') # a bit hack-like
 
        self.sublabel.configure(text="N/A")
 
        self.color_bg()
 
    def isdisconnected(self):
 
        return self.subname.get() == 'disconnected'
 
        return self.subname.get() == 'disconnected' # a bit more hack-like
 
    def check_synced(self, *args):
 
        'If external level is near than the sublevel, it synces'
 
        if self.isdisconnected(): 
 
            self.unsync()
 
            return
 

	
 
@@ -66,21 +49,26 @@ class SliderMapping:
 
    def set_subname(self, newname):
 
        self.subname.set(newname)
 
        self.unsync()
 
        self.color_bg()
 
    def color_bg(self):
 
        if self.widgets:
 
            self.check_synced()
 
            if self.isdisconnected():
 
                color = 'honeyDew4'
 
            elif self.issynced():
 
            # elif abs(self.extlevel.get() - self.sublevel.get()) <= 0.02:
 
                color = 'honeyDew2'
 
            else: # unsynced
 
                color = 'red'
 

	
 
            if self.statuslabel:
 
                if color == 'honeyDew2': # connected
 
                    self.statuslabel['text'] = 'Sync'
 
                else:
 
                    self.statuslabel['text'] = 'No sync'
 

	
 
            # print "color", color, "lastbgcolor", self.lastbgcolor
 
            if self.lastbgcolor == color: return
 
            for widget in self.widgets:
 
                widget.configure(bg=color)
 
            self.lastbgcolor = color
 
    def set_sublevel_var(self, newvar):
 
@@ -102,29 +90,34 @@ class SliderMapping:
 
        c = ComboBox(frame, variable=self.subname)
 
        c.slistbox.listbox.insert(END, "disconnected")
 
        for s in subnames:
 
            c.slistbox.listbox.insert(END, s)
 
        c.entry.configure(width=12)
 
        statframe = Frame(frame)
 

	
 
        '''
 
        cb = Checkbutton(statframe, variable=self.synced, 
 
            text="Synced")
 
        cb.grid(columnspan=2, sticky=W)
 
        '''
 
        self.statuslabel = Label(statframe, text="No sync")
 
        self.statuslabel.grid(columnspan=2, sticky=W)
 
        ilabel = Label(statframe, text="Input", fg='blue')
 
        ilabel.grid(row=1, sticky=W)
 
        extlabel = Label(statframe, textvariable=self.extlevel, width=5)
 
        extlabel.grid(row=1, column=1)
 
        rlabel = Label(statframe, text="Real")
 
        rlabel.grid(row=2, sticky=W)
 
        self.sublabel = Label(statframe, text="N/A", width=5)
 
        self.sublabel.grid(row=2, column=1)
 
        statframe.pack(side=BOTTOM, expand=1, fill=X)
 
        c.pack()
 
        frame.pack(side=LEFT, expand=1, fill=BOTH)
 

	
 
        self.widgets = [frame, c, statframe, cb, ilabel, extlabel, rlabel, 
 
                        self.sublabel]
 
        self.widgets = [frame, c, statframe, self.statuslabel, ilabel, extlabel,
 
                        rlabel, self.sublabel]
 

	
 
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)
 
@@ -180,24 +173,24 @@ class ExtSliderMapper(Frame):
 
        self.load_scalelevels() # freshen our input from the physical sliders
 

	
 
        rawlevels = self.sliderinput.get_levels()
 
        for rawlev, slidermap in zip(rawlevels, self.current_mappings):
 
            slidermap.changed_extinput(rawlev)
 

	
 
        '''
 
        outputlevels = {}
 
        for m in self.current_mappings:
 
            if m.issynced():
 
                k, v = m.get_level_pair()
 
                outputlevels[k] = v
 
                m.ignorenextunync()
 
        return outputlevels
 
        '''
 
        return dict([m.get_level_pair()
 
            for m in self.current_mappings
 
            if m.issynced()])
 
        '''
 
    def draw_interface(self):
 
        self.reallevellabels = []
 
        subchoiceframe = Frame(self)
 
        for m in self.current_mappings:
 
            m.draw_interface(subchoiceframe, self.subnames)
 
        subchoiceframe.pack()
0 comments (0 inline, 0 general)