mirror of https://github.com/python/cpython
Add unregister() method.
Unregister everything at closing. Don't call close() in __del__, rely on explicit call to close().
This commit is contained in:
parent
e689f0087e
commit
374c0dfb10
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue