Mercurial > cpython-lru_cache-weakref
annotate Mac/Lib/FrameWork.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 | 5a7429ac90c8 |
| children | 83e7759e7297 |
| rev | line source |
|---|---|
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 "A sort of application framework for the Mac" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
3 DEBUG=0 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 import MacOS |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 import traceback |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 from AE import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 from AppleEvents import * |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
10 from Ctl import * |
|
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
11 from Controls import * |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 from Dlg import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 from Dialogs import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 from Evt import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 from Events import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 from Menu import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 from Menus import * |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
18 from Qd import * |
|
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
19 from QuickDraw import * |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 #from Res import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 #from Resources import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 #from Snd import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 #from Sound import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 from Win import * |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 from Windows import * |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
26 import types |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 import EasyDialogs |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 kHighLevelEvent = 23 # Don't know what header file this should come from |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
31 SCROLLBARWIDTH = 16 # Again, not a clue... |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 # Map event 'what' field to strings |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 eventname = {} |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 eventname[1] = 'mouseDown' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 eventname[2] = 'mouseUp' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 eventname[3] = 'keyDown' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 eventname[4] = 'keyUp' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 eventname[5] = 'autoKey' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 eventname[6] = 'updateEvt' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 eventname[7] = 'diskEvt' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 eventname[8] = 'activateEvt' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 eventname[15] = 'osEvt' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 eventname[23] = 'kHighLevelEvent' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 # Map part codes returned by WhichWindow() to strings |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 partname = {} |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 partname[0] = 'inDesk' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 partname[1] = 'inMenuBar' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 partname[2] = 'inSysWindow' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 partname[3] = 'inContent' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 partname[4] = 'inDrag' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 partname[5] = 'inGrow' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 partname[6] = 'inGoAway' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 partname[7] = 'inZoomIn' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 partname[8] = 'inZoomOut' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
59 # |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
60 # The useable portion of the screen |
| 3814 | 61 # ## but what happens with multiple screens? jvr |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
62 screenbounds = qd.screenBits.bounds |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
63 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \ |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
64 screenbounds[2]-4, screenbounds[3]-4 |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
65 |
| 3814 | 66 next_window_x = 16 # jvr |
| 67 next_window_y = 44 # jvr | |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
68 |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
69 def windowbounds(width, height): |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
70 "Return sensible window bounds" |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
71 global next_window_x, next_window_y |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
72 r, b = next_window_x+width, next_window_y+height |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
73 if r > screenbounds[2]: |
| 3814 | 74 next_window_x = 16 |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
75 if b > screenbounds[3]: |
| 3814 | 76 next_window_y = 44 |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
77 l, t = next_window_x, next_window_y |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
78 r, b = next_window_x+width, next_window_y+height |
| 3814 | 79 next_window_x, next_window_y = next_window_x + 8, next_window_y + 20 # jvr |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
80 return l, t, r, b |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
4162
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
82 _watch = None |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
83 def setwatchcursor(): |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
84 global _watch |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
85 |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
86 if _watch == None: |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
87 _watch = GetCursor(4).data |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
88 SetCursor(_watch) |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
89 |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
90 def setarrowcursor(): |
|
99250182c48a
Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents:
3814
diff
changeset
|
91 SetCursor(qd.arrow) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 class Application: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 "Application framework -- your application should be a derived class" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
97 def __init__(self, nomenubar=0): |
|
5750
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
98 self._doing_asyncevents = 0 |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
99 self.quitting = 0 |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
100 self.needmenubarredraw = 0 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
101 self._windows = {} |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
102 if nomenubar: |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
103 self.menubar = None |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
104 else: |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
105 self.makemenubar() |
|
5750
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
106 |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
107 def __del__(self): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
108 if self._doing_asyncevents: |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
109 self._doing_asyncevents = 0 |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
110 MacOS.SetEventHandler() |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 def makemenubar(self): |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
113 self.menubar = MenuBar(self) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 AppleMenu(self.menubar, self.getabouttext(), self.do_about) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 self.makeusermenus() |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
116 |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
117 def makeusermenus(self): |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
118 self.filemenu = m = Menu(self.menubar, "File") |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
119 self._quititem = MenuItem(m, "Quit", "Q", self._quit) |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
120 |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
121 def _quit(self, *args): |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
122 self.quitting = 1 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
123 |
|
4819
9bda38c67f4e
Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents:
4335
diff
changeset
|
124 def cleanup(self): |
|
9bda38c67f4e
Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents:
4335
diff
changeset
|
125 for w in self._windows.values(): |
|
9bda38c67f4e
Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents:
4335
diff
changeset
|
126 w.do_close() |
|
9bda38c67f4e
Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents:
4335
diff
changeset
|
127 return self._windows == {} |
|
9bda38c67f4e
Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents:
4335
diff
changeset
|
128 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
129 def appendwindow(self, wid, window): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
130 self._windows[wid] = window |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
131 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
132 def removewindow(self, wid): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
133 del self._windows[wid] |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 def getabouttext(self): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 return "About %s..." % self.__class__.__name__ |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 def do_about(self, id, item, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 EasyDialogs.Message("Hello, world!" + "\015(%s)" % self.__class__.__name__) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 # The main event loop is broken up in several simple steps. |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 # This is done so you can override each individual part, |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 # if you have a need to do extra processing independent of the |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 # event type. |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 # Normally, however, you'd just define handlers for individual |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 # events. |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 # (XXX I'm not sure if using default parameter values is the right |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 # way to define the mask and wait time passed to WaitNextEvent.) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 def mainloop(self, mask = everyEvent, wait = 0): |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
151 self.quitting = 0 |
|
5735
634728d8bc98
Replaced MacOS.EnableAppSwitch with MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents:
4819
diff
changeset
|
152 saveparams = apply(MacOS.SchedParams, self.schedparams) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 try: |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
154 while not self.quitting: |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 try: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 self.do1event(mask, wait) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 except (Application, SystemExit): |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
158 # Note: the raising of "self" is old-fashioned idiom to |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
159 # exit the mainloop. Calling _quit() is better for new |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
160 # applications. |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 break |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 finally: |
|
5735
634728d8bc98
Replaced MacOS.EnableAppSwitch with MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents:
4819
diff
changeset
|
163 apply(MacOS.SchedParams, self.schedparams) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
5735
634728d8bc98
Replaced MacOS.EnableAppSwitch with MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents:
4819
diff
changeset
|
165 schedparams = MacOS.SchedParams() |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 |
|
5750
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
167 def dopendingevents(self, mask = everyEvent): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
168 """dopendingevents - Handle all pending events""" |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
169 while self.do1event(mask, wait=0): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
170 pass |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
171 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 def do1event(self, mask = everyEvent, wait = 0): |
|
3037
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
173 ok, event = self.getevent(mask, wait) |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
174 if IsDialogEvent(event): |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
175 if self.do_dialogevent(event): |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
176 return |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
177 if ok: |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 self.dispatch(event) |
|
3245
18b60d8d9e35
Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3037
diff
changeset
|
179 else: |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
180 self.idle(event) |
|
3245
18b60d8d9e35
Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3037
diff
changeset
|
181 |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
182 def idle(self, event): |
|
3245
18b60d8d9e35
Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3037
diff
changeset
|
183 pass |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 def getevent(self, mask = everyEvent, wait = 0): |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
186 if self.needmenubarredraw: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
187 DrawMenuBar() |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
188 self.needmenubarredraw = 0 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 ok, event = WaitNextEvent(mask, wait) |
|
3037
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
190 return ok, event |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
191 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 def dispatch(self, event): |
|
5750
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
193 # The following appears to be double work (already done in do1event) |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
194 # but we need it for asynchronous event handling |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
195 if IsDialogEvent(event): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
196 if self.do_dialogevent(event): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
197 return |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 (what, message, when, where, modifiers) = event |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 if eventname.has_key(what): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 name = "do_" + eventname[what] |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 else: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 name = "do_%d" % what |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 try: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 handler = getattr(self, name) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 except AttributeError: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 handler = self.do_unknownevent |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 handler(event) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
208 |
|
5750
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
209 def asyncevents(self, onoff): |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
210 """asyncevents - Set asynchronous event handling on or off""" |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
211 old = self._doing_asyncevents |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
212 if old: |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
213 MacOS.SetEventHandler() |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
214 apply(MacOS.SchedParams, self.schedparams) |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
215 if onoff: |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
216 MacOS.SetEventHandler(self.dispatch) |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
217 doint, dummymask, benice, howoften, bgyield = \ |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
218 self.schedparams |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
219 MacOS.SchedParams(doint, everyEvent, benice, |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
220 howoften, bgyield) |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
221 self._doing_asyncevents = onoff |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
222 return old |
|
5a7429ac90c8
Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents:
5735
diff
changeset
|
223 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
224 def do_dialogevent(self, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
225 gotone, window, item = DialogSelect(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
226 if gotone: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
227 if self._windows.has_key(window): |
|
3037
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
228 self._windows[window].do_itemhit(item, event) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
229 else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
230 print 'Dialog event for unknown dialog' |
|
3037
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
231 return 1 |
|
f8abc037b94f
Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
2998
diff
changeset
|
232 return 0 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 def do_mouseDown(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 (what, message, when, where, modifiers) = event |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
236 partcode, wid = FindWindow(where) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
237 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
238 # |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
239 # Find the correct name. |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
240 # |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 if partname.has_key(partcode): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 name = "do_" + partname[partcode] |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 else: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 name = "do_%d" % partcode |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
245 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
246 if wid == None: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
247 # No window, or a non-python window |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
248 try: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
249 handler = getattr(self, name) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
250 except AttributeError: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
251 # Not menubar or something, so assume someone |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
252 # else's window |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
253 MacOS.HandleEvent(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
254 return |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
255 elif self._windows.has_key(wid): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
256 # It is a window. Hand off to correct window. |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
257 window = self._windows[wid] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
258 try: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
259 handler = getattr(window, name) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
260 except AttributeError: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
261 handler = self.do_unknownpartcode |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
262 else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
263 # It is a python-toolbox window, but not ours. |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
264 handler = self.do_unknownwindow |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
265 handler(partcode, wid, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
266 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 def do_inSysWindow(self, partcode, window, event): |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
268 MacOS.HandleEvent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 def do_inDesk(self, partcode, window, event): |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
271 MacOS.HandleEvent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 def do_inMenuBar(self, partcode, window, event): |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
274 if not self.menubar: |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
275 MacOS.HandleEvent(event) |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
276 return |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 (what, message, when, where, modifiers) = event |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 result = MenuSelect(where) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 id = (result>>16) & 0xffff # Hi word |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 item = result & 0xffff # Lo word |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 self.do_rawmenu(id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 def do_rawmenu(self, id, item, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 try: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 self.do_menu(id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 finally: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 HiliteMenu(0) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 def do_menu(self, id, item, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 self.menubar.dispatch(id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 def do_unknownpartcode(self, partcode, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 (what, message, when, where, modifiers) = event |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
295 if DEBUG: print "Mouse down at global:", where |
|
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
296 if DEBUG: print "\tUnknown part code:", partcode |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
297 if DEBUG: print "\tEvent:", self.printevent(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
298 MacOS.HandleEvent(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
299 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
300 def do_unknownwindow(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
301 if DEBUG: print 'Unknown window:', window |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
302 MacOS.HandleEvent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 def do_keyDown(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 self.do_key(event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 def do_autoKey(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 if not event[-1] & cmdKey: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 self.do_key(event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 def do_key(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 (what, message, when, where, modifiers) = event |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 c = chr(message & charCodeMask) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 if modifiers & cmdKey: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 if c == '.': |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 raise self |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 else: |
|
4312
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
318 if not self.menubar: |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
319 MacOS.HandleEvent(event) |
|
937f69fd43fe
- Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents:
4162
diff
changeset
|
320 return |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 result = MenuKey(ord(c)) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 id = (result>>16) & 0xffff # Hi word |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 item = result & 0xffff # Lo word |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 if id: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 self.do_rawmenu(id, item, None, event) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
326 # elif c == 'w': |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
327 # w = FrontWindow() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
328 # if w: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
329 # self.do_close(w) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
330 # else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
331 # if DEBUG: print 'Command-W without front window' |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 else: |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
333 if DEBUG: print "Command-" +`c` |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 else: |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
335 # See whether the front window wants it |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
336 w = FrontWindow() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
337 if w and self._windows.has_key(w): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
338 window = self._windows[w] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
339 try: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
340 do_char = window.do_char |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
341 except AttributeError: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
342 do_char = self.do_char |
|
3296
0d6b60b74838
Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
3253
diff
changeset
|
343 do_char(c, event) |
|
0d6b60b74838
Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents:
3253
diff
changeset
|
344 # else it wasn't for us, sigh... |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 def do_char(self, c, event): |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
347 if DEBUG: print "Character", `c` |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 def do_updateEvt(self, event): |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
350 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
351 wid = WhichWindow(message) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
352 if wid and self._windows.has_key(wid): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
353 window = self._windows[wid] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
354 window.do_rawupdate(wid, event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 else: |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
356 MacOS.HandleEvent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
358 def do_activateEvt(self, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
359 (what, message, when, where, modifiers) = event |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
360 # XXXX Incorrect, should be fixed in suspendresume |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
361 if type(message) == type(1): |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
362 wid = WhichWindow(message) |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
363 else: |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
364 wid = message |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
365 if wid and self._windows.has_key(wid): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
366 window = self._windows[wid] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
367 window.do_activate(modifiers & 1, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
368 else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
369 MacOS.HandleEvent(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
370 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
371 def do_osEvt(self, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
372 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
373 which = (message >> 24) & 0xff |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
374 if which == 1: # suspend/resume |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
375 self.do_suspendresume(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
376 else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
377 if DEBUG: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
378 print 'unknown osEvt:', |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
379 self.printevent(event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
380 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
381 def do_suspendresume(self, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
382 # Is this a good idea??? |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
383 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
384 w = FrontWindow() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
385 if w: |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
386 # XXXX Incorrect, should stuff windowptr into message field |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
387 nev = (activateEvt, w, when, where, message&1) |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
388 self.do_activateEvt(nev) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
389 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 def do_kHighLevelEvent(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 (what, message, when, where, modifiers) = event |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
392 if DEBUG: |
|
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
393 print "High Level Event:", |
|
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
394 self.printevent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 try: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 AEProcessAppleEvent(event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 except: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 print "AEProcessAppleEvent error:" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 traceback.print_exc() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 def do_unknownevent(self, event): |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
402 if DEBUG: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
403 print "Unhandled event:", |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
404 self.printevent(event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 def printevent(self, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 (what, message, when, where, modifiers) = event |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 nicewhat = `what` |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 if eventname.has_key(what): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 nicewhat = eventname[what] |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 print nicewhat, |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 if what == kHighLevelEvent: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 h, v = where |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 print `ostypecode(message)`, hex(when), `ostypecode(h | (v<<16))`, |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 else: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 print hex(message), hex(when), where, |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 print hex(modifiers) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 class MenuBar: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 """Represent a set of menus in a menu bar. |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 Interface: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 - (constructor) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 - (destructor) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 - addmenu |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 - addpopup (normally used internally) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 - dispatch (called from Application) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 """ |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 nextid = 1 # Necessarily a class variable |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 def getnextid(self): |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
435 id = MenuBar.nextid |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
436 MenuBar.nextid = id+1 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 return id |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
439 def __init__(self, parent=None): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
440 self.parent = parent |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 ClearMenuBar() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 self.bar = GetMenuBar() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 self.menus = {} |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
445 # XXX necessary? |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
446 def close(self): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
447 self.parent = None |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
448 self.bar = None |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
449 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 def addmenu(self, title, after = 0): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 id = self.getnextid() |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
452 if DEBUG: print 'Newmenu', title, id # XXXX |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 m = NewMenu(id, title) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 m.InsertMenu(after) |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
455 if self.parent: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
456 self.parent.needmenubarredraw = 1 |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
457 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
458 DrawMenuBar() |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 return id, m |
|
3449
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
460 |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
461 def delmenu(self, id): |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
462 if DEBUG: print 'Delmenu', id # XXXX |
|
3449
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
463 DeleteMenu(id) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 def addpopup(self, title = ''): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 return self.addmenu(title, -1) |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
467 |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
468 # Useless: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
469 # def install(self): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
470 # if not self.bar: return |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
471 # SetMenuBar(self.bar) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
472 # if self.parent: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
473 # self.parent.needmenubarredraw = 1 |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
474 # else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
475 # DrawMenuBar() |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
477 def fixmenudimstate(self): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
478 for m in self.menus.keys(): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
479 menu = self.menus[m] |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
480 if menu.__class__ == FrameWork.AppleMenu: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
481 continue |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
482 for i in range(len(menu.items)): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
483 label, shortcut, callback, kind = menu.items[i] |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
484 if type(callback) == types.StringType: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
485 wid = Win.FrontWindow() |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
486 if wid and self.parent._windows.has_key(wid): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
487 window = self.parent._windows[wid] |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
488 if hasattr(window, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
489 menu.menu.EnableItem(i + 1) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
490 elif hasattr(self.parent, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
491 menu.menu.EnableItem(i + 1) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
492 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
493 menu.menu.DisableItem(i + 1) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
494 elif hasattr(self.parent, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
495 menu.menu.EnableItem(i + 1) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
496 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
497 menu.menu.DisableItem(i + 1) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
498 elif callback: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
499 pass |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
500 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 def dispatch(self, id, item, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 if self.menus.has_key(id): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 self.menus[id].dispatch(id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 else: |
|
2991
448edc923cad
Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents:
2837
diff
changeset
|
505 if DEBUG: print "MenuBar.dispatch(%d, %d, %s, %s)" % \ |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 (id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
508 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 # XXX Need a way to get menus as resources and bind them to callbacks |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 class Menu: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 "One menu." |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 def __init__(self, bar, title, after=0): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 self.bar = bar |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 self.id, self.menu = self.bar.addmenu(title, after) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 bar.menus[self.id] = self |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 self.items = [] |
|
3449
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
519 |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
520 def delete(self): |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
521 self.bar.delmenu(self.id) |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
522 del self.bar.menus[self.id] |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
523 del self.bar |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
524 del self.items |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
525 del self.menu |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
526 del self.id |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
528 def additem(self, label, shortcut=None, callback=None, kind=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
529 self.menu.AppendMenu('x') # add a dummy string |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
530 self.items.append(label, shortcut, callback, kind) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 item = len(self.items) |
|
2837
b988a4aca6f9
Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2632
diff
changeset
|
532 self.menu.SetMenuItemText(item, label) # set the actual text |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 if shortcut: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 self.menu.SetItemCmd(item, ord(shortcut)) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 return item |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 def addcheck(self, label, shortcut=None, callback=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
538 return self.additem(label, shortcut, callback, 'check') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 def addradio(self, label, shortcut=None, callback=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 return self.additem(label, shortcut, callback, 'radio') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
542 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
543 def addseparator(self): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 self.menu.AppendMenu('(-') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 self.items.append('', None, None, 'separator') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
546 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 def addsubmenu(self, label, title=''): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 sub = Menu(self.bar, title, -1) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 item = self.additem(label, '\x1B', None, 'submenu') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
550 self.menu.SetItemMark(item, sub.id) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
551 return sub |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
552 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
553 def dispatch(self, id, item, window, event): |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
554 title, shortcut, callback, mtype = self.items[item-1] |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
555 if callback: |
|
4335
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
556 if not self.bar.parent or type(callback) <> types.StringType: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
557 menuhandler = callback |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
558 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
559 # callback is string |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
560 wid = Win.FrontWindow() |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
561 if wid and self.bar.parent._windows.has_key(wid): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
562 window = self.bar.parent._windows[wid] |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
563 if hasattr(window, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
564 menuhandler = getattr(window, "domenu_" + callback) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
565 elif hasattr(self.bar.parent, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
566 menuhandler = getattr(self.bar.parent, "domenu_" + callback) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
567 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
568 # nothing we can do. we shouldn't have come this far |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
569 # since the menu item should have been disabled... |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
570 return |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
571 elif hasattr(self.bar.parent, "domenu_" + callback): |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
572 menuhandler = getattr(self.bar.parent, "domenu_" + callback) |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
573 else: |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
574 # nothing we can do. we shouldn't have come this far |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
575 # since the menu item should have been disabled... |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
576 return |
|
366d72f12794
Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents:
4312
diff
changeset
|
577 menuhandler(id, item, window, event) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 |
|
3510
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
579 def enable(self, onoff): |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
580 if onoff: |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
581 self.menu.EnableItem(0) |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
582 else: |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
583 self.menu.DisableItem(0) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 class MenuItem: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 def __init__(self, menu, title, shortcut=None, callback=None, kind=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 self.item = menu.additem(title, shortcut, callback) |
|
3449
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
588 self.menu = menu |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
589 |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
590 def check(self, onoff): |
|
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
591 self.menu.menu.CheckItem(self.item, onoff) |
|
3510
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
592 |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
593 def enable(self, onoff): |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
594 if onoff: |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
595 self.menu.menu.EnableItem(self.item) |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
596 else: |
|
a1c0c2a38883
Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents:
3467
diff
changeset
|
597 self.menu.menu.DisableItem(self.item) |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
598 |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
599 def settext(self, text): |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
600 self.menu.menu.SetMenuItemText(self.item, text) |
|
3449
c3e51eb1c14f
Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents:
3310
diff
changeset
|
601 |
|
3540
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
602 def setstyle(self, style): |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
603 self.menu.menu.SetItemStyle(self.item, style) |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
604 |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
605 def seticon(self, icon): |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
606 self.menu.menu.SetItemIcon(self.item, icon) |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
607 |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
608 def setcmd(self, cmd): |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
609 self.menu.menu.SetItemCmd(self.item, cmd) |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
610 |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
611 def setmark(self, cmd): |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
612 self.menu.menu.SetItemMark(self.item, cmd) |
|
2b166b220c11
Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3533
diff
changeset
|
613 |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 class RadioItem(MenuItem): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 def __init__(self, menu, title, shortcut=None, callback=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 MenuItem.__init__(self, menu, title, shortcut, callback, 'radio') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 class CheckItem(MenuItem): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 def __init__(self, menu, title, shortcut=None, callback=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 MenuItem.__init__(self, menu, title, shortcut, callback, 'check') |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 def Separator(menu): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 menu.addseparator() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 def SubMenu(menu, label, title=''): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 return menu.addsubmenu(label, title) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 class AppleMenu(Menu): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 def __init__(self, bar, abouttext="About me...", aboutcallback=None): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 Menu.__init__(self, bar, "\024") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 self.additem(abouttext, None, aboutcallback) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 self.addseparator() |
|
2837
b988a4aca6f9
Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2632
diff
changeset
|
636 self.menu.AppendResMenu('DRVR') |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 def dispatch(self, id, item, window, event): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 if item == 1: |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 Menu.dispatch(self, id, item, window, event) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 else: |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
642 name = self.menu.GetMenuItemText(item) |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 OpenDeskAcc(name) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
645 class Window: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
646 """A single window belonging to an application""" |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
647 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
648 def __init__(self, parent): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
649 self.wid = None |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
650 self.parent = parent |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
651 |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
652 def open(self, bounds=(40, 40, 400, 400), resid=None): |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
653 if resid <> None: |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
654 self.wid = GetNewWindow(resid, -1) |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
655 else: |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
656 self.wid = NewWindow(bounds, self.__class__.__name__, 1, |
| 3814 | 657 8, -1, 1, 0) # changed to proc id 8 to include zoom box. jvr |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
658 self.do_postopen() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
659 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
660 def do_postopen(self): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
661 """Tell our parent we exist""" |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
662 self.parent.appendwindow(self.wid, self) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
663 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
664 def close(self): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
665 self.do_postclose() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
666 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
667 def do_postclose(self): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
668 self.parent.removewindow(self.wid) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
669 self.parent = None |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
670 self.wid = None |
|
3310
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
671 |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
672 def SetPort(self): |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
673 # Convinience method |
|
604b1fc26d63
Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents:
3296
diff
changeset
|
674 SetPort(self.wid) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
675 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
676 def do_inDrag(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
677 where = event[3] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
678 window.DragWindow(where, self.draglimit) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
679 |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
680 draglimit = screenbounds |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
681 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
682 def do_inGoAway(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
683 where = event[3] |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
684 if window.TrackGoAway(where): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
685 self.close() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
686 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
687 def do_inZoom(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
688 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
689 if window.TrackBox(where, partcode): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
690 window.ZoomWindow(partcode, 1) |
| 3814 | 691 rect = window.GetWindowUserState() # so that zoom really works... jvr |
| 692 self.do_postresize(rect[2] - rect[0], rect[3] - rect[1], window) # jvr | |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
693 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
694 def do_inZoomIn(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
695 SetPort(window) # !!! |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
696 self.do_inZoom(partcode, window, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
697 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
698 def do_inZoomOut(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
699 SetPort(window) # !!! |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
700 self.do_inZoom(partcode, window, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
701 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
702 def do_inGrow(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
703 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
704 result = window.GrowWindow(where, self.growlimit) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
705 if result: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
706 height = (result>>16) & 0xffff # Hi word |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
707 width = result & 0xffff # Lo word |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
708 self.do_resize(width, height, window) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
709 |
| 3814 | 710 growlimit = (50, 50, screenbounds[2] - screenbounds[0], screenbounds[3] - screenbounds[1]) # jvr |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
711 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
712 def do_resize(self, width, height, window): |
| 3814 | 713 l, t, r, b = self.wid.GetWindowPort().portRect # jvr, forGrowIcon |
| 714 self.SetPort() # jvr | |
| 715 InvalRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr | |
| 716 window.SizeWindow(width, height, 1) # changed updateFlag to true jvr | |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
717 self.do_postresize(width, height, window) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
718 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
719 def do_postresize(self, width, height, window): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
720 SetPort(window) |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
721 InvalRect(window.GetWindowPort().portRect) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
722 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
723 def do_inContent(self, partcode, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
724 # |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
725 # If we're not frontmost, select ourselves and wait for |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
726 # the activate event. |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
727 # |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
728 if FrontWindow() <> window: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
729 window.SelectWindow() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
730 return |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
731 # We are. Handle the event. |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
732 (what, message, when, where, modifiers) = event |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
733 SetPort(window) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
734 local = GlobalToLocal(where) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
735 self.do_contentclick(local, modifiers, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
736 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
737 def do_contentclick(self, local, modifiers, event): |
| 3814 | 738 if DEBUG: |
| 739 print 'Click in contents at %s, modifiers %s'%(local, modifiers) | |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
740 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
741 def do_rawupdate(self, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
742 if DEBUG: print "raw update for", window |
|
3253
f89cdda7405a
Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents:
3245
diff
changeset
|
743 SetPort(window) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
744 window.BeginUpdate() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
745 self.do_update(window, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
746 window.EndUpdate() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
747 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
748 def do_update(self, window, event): |
| 3814 | 749 if DEBUG: |
| 750 import time | |
| 751 for i in range(8): | |
| 752 time.sleep(0.1) | |
| 753 InvertRgn(window.GetWindowPort().visRgn) | |
| 754 FillRgn(window.GetWindowPort().visRgn, qd.gray) | |
| 755 else: | |
| 756 EraseRgn(window.GetWindowPort().visRgn) | |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
757 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
758 def do_activate(self, activate, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
759 if DEBUG: print 'Activate %d for %s'%(activate, self.wid) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
760 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
761 class ControlsWindow(Window): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
762 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
763 def do_rawupdate(self, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
764 if DEBUG: print "raw update for", window |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
765 SetPort(window) |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
766 window.BeginUpdate() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
767 self.do_update(window, event) |
| 3814 | 768 #DrawControls(window) # jvr |
| 769 UpdateControls(window, window.GetWindowPort().visRgn) # jvr | |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
770 window.DrawGrowIcon() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
771 window.EndUpdate() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
772 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
773 def do_controlhit(self, window, control, pcode, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
774 if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
775 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
776 def do_inContent(self, partcode, window, event): |
|
3533
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
777 if FrontWindow() <> window: |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
778 window.SelectWindow() |
|
e67adc8b2f16
- Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents:
3527
diff
changeset
|
779 return |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
780 (what, message, when, where, modifiers) = event |
|
3253
f89cdda7405a
Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents:
3245
diff
changeset
|
781 SetPort(window) # XXXX Needed? |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
782 local = GlobalToLocal(where) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
783 ctltype, control = FindControl(local, window) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
784 if ctltype and control: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
785 pcode = control.TrackControl(local) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
786 if pcode: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
787 self.do_controlhit(window, control, pcode, event) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
788 else: |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
789 if DEBUG: print "FindControl(%s, %s) -> (%s, %s)" % \ |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
790 (local, window, ctltype, control) |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
791 self.do_contentclick(local, modifiers, event) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
792 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
793 class ScrolledWindow(ControlsWindow): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
794 def __init__(self, parent): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
795 self.barx = self.bary = None |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
796 self.barx_enabled = self.bary_enabled = 1 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
797 self.activated = 1 |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
798 ControlsWindow.__init__(self, parent) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
799 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
800 def scrollbars(self, wantx=1, wanty=1): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
801 SetPort(self.wid) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
802 self.barx = self.bary = None |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
803 self.barx_enabled = self.bary_enabled = 1 |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
804 x0, y0, x1, y1 = self.wid.GetWindowPort().portRect |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
805 vx, vy = self.getscrollbarvalues() |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
806 if vx == None: self.barx_enabled, vx = 0, 0 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
807 if vy == None: self.bary_enabled, vy = 0, 0 |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
808 if wantx: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
809 rect = x0-1, y1-(SCROLLBARWIDTH-1), x1-(SCROLLBARWIDTH-2), y1+1 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
810 self.barx = NewControl(self.wid, rect, "", 1, vx, 0, 32767, 16, 0) |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
811 if not self.barx_enabled: self.barx.HiliteControl(255) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
812 ## InvalRect(rect) |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
813 if wanty: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
814 rect = x1-(SCROLLBARWIDTH-1), y0-1, x1+1, y1-(SCROLLBARWIDTH-2) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
815 self.bary = NewControl(self.wid, rect, "", 1, vy, 0, 32767, 16, 0) |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
816 if not self.bary_enabled: self.bary.HiliteControl(255) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
817 ## InvalRect(rect) |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
818 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
819 def do_postclose(self): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
820 self.barx = self.bary = None |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
821 ControlsWindow.do_postclose(self) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
822 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
823 def do_activate(self, onoff, event): |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
824 self.activated = onoff |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
825 if onoff: |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
826 if self.barx and self.barx_enabled: |
| 3814 | 827 self.barx.ShowControl() # jvr |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
828 if self.bary and self.bary_enabled: |
| 3814 | 829 self.bary.ShowControl() # jvr |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
830 else: |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
831 if self.barx: |
| 3814 | 832 self.barx.HideControl() # jvr; An inactive window should have *hidden* |
| 833 # scrollbars, not just dimmed (no matter what | |
| 834 # BBEdit does... look at the Finder) | |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
835 if self.bary: |
| 3814 | 836 self.bary.HideControl() # jvr |
| 837 self.wid.DrawGrowIcon() # jvr | |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
838 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
839 def do_postresize(self, width, height, window): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
840 l, t, r, b = self.wid.GetWindowPort().portRect |
| 3814 | 841 self.SetPort() |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
842 if self.barx: |
| 3814 | 843 self.barx.HideControl() # jvr |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
844 self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1)) |
| 3814 | 845 self.barx.SizeControl((r-l)-(SCROLLBARWIDTH-3), SCROLLBARWIDTH) # jvr |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
846 if self.bary: |
| 3814 | 847 self.bary.HideControl() # jvr |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
848 self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1) |
| 3814 | 849 self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-3)) # jvr |
| 850 if self.barx: | |
| 851 self.barx.ShowControl() # jvr | |
| 852 ValidRect((l, b - SCROLLBARWIDTH + 1, r - SCROLLBARWIDTH + 2, b)) # jvr | |
| 853 if self.bary: | |
| 854 self.bary.ShowControl() # jvr | |
| 855 ValidRect((r - SCROLLBARWIDTH + 1, t, r, b - SCROLLBARWIDTH + 2)) # jvr | |
| 856 InvalRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr, growicon | |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
857 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
858 def do_controlhit(self, window, control, pcode, event): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
859 if control == self.barx: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
860 bar = self.barx |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
861 which = 'x' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
862 elif control == self.bary: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
863 bar = self.bary |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
864 which = 'y' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
865 else: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
866 return 0 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
867 value = None |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
868 if pcode == inUpButton: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
869 what = '-' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
870 elif pcode == inDownButton: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
871 what = '+' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
872 elif pcode == inPageUp: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
873 what = '--' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
874 elif pcode == inPageDown: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
875 what = '++' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
876 else: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
877 what = 'set' |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
878 value = bar.GetControlValue() |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
879 self.scrollbar_callback(which, what, value) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
880 self.updatescrollbars() |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
881 return 1 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
882 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
883 def updatescrollbars(self): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
884 SetPort(self.wid) |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
885 vx, vy = self.getscrollbarvalues() |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
886 if self.barx: |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
887 if vx == None: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
888 self.barx.HiliteControl(255) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
889 self.barx_enabled = 0 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
890 else: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
891 if not self.barx_enabled: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
892 self.barx_enabled = 1 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
893 if self.activated: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
894 self.barx.HiliteControl(0) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
895 self.barx.SetControlValue(vx) |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
896 if self.bary: |
|
3527
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
897 if vy == None: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
898 self.bary.HiliteControl(255) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
899 self.bary_enabled = 0 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
900 else: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
901 if not self.bary_enabled: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
902 self.bary_enabled = 1 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
903 if self.activated: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
904 self.bary.HiliteControl(0) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
905 self.bary.SetControlValue(vy) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
906 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
907 # Auxiliary function: convert standard text/image/etc coordinate |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
908 # to something palatable as getscrollbarvalues() return |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
909 def scalebarvalue(self, absmin, absmax, curmin, curmax): |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
910 if curmin <= absmin and curmax >= absmax: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
911 return None |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
912 if curmin <= absmin: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
913 return 0 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
914 if curmax >= absmax: |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
915 return 32767 |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
916 perc = float(curmin-absmin)/float(absmax-absmin) |
|
510dbfa8c599
Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3514
diff
changeset
|
917 return int(perc*32767) |
|
3514
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
918 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
919 # To be overridden: |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
920 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
921 def getscrollbarvalues(self): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
922 return 0, 0 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
923 |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
924 def scrollbar_callback(self, which, what, value): |
|
05af29e8df0e
Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents:
3510
diff
changeset
|
925 print 'scroll', which, what, value |
|
2998
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
926 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
927 class DialogWindow(Window): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
928 """A modeless dialog window""" |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
929 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
930 def open(self, resid): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
931 self.wid = GetNewDialog(resid, -1) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
932 self.do_postopen() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
933 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
934 def close(self): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
935 self.do_postclose() |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
936 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
937 def do_itemhit(self, item, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
938 print 'Dialog %s, item %d hit'%(self.wid, item) |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
939 |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
940 def do_rawupdate(self, window, event): |
|
9bca94a36a08
Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents:
2991
diff
changeset
|
941 pass |
|
2632
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
942 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
943 def ostypecode(x): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
944 "Convert a long int to the 4-character code it really is" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
945 s = '' |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
946 for i in range(4): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
947 x, c = divmod(x, 256) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
948 s = chr(c) + s |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
949 return s |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
950 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
951 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
952 class TestApp(Application): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
953 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 "This class is used by the test() function" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
955 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
956 def makeusermenus(self): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
957 self.filemenu = m = Menu(self.menubar, "File") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
958 self.saveitem = MenuItem(m, "Save", "S", self.save) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
959 Separator(m) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
960 self.optionsmenu = mm = SubMenu(m, "Options") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
961 self.opt1 = CheckItem(mm, "Arguments") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
962 self.opt2 = CheckItem(mm, "Being hit on the head lessons") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
963 self.opt3 = CheckItem(mm, "Complaints") |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 Separator(m) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 self.quititem = MenuItem(m, "Quit", "Q", self.quit) |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
966 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
967 def save(self, *args): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
968 print "Save" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
970 def quit(self, *args): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
971 raise self |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
974 def test(): |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
975 "Test program" |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
976 app = TestApp() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 app.mainloop() |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
978 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 if __name__ == '__main__': |
|
75e9e56b5f9b
two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
981 test() |
