Add unregister() method.

Unregister everything at closing.
Don't call close() in __del__, rely on explicit call to close().
This commit is contained in:
Guido van Rossum 1999-06-25 16:03:19 +00:00
parent e689f0087e
commit 374c0dfb10
1 changed files with 12 additions and 4 deletions

View 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: