annotate Mac/Lib/FrameWork.py @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 366d72f12794
children 9bda38c67f4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
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
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
66 next_window_x = 16 # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
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
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
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
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
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
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
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):
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
98 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
99 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
100 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
101 if nomenubar:
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
102 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
103 else:
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
104 self.makemenubar()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 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
107 self.menubar = MenuBar(self)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 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
109 self.makeusermenus()
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
110
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
111 def makeusermenus(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
112 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
113 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
114
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
115 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
116 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
117
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
118 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
119 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
120
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
121 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
122 del self._windows[wid]
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 def getabouttext(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return "About %s..." % self.__class__.__name__
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 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
128 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
129
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 # 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
131 # 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
132 # 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
133 # event type.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 # 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
135 # events.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 # (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
137 # 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
138
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 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
140 self.quitting = 0
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 saveyield = MacOS.EnableAppswitch(self.yield)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 try:
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
143 while not self.quitting:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 self.do1event(mask, wait)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 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
147 # 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
148 # 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
149 # applications.
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 break
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 finally:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 MacOS.EnableAppswitch(saveyield)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 yield = -1
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 def do1event(self, mask = everyEvent, wait = 0):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
157 ok, event = self.getevent(mask, wait)
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
158 if IsDialogEvent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
159 if self.do_dialogevent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
160 return
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
161 if ok:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 self.dispatch(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
163 else:
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
164 self.idle(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
165
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
166 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
167 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 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
170 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
171 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
172 self.needmenubarredraw = 0
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 ok, event = WaitNextEvent(mask, wait)
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
174 return ok, event
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
175
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 def dispatch(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 name = "do_" + eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 name = "do_%d" % what
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 handler = getattr(self, name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 except AttributeError:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 handler = self.do_unknownevent
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 handler(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
187
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
188 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
189 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
190 if gotone:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
191 if self._windows.has_key(window):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
192 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
193 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
194 print 'Dialog event for unknown dialog'
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
195 return 1
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
196 return 0
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 def do_mouseDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 (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
200 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
201
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
202 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
203 # 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
204 #
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if partname.has_key(partcode):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 name = "do_" + partname[partcode]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 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
209
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
210 if wid == None:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
211 # 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
212 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
213 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
214 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
215 # 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
216 # else's window
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
217 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
218 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
219 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
220 # 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
221 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
222 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
223 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
224 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
225 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
226 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
227 # 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
228 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
229 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
230
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 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
232 MacOS.HandleEvent(event)
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_inDesk(self, partcode, window, event):
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
235 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 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
238 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
239 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
240 return
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 result = MenuSelect(where)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 id = (result>>16) & 0xffff # Hi word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 item = result & 0xffff # Lo word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 self.do_rawmenu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 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
248 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 self.do_menu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 finally:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 HiliteMenu(0)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
252
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 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
254 self.menubar.dispatch(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
256
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 def do_unknownpartcode(self, partcode, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 (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
259 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
260 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
261 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
262 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
263
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
264 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
265 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
266 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 def do_keyDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
270
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 def do_autoKey(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 if not event[-1] & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 def do_key(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 c = chr(message & charCodeMask)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 if modifiers & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 if c == '.':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 else:
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
282 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
283 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
284 return
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 result = MenuKey(ord(c))
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 id = (result>>16) & 0xffff # Hi word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 item = result & 0xffff # Lo word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 if id:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 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
290 # elif c == 'w':
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
291 # w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
292 # if w:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
293 # 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
294 # else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
295 # 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
296 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
297 if DEBUG: print "Command-" +`c`
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 else:
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
299 # 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
300 w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
301 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
302 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
303 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
304 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
305 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
306 do_char = self.do_char
3296
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
307 do_char(c, event)
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
308 # 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
309
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 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
311 if DEBUG: print "Character", `c`
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
312
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 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
314 (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
315 wid = WhichWindow(message)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
316 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
317 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
318 window.do_rawupdate(wid, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
320 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
321
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
322 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
323 (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
324 # 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
325 if type(message) == type(1):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
326 wid = WhichWindow(message)
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
327 else:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
328 wid = message
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
329 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
330 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
331 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
332 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
333 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
334
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
335 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
336 (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
337 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
338 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
339 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
340 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
341 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
342 print 'unknown osEvt:',
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
343 self.printevent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
344
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
345 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
346 # 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
347 (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
348 w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
349 if w:
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
350 # 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
351 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
352 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
353
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 def do_kHighLevelEvent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 (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
356 if DEBUG:
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
357 print "High Level Event:",
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
358 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 AEProcessAppleEvent(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 except:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 print "AEProcessAppleEvent error:"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 traceback.print_exc()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
364
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 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
366 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
367 print "Unhandled event:",
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
368 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 def printevent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 nicewhat = `what`
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 nicewhat = eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 print nicewhat,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 if what == kHighLevelEvent:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 h, v = where
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 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
379 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 print hex(message), hex(when), where,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 print hex(modifiers)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
383
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 class MenuBar:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 """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
386
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 Interface:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
388
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 - (constructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 - (destructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 - addmenu
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 - addpopup (normally used internally)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 - dispatch (called from Application)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
395
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 nextid = 1 # Necessarily a class variable
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
397
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 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
399 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
400 MenuBar.nextid = id+1
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 return id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
402
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
403 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
404 self.parent = parent
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 ClearMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 self.bar = GetMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 self.menus = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
408
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
409 # 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
410 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
411 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
412 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
413
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 def addmenu(self, title, after = 0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 id = self.getnextid()
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
416 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
417 m = NewMenu(id, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 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
419 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
420 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
421 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
422 DrawMenuBar()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 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
424
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
425 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
426 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
427 DeleteMenu(id)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
428
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 def addpopup(self, title = ''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 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
431
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
432 # 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
433 # 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
434 # 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
435 # 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
436 # 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
437 # 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
438 # 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
439 # DrawMenuBar()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
440
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
441 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
442 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
443 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
444 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
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458 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
459 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
460 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
461 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
462 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
463 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
464
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 if self.menus.has_key(id):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 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
468 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
469 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
470 (id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
471
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
472
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 # 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
474
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 class Menu:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 "One menu."
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
477
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 def __init__(self, bar, title, after=0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 self.bar = bar
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 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
481 bar.menus[self.id] = self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
482 self.items = []
3449
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
483
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
484 def delete(self):
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
485 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
486 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
487 del self.bar
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
488 del self.items
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
489 del self.menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
490 del self.id
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
491
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 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
493 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
494 self.items.append(label, shortcut, callback, kind)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 item = len(self.items)
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
496 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
497 if shortcut:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 self.menu.SetItemCmd(item, ord(shortcut))
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 return item
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
500
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 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
502 return self.additem(label, shortcut, callback, 'check')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
503
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
504 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
505 return self.additem(label, shortcut, callback, 'radio')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
506
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
507 def addseparator(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 self.menu.AppendMenu('(-')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
509 self.items.append('', None, None, 'separator')
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 def addsubmenu(self, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 sub = Menu(self.bar, title, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
513 item = self.additem(label, '\x1B', None, 'submenu')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 self.menu.SetItemMark(item, sub.id)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 return sub
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
516
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
517 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
518 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
519 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
520 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
521 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
522 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
523 # 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
524 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
525 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
526 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
527 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
528 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
529 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
530 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
531 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
532 # 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
533 # 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
534 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
535 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
536 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
537 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
538 # 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
539 # 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
540 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
541 menuhandler(id, item, window, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
542
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
543 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
544 if onoff:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
545 self.menu.EnableItem(0)
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
546 else:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
547 self.menu.DisableItem(0)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
548
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 class MenuItem:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 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
551 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
552 self.menu = menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
553
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
554 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
555 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
556
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
557 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
558 if onoff:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
559 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
560 else:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
561 self.menu.menu.DisableItem(self.item)
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
562
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
563 def settext(self, text):
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
564 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
565
3540
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
566 def setstyle(self, style):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
567 self.menu.menu.SetItemStyle(self.item, style)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
568
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
569 def seticon(self, icon):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
570 self.menu.menu.SetItemIcon(self.item, icon)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
571
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
572 def setcmd(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
573 self.menu.menu.SetItemCmd(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
574
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
575 def setmark(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
576 self.menu.menu.SetItemMark(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
577
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
578
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
579 class RadioItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 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
581 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
582
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 class CheckItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
584 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
585 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
586
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
587 def Separator(menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 menu.addseparator()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
589
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 def SubMenu(menu, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
591 return menu.addsubmenu(label, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
592
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
593
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
594 class AppleMenu(Menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
595
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 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
597 Menu.__init__(self, bar, "\024")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
598 self.additem(abouttext, None, aboutcallback)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
599 self.addseparator()
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
600 self.menu.AppendResMenu('DRVR')
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
601
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 if item == 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 Menu.dispatch(self, id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
605 else:
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
606 name = self.menu.GetMenuItemText(item)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 OpenDeskAcc(name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
609 class Window:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
610 """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
611
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
612 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
613 self.wid = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
614 self.parent = parent
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
615
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
616 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
617 if resid <> None:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
618 self.wid = GetNewWindow(resid, -1)
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
619 else:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
620 self.wid = NewWindow(bounds, self.__class__.__name__, 1,
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
621 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
622 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
623
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
624 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
625 """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
626 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
627
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
628 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
629 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
630
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
631 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
632 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
633 self.parent = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
634 self.wid = None
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
635
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
636 def SetPort(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
637 # Convinience method
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
638 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
639
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
640 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
641 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
642 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
643
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
644 draglimit = screenbounds
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
645
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
646 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
647 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
648 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
649 self.close()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
650
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
651 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
652 (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
653 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
654 window.ZoomWindow(partcode, 1)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
655 rect = window.GetWindowUserState() # so that zoom really works... jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
656 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
657
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
658 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
659 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
660 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
661
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
662 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
663 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
664 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
665
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
666 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
667 (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
668 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
669 if result:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
670 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
671 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
672 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
673
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
674 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
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_resize(self, width, height, window):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
677 l, t, r, b = self.wid.GetWindowPort().portRect # jvr, forGrowIcon
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
678 self.SetPort() # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
679 InvalRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
680 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
681 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
682
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
683 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
684 SetPort(window)
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
685 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
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_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
688 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
689 # 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
690 # the activate event.
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
691 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
692 if FrontWindow() <> window:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
693 window.SelectWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
694 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
695 # 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
696 (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
697 SetPort(window)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
698 local = GlobalToLocal(where)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
699 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
700
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
701 def do_contentclick(self, local, modifiers, event):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
702 if DEBUG:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
703 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
704
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
705 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
706 if DEBUG: print "raw update for", window
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
707 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
708 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
709 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
710 window.EndUpdate()
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_update(self, window, event):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
713 if DEBUG:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
714 import time
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
715 for i in range(8):
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
716 time.sleep(0.1)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
717 InvertRgn(window.GetWindowPort().visRgn)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
718 FillRgn(window.GetWindowPort().visRgn, qd.gray)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
719 else:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
720 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
721
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
722 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
723 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
724
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
725 class ControlsWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
726
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
727 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
728 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
729 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
730 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
731 self.do_update(window, event)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
732 #DrawControls(window) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
733 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
734 window.DrawGrowIcon()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
735 window.EndUpdate()
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_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
738 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
739
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
740 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
741 if FrontWindow() <> window:
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
742 window.SelectWindow()
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
743 return
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
744 (what, message, when, where, modifiers) = event
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
745 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
746 local = GlobalToLocal(where)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
747 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
748 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
749 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
750 if pcode:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
751 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
752 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
753 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
754 (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
755 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
756
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
757 class ScrolledWindow(ControlsWindow):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
758 def __init__(self, parent):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
759 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
760 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
761 self.activated = 1
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
762 ControlsWindow.__init__(self, parent)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
763
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
764 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
765 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
766 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
767 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
768 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
769 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
770 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
771 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
772 if wantx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
773 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
774 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
775 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
776 ## InvalRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
777 if wanty:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
778 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
779 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
780 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
781 ## InvalRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
782
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
783 def do_postclose(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
784 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
785 ControlsWindow.do_postclose(self)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
786
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
787 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
788 self.activated = onoff
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
789 if onoff:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
790 if self.barx and self.barx_enabled:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
791 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
792 if self.bary and self.bary_enabled:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
793 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
794 else:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
795 if self.barx:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
796 self.barx.HideControl() # jvr; An inactive window should have *hidden*
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
797 # scrollbars, not just dimmed (no matter what
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
798 # 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
799 if self.bary:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
800 self.bary.HideControl() # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
801 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
802
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
803 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
804 l, t, r, b = self.wid.GetWindowPort().portRect
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
805 self.SetPort()
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
806 if self.barx:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
807 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
808 self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1))
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
809 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
810 if self.bary:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
811 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
812 self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
813 self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-3)) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
814 if self.barx:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
815 self.barx.ShowControl() # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
816 ValidRect((l, b - SCROLLBARWIDTH + 1, r - SCROLLBARWIDTH + 2, b)) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
817 if self.bary:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
818 self.bary.ShowControl() # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
819 ValidRect((r - SCROLLBARWIDTH + 1, t, r, b - SCROLLBARWIDTH + 2)) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
820 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
821
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
822 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
823 if control == self.barx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
824 bar = self.barx
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
825 which = 'x'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
826 elif control == self.bary:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
827 bar = self.bary
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
828 which = 'y'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
829 else:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
830 return 0
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
831 value = None
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
832 if pcode == inUpButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
833 what = '-'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
834 elif pcode == inDownButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
835 what = '+'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
836 elif pcode == inPageUp:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
837 what = '--'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
838 elif pcode == inPageDown:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
839 what = '++'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
840 else:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
841 what = 'set'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
842 value = bar.GetControlValue()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
843 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
844 self.updatescrollbars()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
845 return 1
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
846
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
847 def updatescrollbars(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
848 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
849 vx, vy = self.getscrollbarvalues()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
850 if self.barx:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
851 if vx == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
852 self.barx.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
853 self.barx_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
854 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
855 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
856 self.barx_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
857 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
858 self.barx.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
859 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
860 if self.bary:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
861 if vy == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
862 self.bary.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
863 self.bary_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
864 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
865 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
866 self.bary_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
867 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
868 self.bary.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
869 self.bary.SetControlValue(vy)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
870
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
871 # 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
872 # 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
873 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
874 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
875 return None
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
876 if curmin <= absmin:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
877 return 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
878 if curmax >= absmax:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
879 return 32767
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
880 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
881 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
882
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
883 # To be overridden:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
884
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
885 def getscrollbarvalues(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
886 return 0, 0
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
887
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
888 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
889 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
890
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
891 class DialogWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
892 """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
893
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
894 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
895 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
896 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
897
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
898 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
899 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
900
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
901 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
902 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
903
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
904 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
905 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
906
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
907 def ostypecode(x):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 "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
909 s = ''
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
910 for i in range(4):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
911 x, c = divmod(x, 256)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
912 s = chr(c) + s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
913 return s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
914
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
915
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
916 class TestApp(Application):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
917
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
918 "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
919
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
920 def makeusermenus(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
921 self.filemenu = m = Menu(self.menubar, "File")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
922 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
923 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
924 self.optionsmenu = mm = SubMenu(m, "Options")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
925 self.opt1 = CheckItem(mm, "Arguments")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
926 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
927 self.opt3 = CheckItem(mm, "Complaints")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
928 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
929 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
930
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
931 def save(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
932 print "Save"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
933
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
934 def quit(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
935 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
936
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
937
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
938 def test():
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
939 "Test program"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
940 app = TestApp()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
941 app.mainloop()
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
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
944 if __name__ == '__main__':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
945 test()