From 374c0dfb10ec9bebffbcc9ec30b37043fd13d6dc Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 25 Jun 1999 16:03:19 +0000 Subject: [PATCH] Add unregister() method. Unregister everything at closing. Don't call close() in __del__, rely on explicit call to close(). --- Tools/idle/WidgetRedirector.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Tools/idle/WidgetRedirector.py b/Tools/idle/WidgetRedirector.py index b11b0e40472..b49ccf1c590 100644 --- a/Tools/idle/WidgetRedirector.py +++ b/Tools/idle/WidgetRedirector.py @@ -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: