annotate Mac/Lib/FrameWork.py @ 3720:b341def4eef8 legacy-trunk

Ignore latex intermediate products.
author Guido van Rossum <guido@python.org>
date Wed, 26 Jun 1996 19:30:01 +0000
parents 2b166b220c11
children 31e100d9d929
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 *
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 import EasyDialogs
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 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
30 SCROLLBARWIDTH = 16 # Again, not a clue...
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
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 # Map event 'what' field to strings
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 eventname = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 eventname[1] = 'mouseDown'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 eventname[2] = 'mouseUp'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 eventname[3] = 'keyDown'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 eventname[4] = 'keyUp'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 eventname[5] = 'autoKey'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 eventname[6] = 'updateEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 eventname[7] = 'diskEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 eventname[8] = 'activateEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 eventname[15] = 'osEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 eventname[23] = 'kHighLevelEvent'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 # 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
47 partname = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 partname[0] = 'inDesk'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 partname[1] = 'inMenuBar'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 partname[2] = 'inSysWindow'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 partname[3] = 'inContent'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 partname[4] = 'inDrag'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 partname[5] = 'inGrow'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 partname[6] = 'inGoAway'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 partname[7] = 'inZoomIn'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 partname[8] = 'inZoomOut'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
58 #
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
59 # The useable portion of the screen
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
60 #
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
61 screenbounds = qd.screenBits.bounds
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
62 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
63 screenbounds[2]-4, screenbounds[3]-4
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
64
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
65 next_window_x = 40
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
66 next_window_y = 40
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
67
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
68 def windowbounds(width, height):
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
69 "Return sensible window bounds"
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
70 global next_window_x, next_window_y
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
71 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
72 if r > screenbounds[2]:
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
73 next_window_x = 40
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
74 if b > screenbounds[3]:
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
75 next_window_y = 40
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
76 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
77 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
78 next_window_x, next_window_y = next_window_x+20, next_window_y+20
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
79 return l, t, r, b
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 class Application:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 "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
85
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 def __init__(self):
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
87 self._windows = {}
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 self.makemenubar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 def makemenubar(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 self.menubar = MenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 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
93 self.makeusermenus()
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
94
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
95 def makeusermenus(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
96 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
97 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
98
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
99 def _quit(self, *args):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
100 raise self
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
101
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
102 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
103 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
104
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
105 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
106 del self._windows[wid]
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 def getabouttext(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 return "About %s..." % self.__class__.__name__
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 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
112 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
113
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 # 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
115 # 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
116 # 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
117 # event type.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 # 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
119 # events.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 # (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
121 # 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
122
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 def mainloop(self, mask = everyEvent, wait = 0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 saveyield = MacOS.EnableAppswitch(self.yield)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 self.do1event(mask, wait)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 except (Application, SystemExit):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 break
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 finally:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 MacOS.EnableAppswitch(saveyield)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 yield = -1
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 def do1event(self, mask = everyEvent, wait = 0):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
137 ok, event = self.getevent(mask, wait)
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
138 if IsDialogEvent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
139 if self.do_dialogevent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
140 return
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
141 if ok:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 self.dispatch(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
143 else:
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
144 self.idle(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
145
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
146 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
147 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 def getevent(self, mask = everyEvent, wait = 0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 ok, event = WaitNextEvent(mask, wait)
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
151 return ok, event
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
152
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 def dispatch(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 name = "do_" + eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 name = "do_%d" % what
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 handler = getattr(self, name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 except AttributeError:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 handler = self.do_unknownevent
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 handler(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
164
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
165 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
166 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
167 if gotone:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
168 if self._windows.has_key(window):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
169 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
170 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
171 print 'Dialog event for unknown dialog'
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
172 return 1
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
173 return 0
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 def do_mouseDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 (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
177 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
178
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
179 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
180 # 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
181 #
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 if partname.has_key(partcode):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 name = "do_" + partname[partcode]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 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
186
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
187 if wid == None:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
188 # 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
189 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
190 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
191 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
192 # 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
193 # else's window
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
194 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
195 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
196 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
197 # 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
198 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
199 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
200 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
201 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
202 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
203 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
204 # 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
205 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
206 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
207
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 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
209 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 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
212 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 def do_inMenuBar(self, partcode, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 result = MenuSelect(where)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 id = (result>>16) & 0xffff # Hi word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 item = result & 0xffff # Lo word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 self.do_rawmenu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
220
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 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
222 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 self.do_menu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 finally:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 HiliteMenu(0)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 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
228 self.menubar.dispatch(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
230
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 def do_unknownpartcode(self, partcode, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 (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
233 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
234 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
235 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
236 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
237
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
238 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
239 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
240 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 def do_keyDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 def do_autoKey(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 if not event[-1] & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 def do_key(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 c = chr(message & charCodeMask)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 if modifiers & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 if c == '.':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 result = MenuKey(ord(c))
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 id = (result>>16) & 0xffff # Hi word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 item = result & 0xffff # Lo word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 if id:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 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
261 # elif c == 'w':
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
262 # w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
263 # if w:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
264 # 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
265 # else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
266 # 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
267 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
268 if DEBUG: print "Command-" +`c`
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 else:
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
270 # 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
271 w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
272 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
273 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
274 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
275 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
276 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
277 do_char = self.do_char
3296
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
278 do_char(c, event)
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
279 # 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
280
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 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
282 if DEBUG: print "Character", `c`
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
283
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 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
285 (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
286 wid = WhichWindow(message)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
287 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
288 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
289 window.do_rawupdate(wid, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
291 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
293 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
294 (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
295 # 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
296 if type(message) == type(1):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
297 wid = WhichWindow(message)
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
298 else:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
299 wid = message
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
300 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
301 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
302 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
303 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
304 MacOS.HandleEvent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
305
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
306 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
307 (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
308 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
309 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
310 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
311 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
312 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
313 print 'unknown osEvt:',
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
314 self.printevent(event)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
315
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
316 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
317 # 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
318 (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
319 w = FrontWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
320 if w:
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
321 # 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
322 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
323 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
324
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 def do_kHighLevelEvent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 (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
327 if DEBUG:
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
328 print "High Level Event:",
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
329 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 AEProcessAppleEvent(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 except:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 print "AEProcessAppleEvent error:"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 traceback.print_exc()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
335
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 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
337 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
338 print "Unhandled event:",
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
339 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 def printevent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 nicewhat = `what`
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 nicewhat = eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 print nicewhat,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 if what == kHighLevelEvent:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 h, v = where
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 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
350 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 print hex(message), hex(when), where,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 print hex(modifiers)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
353
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
354
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 class MenuBar:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 """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
357
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 Interface:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 - (constructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 - (destructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 - addmenu
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 - addpopup (normally used internally)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 - dispatch (called from Application)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
366
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 nextid = 1 # Necessarily a class variable
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
368
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 def getnextid(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 id = self.nextid
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 self.nextid = id+1
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 return id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
373
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 def __init__(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 ClearMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 self.bar = GetMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 self.menus = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
378
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 def addmenu(self, title, after = 0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 id = self.getnextid()
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
381 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
382 m = NewMenu(id, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 m.InsertMenu(after)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 DrawMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 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
386
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
387 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
388 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
389 DeleteMenu(id)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
390
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 def addpopup(self, title = ''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 return self.addmenu(title, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
393
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 def install(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 self.bar.SetMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 DrawMenuBar()
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 dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 if self.menus.has_key(id):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 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
401 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
402 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
403 (id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
404
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 # 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
407
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 class Menu:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 "One menu."
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
410
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 def __init__(self, bar, title, after=0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 self.bar = bar
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 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
414 bar.menus[self.id] = self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 self.items = []
3449
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
416
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
417 def delete(self):
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
418 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
419 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
420 del self.bar
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
421 del self.items
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
422 del self.menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
423 del self.id
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
424
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 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
426 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
427 self.items.append(label, shortcut, callback, kind)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 item = len(self.items)
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
429 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
430 if shortcut:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 self.menu.SetItemCmd(item, ord(shortcut))
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 return item
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
433
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 def addcheck(self, label, shortcut=None, callback=None):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 return self.additem(label, shortcut, callback, 'check')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
436
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 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
438 return self.additem(label, shortcut, callback, 'radio')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
439
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 def addseparator(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 self.menu.AppendMenu('(-')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 self.items.append('', None, None, 'separator')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
443
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 def addsubmenu(self, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 sub = Menu(self.bar, title, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 item = self.additem(label, '\x1B', None, 'submenu')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 self.menu.SetItemMark(item, sub.id)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 return sub
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
449
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 title, shortcut, callback, type = self.items[item-1]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 if callback:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 callback(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
454
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
455 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
456 if onoff:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
457 self.menu.EnableItem(0)
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
458 else:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
459 self.menu.DisableItem(0)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
460
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 class MenuItem:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 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
463 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
464 self.menu = menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
465
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
466 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
467 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
468
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
469 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
470 if onoff:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
471 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
472 else:
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
473 self.menu.menu.DisableItem(self.item)
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
474
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
475 def settext(self, text):
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
476 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
477
3540
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
478 def setstyle(self, style):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
479 self.menu.menu.SetItemStyle(self.item, style)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
480
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
481 def seticon(self, icon):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
482 self.menu.menu.SetItemIcon(self.item, icon)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
483
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
484 def setcmd(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
485 self.menu.menu.SetItemCmd(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
486
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
487 def setmark(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
488 self.menu.menu.SetItemMark(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
489
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
490
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 class RadioItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 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
493 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
494
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
495 class CheckItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
496 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
497 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
498
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 def Separator(menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
500 menu.addseparator()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
501
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 def SubMenu(menu, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 return menu.addsubmenu(label, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
504
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
505
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
506 class AppleMenu(Menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
507
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 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
509 Menu.__init__(self, bar, "\024")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
510 self.additem(abouttext, None, aboutcallback)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 self.addseparator()
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
512 self.menu.AppendResMenu('DRVR')
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
513
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 if item == 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 Menu.dispatch(self, id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
517 else:
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
518 name = self.menu.GetMenuItemText(item)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 OpenDeskAcc(name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
520
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
521 class Window:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
522 """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
523
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
524 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
525 self.wid = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
526 self.parent = parent
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
527
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
528 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
529 if resid <> None:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
530 self.wid = GetNewWindow(resid, -1)
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
531 else:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
532 self.wid = NewWindow(bounds, self.__class__.__name__, 1,
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
533 0, -1, 1, 0)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
534 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
535
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
536 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
537 """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
538 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
539
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
540 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
541 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
542
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
543 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
544 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
545 self.parent = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
546 self.wid = None
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
547
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
548 def SetPort(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
549 # Convinience method
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
550 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
551
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
552 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
553 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
554 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
555
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
556 draglimit = screenbounds
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
557
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
558 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
559 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
560 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
561 self.close()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
562
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
563 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
564 (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
565 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
566 window.ZoomWindow(partcode, 1)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
567
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
568 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
569 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
570 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
571
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
572 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
573 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
574 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
575
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
576 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
577 (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
578 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
579 if result:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
580 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
581 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
582 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
583
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
584 growlimit = screenbounds
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
585
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
586 def do_resize(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
587 window.SizeWindow(width, height, 0)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
588 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
589
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
590 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
591 SetPort(window)
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
592 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
593
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
594 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
595 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
596 # 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
597 # the activate event.
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
598 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
599 if FrontWindow() <> window:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
600 window.SelectWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
601 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
602 # 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
603 (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
604 SetPort(window)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
605 local = GlobalToLocal(where)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
606 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
607
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
608 def do_contentclick(self, local, modifiers, event):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
609 print 'Click in contents at %s, modifiers %s'%(local, modifiers)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
610
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
611 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
612 if DEBUG: print "raw update for", window
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
613 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
614 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
615 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
616 window.EndUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
617
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
618 def do_update(self, window, event):
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
619 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
620
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
621 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
622 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
623
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
624 class ControlsWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
625
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
626 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
627 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
628 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
629 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
630 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
631 DrawControls(window)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
632 window.DrawGrowIcon()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
633 window.EndUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
634
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
635 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
636 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
637
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
638 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
639 if FrontWindow() <> window:
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
640 window.SelectWindow()
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
641 return
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
642 (what, message, when, where, modifiers) = event
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
643 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
644 local = GlobalToLocal(where)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
645 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
646 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
647 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
648 if pcode:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
649 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
650 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
651 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
652 (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
653 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
654
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
655 class ScrolledWindow(ControlsWindow):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
656 def __init__(self, parent):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
657 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
658 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
659 self.activated = 1
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
660 ControlsWindow.__init__(self, parent)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
661
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
662 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
663 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
664 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
665 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
666 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
667 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
668 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
669 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
670 if wantx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
671 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
672 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
673 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
674 ## InvalRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
675 if wanty:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
676 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
677 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
678 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
679 ## InvalRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
680
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
681 def do_postclose(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
682 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
683 ControlsWindow.do_postclose(self)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
684
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
685 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
686 self.activated = onoff
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
687 if onoff:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
688 if self.barx and self.barx_enabled:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
689 self.barx.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
690 if self.bary and self.bary_enabled:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
691 self.bary.HiliteControl(0)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
692 else:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
693 if self.barx:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
694 self.barx.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
695 if self.bary:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
696 self.bary.HiliteControl(255)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
697
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
698 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
699 l, t, r, b = self.wid.GetWindowPort().portRect
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
700 if self.barx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
701 self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1))
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
702 self.barx.SizeControl((r-l)-(SCROLLBARWIDTH-2), SCROLLBARWIDTH)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
703 if self.bary:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
704 self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
705 self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-2))
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
706 InvalRect((l, t, r, b))
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
707
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
708 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
709 if control == self.barx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
710 bar = self.barx
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
711 which = 'x'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
712 elif control == self.bary:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
713 bar = self.bary
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
714 which = 'y'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
715 else:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
716 return 0
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
717 value = None
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
718 if pcode == inUpButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
719 what = '-'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
720 elif pcode == inDownButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
721 what = '+'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
722 elif pcode == inPageUp:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
723 what = '--'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
724 elif pcode == inPageDown:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
725 what = '++'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
726 else:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
727 what = 'set'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
728 value = bar.GetControlValue()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
729 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
730 self.updatescrollbars()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
731 return 1
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
732
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
733 def updatescrollbars(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
734 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
735 vx, vy = self.getscrollbarvalues()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
736 if self.barx:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
737 if vx == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
738 self.barx.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
739 self.barx_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
740 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
741 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
742 self.barx_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
743 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
744 self.barx.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
745 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
746 if self.bary:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
747 if vy == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
748 self.bary.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
749 self.bary_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
750 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
751 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
752 self.bary_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
753 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
754 self.bary.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
755 self.bary.SetControlValue(vy)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
756
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
757 # 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
758 # 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
759 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
760 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
761 return None
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
762 if curmin <= absmin:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
763 return 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
764 if curmax >= absmax:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
765 return 32767
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
766 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
767 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
768
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
769 # To be overridden:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
770
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
771 def getscrollbarvalues(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
772 return 0, 0
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
773
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
774 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
775 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
776
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
777 class DialogWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
778 """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
779
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
780 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
781 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
782 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
783
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
784 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
785 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
786
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
787 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
788 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
789
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
790 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
791 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
792
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 def ostypecode(x):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 "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
795 s = ''
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
796 for i in range(4):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
797 x, c = divmod(x, 256)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
798 s = chr(c) + s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
799 return s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
800
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
801
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
802 class TestApp(Application):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
803
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
804 "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
805
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
806 def makeusermenus(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
807 self.filemenu = m = Menu(self.menubar, "File")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
808 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
809 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
810 self.optionsmenu = mm = SubMenu(m, "Options")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
811 self.opt1 = CheckItem(mm, "Arguments")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
812 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
813 self.opt3 = CheckItem(mm, "Complaints")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
814 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
815 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
816
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 def save(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
818 print "Save"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
819
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
820 def quit(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
821 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
822
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
823
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
824 def test():
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
825 "Test program"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
826 app = TestApp()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
827 app.mainloop()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
828
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
829
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 if __name__ == '__main__':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
831 test()