changeset 97:139d6ed2fbaa

partway through the fancy trace-disabling feature
author drewp
date Sat, 13 Jul 2002 04:04:33 +0000
parents d1a1ded20ec7
children 57319ec2bfad
files light8/uihelpers.py
diffstat 1 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/light8/uihelpers.py	Sat Jul 13 03:33:48 2002 +0000
+++ b/light8/uihelpers.py	Sat Jul 13 04:04:33 2002 +0000
@@ -159,20 +159,34 @@
         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()