Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/WindowList.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 560b2f52952c |
| children |
| rev | line source |
|---|---|
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
42725
diff
changeset
|
1 from tkinter import * |
| 13975 | 2 |
| 3 class WindowList: | |
| 4 | |
| 5 def __init__(self): | |
| 6 self.dict = {} | |
| 7 self.callbacks = [] | |
| 8 | |
| 9 def add(self, window): | |
| 10 window.after_idle(self.call_callbacks) | |
| 11 self.dict[str(window)] = window | |
| 12 | |
| 13 def delete(self, window): | |
| 14 try: | |
| 15 del self.dict[str(window)] | |
| 16 except KeyError: | |
| 17 # Sometimes, destroy() is called twice | |
| 18 pass | |
| 19 self.call_callbacks() | |
| 20 | |
| 21 def add_windows_to_menu(self, menu): | |
| 22 list = [] | |
|
42725
fa9a40ef0780
Conform to py3k dict.{keys, items, values} with some advice from 2b3
Kurt B. Kaiser <kbk@shore.net>
parents:
40775
diff
changeset
|
23 for key in self.dict: |
| 13975 | 24 window = self.dict[key] |
| 25 try: | |
| 26 title = window.get_title() | |
| 27 except TclError: | |
| 28 continue | |
|
49887
560b2f52952c
#4455: IDLE failed to display the windows list when two windows have the same title.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47130
diff
changeset
|
29 list.append((title, key, window)) |
| 13975 | 30 list.sort() |
|
49887
560b2f52952c
#4455: IDLE failed to display the windows list when two windows have the same title.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47130
diff
changeset
|
31 for title, key, window in list: |
| 13975 | 32 menu.add_command(label=title, command=window.wakeup) |
| 33 | |
| 34 def register_callback(self, callback): | |
| 35 self.callbacks.append(callback) | |
| 36 | |
| 37 def unregister_callback(self, callback): | |
| 38 try: | |
|
18495
c4f75857502a
py-cvs merge, correct indentation
Steven M. Gava <elguavas@python.net>
parents:
13975
diff
changeset
|
39 self.callbacks.remove(callback) |
| 13975 | 40 except ValueError: |
| 41 pass | |
| 42 | |
| 43 def call_callbacks(self): | |
| 44 for callback in self.callbacks: | |
| 45 try: | |
| 46 callback() | |
| 47 except: | |
|
37811
6d8e3e65947f
Fix two errors that prevented "make libinstall" from working:
Guido van Rossum <guido@python.org>
parents:
37042
diff
changeset
|
48 t, v, tb = sys.exc_info() |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
37811
diff
changeset
|
49 print("warning: callback failed in WindowList", t, ":", v) |
| 13975 | 50 |
| 51 registry = WindowList() | |
| 52 | |
| 53 add_windows_to_menu = registry.add_windows_to_menu | |
| 54 register_callback = registry.register_callback | |
| 55 unregister_callback = registry.unregister_callback | |
| 56 | |
| 57 | |
| 58 class ListedToplevel(Toplevel): | |
| 59 | |
| 60 def __init__(self, master, **kw): | |
| 61 Toplevel.__init__(self, master, kw) | |
| 62 registry.add(self) | |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
29367
diff
changeset
|
63 self.focused_widget = self |
| 13975 | 64 |
| 65 def destroy(self): | |
| 66 registry.delete(self) | |
| 67 Toplevel.destroy(self) | |
| 25571 | 68 # If this is Idle's last window then quit the mainloop |
| 69 # (Needed for clean exit on Windows 98) | |
| 70 if not registry.dict: | |
| 71 self.quit() | |
| 13975 | 72 |
|
29367
ca20c3cbc956
1. Update WindowList registry when filename changes so that
Kurt B. Kaiser <kbk@shore.net>
parents:
25571
diff
changeset
|
73 def update_windowlist_registry(self, window): |
|
ca20c3cbc956
1. Update WindowList registry when filename changes so that
Kurt B. Kaiser <kbk@shore.net>
parents:
25571
diff
changeset
|
74 registry.call_callbacks() |
|
ca20c3cbc956
1. Update WindowList registry when filename changes so that
Kurt B. Kaiser <kbk@shore.net>
parents:
25571
diff
changeset
|
75 |
| 13975 | 76 def get_title(self): |
| 77 # Subclass can override | |
| 78 return self.wm_title() | |
| 79 | |
| 80 def wakeup(self): | |
| 81 try: | |
| 82 if self.wm_state() == "iconic": | |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
29367
diff
changeset
|
83 self.wm_withdraw() |
| 13975 | 84 self.wm_deiconify() |
|
33218
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
29367
diff
changeset
|
85 self.tkraise() |
|
066c7890cd61
1. If user passes a non-existant filename on the commandline, just open
Kurt B. Kaiser <kbk@shore.net>
parents:
29367
diff
changeset
|
86 self.focused_widget.focus_set() |
| 13975 | 87 except TclError: |
| 88 # This can happen when the window menu was torn off. | |
| 89 # Simply ignore it. | |
| 90 pass |
