Mercurial > cpython-lru_cache-weakref
annotate Lib/stdwin/gwin.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 1d06b1499eb9 |
| children |
| rev | line source |
|---|---|
| 5 | 1 # Module 'gwin' |
| 2 # Generic stdwin windows | |
| 3 | |
| 4 # This is used as a base class from which to derive other window types. | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
5 # XXX DON'T USE THIS CODE ANY MORE! It is ages old! |
|
526
2b0ad52ac396
Use modern stdwinevent constants.
Guido van Rossum <guido@python.org>
parents:
359
diff
changeset
|
6 |
| 359 | 7 import stdwin, stdwinq |
|
101
08e55db6f796
Use stdwinevents instead of stdwinsupport.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
8 from stdwinevents import * |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
9 from mainloop import mainloop, register, unregister, windows |
| 5 | 10 |
| 11 # Open a window | |
| 12 | |
| 13 def open(title): # Open a generic window | |
| 14 w = stdwin.open(title) | |
| 15 stdwin.setdefwinsize(0, 0) | |
| 16 # Set default event handlers | |
| 17 w.draw = nop | |
| 18 w.char = nop | |
| 19 w.mdown = nop | |
| 20 w.mmove = nop | |
| 21 w.mup = nop | |
| 22 w.m2down = m2down | |
| 23 w.m2up = m2up | |
| 24 w.size = nop | |
| 25 w.move = nop | |
| 26 w.activate = w.deactivate = nop | |
| 27 w.timer = nop | |
| 28 # default command handlers | |
| 29 w.close = close | |
| 30 w.tab = tab | |
| 31 w.enter = enter | |
| 32 w.backspace = backspace | |
| 33 w.arrow = arrow | |
| 34 w.kleft = w.kup = w.kright = w.kdown = nop | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
35 w.dispatch = treatevent |
|
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
36 register(w) |
| 5 | 37 return w |
| 38 | |
| 39 | |
| 40 def treatevent(e): # Handle a stdwin event | |
| 41 type, w, detail = e | |
| 559 | 42 if type == WE_DRAW: |
| 5 | 43 w.draw(w, detail) |
| 559 | 44 elif type == WE_MENU: |
| 5 | 45 m, item = detail |
| 46 m.action[item](w, m, item) | |
| 559 | 47 elif type == WE_COMMAND: |
| 5 | 48 treatcommand(w, detail) |
| 559 | 49 elif type == WE_CHAR: |
| 5 | 50 w.char(w, detail) |
| 559 | 51 elif type == WE_MOUSE_DOWN: |
| 5 | 52 if detail[1] > 1: w.m2down(w, detail) |
| 53 else: w.mdown(w, detail) | |
| 559 | 54 elif type == WE_MOUSE_MOVE: |
| 5 | 55 w.mmove(w, detail) |
| 559 | 56 elif type == WE_MOUSE_UP: |
| 5 | 57 if detail[1] > 1: w.m2up(w, detail) |
| 58 else: w.mup(w, detail) | |
| 559 | 59 elif type == WE_SIZE: |
| 5 | 60 w.size(w, w.getwinsize()) |
| 559 | 61 elif type == WE_ACTIVATE: |
| 5 | 62 w.activate(w) |
| 559 | 63 elif type == WE_DEACTIVATE: |
| 5 | 64 w.deactivate(w) |
| 559 | 65 elif type == WE_MOVE: |
| 5 | 66 w.move(w) |
| 559 | 67 elif type == WE_TIMER: |
| 5 | 68 w.timer(w) |
| 559 | 69 elif type == WE_CLOSE: |
|
101
08e55db6f796
Use stdwinevents instead of stdwinsupport.
Guido van Rossum <guido@python.org>
parents:
5
diff
changeset
|
70 w.close(w) |
| 5 | 71 |
| 72 def treatcommand(w, type): # Handle a we_command event | |
| 559 | 73 if type == WC_CLOSE: |
| 5 | 74 w.close(w) |
| 559 | 75 elif type == WC_RETURN: |
| 5 | 76 w.enter(w) |
| 559 | 77 elif type == WC_TAB: |
| 5 | 78 w.tab(w) |
| 559 | 79 elif type == WC_BACKSPACE: |
| 5 | 80 w.backspace(w) |
|
526
2b0ad52ac396
Use modern stdwinevent constants.
Guido van Rossum <guido@python.org>
parents:
359
diff
changeset
|
81 elif type in (WC_LEFT, WC_UP, WC_RIGHT, WC_DOWN): |
| 5 | 82 w.arrow(w, type) |
| 83 | |
| 84 | |
| 85 # Methods | |
| 86 | |
| 87 def close(w): # Close method | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
88 unregister(w) |
|
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
89 del w.close # Delete our close function |
|
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
90 w.close() # Call the close method |
| 5 | 91 |
| 92 def arrow(w, detail): # Arrow key method | |
| 559 | 93 if detail == WC_LEFT: |
| 5 | 94 w.kleft(w) |
| 559 | 95 elif detail == WC_UP: |
| 5 | 96 w.kup(w) |
| 559 | 97 elif detail == WC_RIGHT: |
| 5 | 98 w.kright(w) |
| 559 | 99 elif detail == WC_DOWN: |
| 5 | 100 w.kdown(w) |
| 101 | |
| 102 | |
| 103 # Trivial methods | |
| 104 | |
| 105 def tab(w): w.char(w, '\t') | |
| 106 def enter(w): w.char(w, '\n') # 'return' is a Python reserved word | |
| 107 def backspace(w): w.char(w, '\b') | |
| 108 def m2down(w, detail): w.mdown(w, detail) | |
| 109 def m2up(w, detail): w.mup(w, detail) | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
110 def nop(*args): pass |
