summaryrefslogtreecommitdiffstats
path: root/Tools/idle/WindowList.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-17 17:19:37 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-17 17:19:37 (GMT)
commit5437ddfa36f785cd8d2a68dc35297173d88ca67c (patch)
tree616987c7c7f338cdf54646cb7d9e97f90bcdb005 /Tools/idle/WindowList.py
parenta79a93ff7334cb162bff1c0423b124f3dc601ebf (diff)
downloadcpython-5437ddfa36f785cd8d2a68dc35297173d88ca67c.zip
cpython-5437ddfa36f785cd8d2a68dc35297173d88ca67c.tar.gz
cpython-5437ddfa36f785cd8d2a68dc35297173d88ca67c.tar.bz2
Support callbacks to patch up Windows menus everywhere.
Diffstat (limited to 'Tools/idle/WindowList.py')
-rw-r--r--Tools/idle/WindowList.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/Tools/idle/WindowList.py b/Tools/idle/WindowList.py
index 3a85c19..b820089 100644
--- a/Tools/idle/WindowList.py
+++ b/Tools/idle/WindowList.py
@@ -4,11 +4,14 @@ class WindowList:
def __init__(self):
self.dict = {}
+ self.callbacks = []
def add(self, window):
+ window.after_idle(self.call_callbacks)
self.dict[str(window)] = window
def delete(self, window):
+ window.after_idle(self.call_callbacks)
try:
del self.dict[str(window)]
except KeyError:
@@ -31,10 +34,30 @@ class WindowList:
continue
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()
-def add_windows_to_menu(menu):
- registry.add_windows_to_menu(menu)
+add_windows_to_menu = registry.add_windows_to_menu
+register_callback = registry.register_callback
+unregister_callback = registry.unregister_callback
+call_callbacks = registry.call_callbacks
+
class ListedToplevel(Toplevel):