Mercurial > cpython-lru_cache-weakref
annotate Lib/lib-stdwin/WindowParent.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | f9bbb01388d5 |
| children |
| rev | line source |
|---|---|
| 64 | 1 # A 'WindowParent' is the only module that uses real stdwin functionality. |
| 2 # It is the root of the tree. | |
| 3 # It should have exactly one child when realized. | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
4 # |
| 354 | 5 # There is also an alternative interface to "mainloop" here. |
| 64 | 6 |
| 7 import stdwin | |
| 8 from stdwinevents import * | |
| 354 | 9 import mainloop |
| 64 | 10 |
| 11 from TransParent import ManageOneChild | |
| 12 | |
| 13 Error = 'WindowParent.Error' # Exception | |
| 14 | |
| 531 | 15 class WindowParent(ManageOneChild): |
| 64 | 16 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
17 def create(self, title, size): |
| 64 | 18 self.title = title |
| 19 self.size = size # (width, height) | |
|
126
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
20 self._reset() |
| 354 | 21 self.close_hook = WindowParent.delayed_destroy |
|
126
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
22 return self |
|
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
23 # |
|
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
24 def _reset(self): |
|
246
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
25 self.child = None |
|
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
26 self.win = None |
| 64 | 27 self.itimer = 0 |
| 28 self.do_mouse = 0 | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
29 self.do_keybd = 0 |
| 64 | 30 self.do_timer = 0 |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
31 self.do_altdraw = 0 |
|
213
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
32 self.pending_destroy = 0 |
|
246
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
33 self.close_hook = None |
| 354 | 34 self.menu_hook = None |
|
126
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
35 # |
|
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
36 def destroy(self): |
| 354 | 37 mainloop.unregister(self.win) |
|
126
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
38 if self.child: self.child.destroy() |
|
27cc0d823766
Added _reset and destroy methods.
Guido van Rossum <guido@python.org>
parents:
100
diff
changeset
|
39 self._reset() |
| 64 | 40 # |
|
213
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
41 def delayed_destroy(self): |
|
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
42 # This interface to be used by 'Close' buttons etc.; |
|
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
43 # destroying a window from within a button hook |
|
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
44 # is not a good idea... |
|
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
45 self.pending_destroy = 1 |
|
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
46 # |
|
246
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
47 def close_trigger(self): |
|
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
48 if self.close_hook: self.close_hook(self) |
|
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
49 # |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
50 def menu_trigger(self, menu, item): |
| 354 | 51 if self.menu_hook: |
| 52 self.menu_hook(self, menu, item) | |
| 53 # | |
| 64 | 54 def need_mouse(self, child): self.do_mouse = 1 |
| 55 def no_mouse(self, child): self.do_mouse = 0 | |
| 56 # | |
| 354 | 57 def need_keybd(self, child): |
| 58 self.do_keybd = 1 | |
| 59 self.child.activate() | |
| 60 def no_keybd(self, child): | |
| 61 self.do_keybd = 0 | |
| 62 self.child.deactivate() | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
63 # |
| 64 | 64 def need_timer(self, child): self.do_timer = 1 |
| 65 def no_timer(self, child): self.do_timer = 0 | |
| 66 # | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
67 def need_altdraw(self, child): self.do_altdraw = 1 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
68 def no_altdraw(self, child): self.do_altdraw = 0 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
69 # |
| 64 | 70 def realize(self): |
| 71 if self.win: | |
| 72 raise Error, 'realize(): called twice' | |
| 73 if not self.child: | |
| 74 raise Error, 'realize(): no child' | |
| 354 | 75 # Compute suggested size |
| 76 self.size = self.child.getminsize(self.beginmeasuring(), \ | |
| 77 self.size) | |
| 78 save_defsize = stdwin.getdefwinsize() | |
| 79 scrwidth, scrheight = stdwin.getscrsize() | |
| 80 width, height = self.size | |
| 81 if width > scrwidth: | |
| 82 width = scrwidth * 2/3 | |
| 83 if height > scrheight: | |
| 84 height = scrheight * 2/3 | |
| 85 stdwin.setdefwinsize(width, height) | |
| 86 self.hbar, self.vbar = stdwin.getdefscrollbars() | |
| 64 | 87 self.win = stdwin.open(self.title) |
| 354 | 88 stdwin.setdefwinsize(save_defsize) |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
89 self.win.setdocsize(self.size) |
| 64 | 90 if self.itimer: |
| 91 self.win.settimer(self.itimer) | |
| 354 | 92 width, height = self.win.getwinsize() |
| 93 if self.hbar: | |
| 94 width = self.size[0] | |
| 95 if self.vbar: | |
| 96 height = self.size[1] | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
97 self.child.setbounds(((0, 0), (width, height))) |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
98 self.child.realize() |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
99 self.win.dispatch = self.dispatch |
| 354 | 100 mainloop.register(self.win) |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
101 # |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
102 def fixup(self): |
| 354 | 103 # XXX This could share code with realize() above |
| 104 self.size = self.child.getminsize(self.beginmeasuring(), \ | |
| 105 self.win.getwinsize()) | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
106 self.win.setdocsize(self.size) |
| 354 | 107 width, height = self.win.getwinsize() |
| 108 if self.hbar: | |
| 109 width = self.size[0] | |
| 110 if self.vbar: | |
| 111 height = self.size[1] | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
112 self.child.setbounds(((0, 0), (width, height))) |
|
246
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
113 # Force a redraw of the entire window: |
| 354 | 114 self.win.change((0, 0), self.size) |
| 64 | 115 # |
| 116 def beginmeasuring(self): | |
| 117 # Return something with which a child can measure text | |
| 118 if self.win: | |
| 119 return self.win.begindrawing() | |
| 120 else: | |
| 121 return stdwin | |
| 122 # | |
| 123 def begindrawing(self): | |
| 124 if self.win: | |
| 125 return self.win.begindrawing() | |
| 126 else: | |
| 127 raise Error, 'begindrawing(): not realized yet' | |
| 128 # | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
129 def getwindow(self): |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
130 if self.win: |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
131 return self.win |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
132 else: |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
133 raise Error, 'getwindow(): not realized yet' |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
134 # |
| 64 | 135 def change(self, area): |
| 136 if self.win: | |
| 137 self.win.change(area) | |
| 138 # | |
|
1178
f9bbb01388d5
* More changes due to stricter argument passing rules
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
139 def scroll(self, area, vector): |
| 64 | 140 if self.win: |
|
1178
f9bbb01388d5
* More changes due to stricter argument passing rules
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
141 self.win.scroll(area, vector) |
| 64 | 142 # |
| 143 def settimer(self, itimer): | |
| 144 if self.win: | |
| 145 self.win.settimer(itimer) | |
| 146 else: | |
| 147 self.itimer = itimer | |
| 148 # | |
|
213
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
149 # Only call dispatch once we are realized |
| 64 | 150 # |
| 151 def dispatch(self, (type, win, detail)): | |
| 559 | 152 if type == WE_DRAW: |
| 64 | 153 d = self.win.begindrawing() |
| 154 self.child.draw(d, detail) | |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
155 del d |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
156 if self.do_altdraw: self.child.altdraw(detail) |
| 559 | 157 elif type == WE_MOUSE_DOWN: |
| 64 | 158 if self.do_mouse: self.child.mouse_down(detail) |
| 559 | 159 elif type == WE_MOUSE_MOVE: |
| 64 | 160 if self.do_mouse: self.child.mouse_move(detail) |
| 559 | 161 elif type == WE_MOUSE_UP: |
| 64 | 162 if self.do_mouse: self.child.mouse_up(detail) |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
163 elif type in (WE_CHAR, WE_COMMAND): |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
164 if self.do_keybd: self.child.keybd(type, detail) |
| 559 | 165 elif type == WE_TIMER: |
| 64 | 166 if self.do_timer: self.child.timer() |
| 559 | 167 elif type == WE_SIZE: |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
168 self.fixup() |
| 559 | 169 elif type == WE_CLOSE: |
|
246
956fd5c3f040
*** empty log message ***
Guido van Rossum <guido@python.org>
parents:
213
diff
changeset
|
170 self.close_trigger() |
| 559 | 171 elif type == WE_MENU: |
| 354 | 172 self.menu_trigger(detail) |
|
213
66b55766ba65
Support delayed destroy. Use built-in remove.
Guido van Rossum <guido@python.org>
parents:
192
diff
changeset
|
173 if self.pending_destroy: |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
174 self.destroy() |
| 64 | 175 # |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
176 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
177 def MainLoop(): |
| 354 | 178 mainloop.mainloop() |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
179 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
180 def Dispatch(event): |
| 354 | 181 mainloop.dispatch(event) |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
182 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
183 # Interface used by WindowSched: |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
184 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
185 def CountWindows(): |
| 354 | 186 return mainloop.countwindows() |
|
192
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
187 |
|
32ae4a1aab68
Added window list management functionality.
Guido van Rossum <guido@python.org>
parents:
126
diff
changeset
|
188 def AnyWindow(): |
| 354 | 189 return mainloop.anywindow() |
