ยปCore Development>Code coverage>Lib/idlelib/windows.py

Python code coverage for Lib/idlelib/windows.py

#countcontent
1n/afrom tkinter import *
2n/a
3n/a
4n/aclass WindowList:
5n/a
6n/a def __init__(self):
7n/a self.dict = {}
8n/a self.callbacks = []
9n/a
10n/a def add(self, window):
11n/a window.after_idle(self.call_callbacks)
12n/a self.dict[str(window)] = window
13n/a
14n/a def delete(self, window):
15n/a try:
16n/a del self.dict[str(window)]
17n/a except KeyError:
18n/a # Sometimes, destroy() is called twice
19n/a pass
20n/a self.call_callbacks()
21n/a
22n/a def add_windows_to_menu(self, menu):
23n/a list = []
24n/a for key in self.dict:
25n/a window = self.dict[key]
26n/a try:
27n/a title = window.get_title()
28n/a except TclError:
29n/a continue
30n/a list.append((title, key, window))
31n/a list.sort()
32n/a for title, key, window in list:
33n/a menu.add_command(label=title, command=window.wakeup)
34n/a
35n/a def register_callback(self, callback):
36n/a self.callbacks.append(callback)
37n/a
38n/a def unregister_callback(self, callback):
39n/a try:
40n/a self.callbacks.remove(callback)
41n/a except ValueError:
42n/a pass
43n/a
44n/a def call_callbacks(self):
45n/a for callback in self.callbacks:
46n/a try:
47n/a callback()
48n/a except:
49n/a t, v, tb = sys.exc_info()
50n/a print("warning: callback failed in WindowList", t, ":", v)
51n/a
52n/a
53n/aregistry = WindowList()
54n/a
55n/aadd_windows_to_menu = registry.add_windows_to_menu
56n/aregister_callback = registry.register_callback
57n/aunregister_callback = registry.unregister_callback
58n/a
59n/a
60n/aclass ListedToplevel(Toplevel):
61n/a
62n/a def __init__(self, master, **kw):
63n/a Toplevel.__init__(self, master, kw)
64n/a registry.add(self)
65n/a self.focused_widget = self
66n/a
67n/a def destroy(self):
68n/a registry.delete(self)
69n/a Toplevel.destroy(self)
70n/a # If this is Idle's last window then quit the mainloop
71n/a # (Needed for clean exit on Windows 98)
72n/a if not registry.dict:
73n/a self.quit()
74n/a
75n/a def update_windowlist_registry(self, window):
76n/a registry.call_callbacks()
77n/a
78n/a def get_title(self):
79n/a # Subclass can override
80n/a return self.wm_title()
81n/a
82n/a def wakeup(self):
83n/a try:
84n/a if self.wm_state() == "iconic":
85n/a self.wm_withdraw()
86n/a self.wm_deiconify()
87n/a self.tkraise()
88n/a self.focused_widget.focus_set()
89n/a except TclError:
90n/a # This can happen when the window menu was torn off.
91n/a # Simply ignore it.
92n/a pass