Changeset - 139d6ed2fbaa
[Not reviewed]
default
0 1 0
drewp - 22 years ago 2002-07-13 04:04:33

partway through the fancy trace-disabling feature
1 file changed with 24 insertions and 10 deletions:
0 comments (0 inline, 0 general)
light8/uihelpers.py
Show inline comments
 
@@ -156,26 +156,40 @@ class Togglebutton(Button):
 

	
 
class FancyDoubleVar(DoubleVar):
 
    def __init__(self,master=None):
 
        DoubleVar.__init__(self,master)
 
        self.callbacklist = {}
 
    def trace_variable(self,mode,callback):
 
        """Define a trace callback for the variable.
 

	
 
        # we build a list of the trace callbacks (the py functrions and the tcl functionnames)
 
        id=DoubleVar.trace_variable(self,mode,callback)
 

	
 
        self.callbacklist[id]= [mode,callback]
 
        MODE is one of "r", "w", "u" for read, write, undefine.
 
        CALLBACK must be a function which is called when
 
        the variable is read, written or undefined.
 

	
 
        return id
 

	
 
        Return the name of the callback.
 
        """
 
        cbname = self._master._register(callback)
 
        self._tk.call("trace", "variable", self._name, mode, cbname)
 
        
 
        # we build a list of the trace callbacks (the py functrions and the tcl functionnames)
 
        self.callbacklist[cbname]= mode
 
        print "added trace:",callback,cbname
 
        
 
        return cbname
 
    trace=trace_variable
 
    def disable_traces(self):
 
        for k,v in self.callbacklist.items():
 
            self.trace_vdelete(v[0],k)
 
        for cb,mode in self.callbacklist.items():
 
#            DoubleVar.trace_vdelete(self,v[0],k)
 
            self._tk.call("trace", "vdelete", self._name, mode,cb)
 
            # but no master delete!
 
            
 
    def recreate_traces(self):
 
        for k,v in self.callbacklist.items():
 
            self.trace_variable(v[0],v[1])
 
        for cb,mode in self.callbacklist.items():
 
#            self.trace_variable(v[0],v[1])
 
            self._tk.call("trace", "variable", self._name, mode,cb)
 

	
 

	
 
if __name__=='__main__':
 
    root=Tk()
 
    root.tk_focusFollowsMouse()
 
    iv=IntVar()
 
    def cb():
0 comments (0 inline, 0 general)