]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add unregister() method.
authorGuido van Rossum <guido@python.org>
Fri, 25 Jun 1999 16:03:19 +0000 (16:03 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 25 Jun 1999 16:03:19 +0000 (16:03 +0000)
Unregister everything at closing.
Don't call close() in __del__, rely on explicit call to close().

Tools/idle/WidgetRedirector.py

index b11b0e40472f7ea4f523c072b33870f1b038dc76..b49ccf1c590a506e1efca25e4c1e82249b3ee4e4 100644 (file)
@@ -18,11 +18,9 @@ class WidgetRedirector:
         return "WidgetRedirector(%s<%s>)" % (self.widget.__class__.__name__,
                                              self.widget._w)
 
-    def __del__(self):
-        self.close()
-
     def close(self):
-        self.dict = {}
+        for name in self.dict.keys():
+            self.unregister(name)
         widget = self.widget; del self.widget
         orig = self.orig; del self.orig
         tk = widget.tk
@@ -39,6 +37,16 @@ class WidgetRedirector:
         setattr(self.widget, name, function)
         return previous
 
+    def unregister(self, name):
+        if self.dict.has_key(name):
+            function = self.dict[name]
+            del self.dict[name]
+            if hasattr(self.widget, name):
+                delattr(self.widget, name)
+            return function
+        else:
+            return None
+
     def dispatch(self, cmd, *args):
         m = self.dict.get(cmd)
         try: