mirror of https://github.com/python/cpython.git
Support callbacks to patch up Windows menus everywhere.
This commit is contained in:
parent
a79a93ff73
commit
5437ddfa36
|
@ -4,11 +4,14 @@ class WindowList:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.dict = {}
|
self.dict = {}
|
||||||
|
self.callbacks = []
|
||||||
|
|
||||||
def add(self, window):
|
def add(self, window):
|
||||||
|
window.after_idle(self.call_callbacks)
|
||||||
self.dict[str(window)] = window
|
self.dict[str(window)] = window
|
||||||
|
|
||||||
def delete(self, window):
|
def delete(self, window):
|
||||||
|
window.after_idle(self.call_callbacks)
|
||||||
try:
|
try:
|
||||||
del self.dict[str(window)]
|
del self.dict[str(window)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -31,10 +34,30 @@ def add_windows_to_menu(self, menu):
|
||||||
continue
|
continue
|
||||||
menu.add_command(label=title, command=window.wakeup)
|
menu.add_command(label=title, command=window.wakeup)
|
||||||
|
|
||||||
|
def register_callback(self, callback):
|
||||||
|
self.callbacks.append(callback)
|
||||||
|
|
||||||
|
def unregister_callback(self, callback):
|
||||||
|
try:
|
||||||
|
self.callback.remove(callback)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def call_callbacks(self):
|
||||||
|
for callback in self.callbacks:
|
||||||
|
try:
|
||||||
|
callback()
|
||||||
|
except:
|
||||||
|
print "warning: callback failed in WindowList", \
|
||||||
|
sys.exc_type, ":", sys.exc_value
|
||||||
|
|
||||||
registry = WindowList()
|
registry = WindowList()
|
||||||
|
|
||||||
def add_windows_to_menu(menu):
|
add_windows_to_menu = registry.add_windows_to_menu
|
||||||
registry.add_windows_to_menu(menu)
|
register_callback = registry.register_callback
|
||||||
|
unregister_callback = registry.unregister_callback
|
||||||
|
call_callbacks = registry.call_callbacks
|
||||||
|
|
||||||
|
|
||||||
class ListedToplevel(Toplevel):
|
class ListedToplevel(Toplevel):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue