annotate Mac/Lib/FrameWork.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 44edbe0f2174
children
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
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
8 from Carbon.AE import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
9 from Carbon.AppleEvents import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
10 from Carbon.Ctl import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
11 from Carbon.Controls import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
12 from Carbon.Dlg import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
13 from Carbon.Dialogs import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
14 from Carbon.Evt import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
15 from Carbon.Events import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
16 from Carbon.Menu import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
17 from Carbon.Menus import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
18 from Carbon.Qd import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
19 from Carbon.QuickDraw import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
20 #from Carbon.Res import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
21 #from Carbon.Resources import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
22 #from Carbon.Snd import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
23 #from Carbon.Sound import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
24 from Carbon.Win import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18962
diff changeset
25 from Carbon.Windows import *
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
26 import types
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 import EasyDialogs
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
30 try:
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
31 MyFrontWindow = FrontNonFloatingWindow
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
32 except NameError:
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
33 MyFrontWindow = FrontWindow
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
34
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 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
36 SCROLLBARWIDTH = 16 # Again, not a clue...
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
21329
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
38 # Trick to forestall a set of SIOUX menus being added to our menubar
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
39 SIOUX_APPLEMENU_ID=32000
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
40
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 # Map event 'what' field to strings
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 eventname = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 eventname[1] = 'mouseDown'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 eventname[2] = 'mouseUp'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 eventname[3] = 'keyDown'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 eventname[4] = 'keyUp'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 eventname[5] = 'autoKey'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 eventname[6] = 'updateEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 eventname[7] = 'diskEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 eventname[8] = 'activateEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 eventname[15] = 'osEvt'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 eventname[23] = 'kHighLevelEvent'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 # 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
56 partname = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 partname[0] = 'inDesk'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 partname[1] = 'inMenuBar'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 partname[2] = 'inSysWindow'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 partname[3] = 'inContent'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 partname[4] = 'inDrag'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 partname[5] = 'inGrow'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 partname[6] = 'inGoAway'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 partname[7] = 'inZoomIn'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 partname[8] = 'inZoomOut'
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
3533
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 # The useable portion of the screen
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
69 # ## but what happens with multiple screens? jvr
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
70 screenbounds = qd.screenBits.bounds
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
71 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
72 screenbounds[2]-4, screenbounds[3]-4
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
73
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
74 next_window_x = 16 # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
75 next_window_y = 44 # jvr
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
76
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
77 def windowbounds(width, height):
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
78 "Return sensible window bounds"
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
79 global next_window_x, next_window_y
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
80 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
81 if r > screenbounds[2]:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
82 next_window_x = 16
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
83 if b > screenbounds[3]:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
84 next_window_y = 44
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
85 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
86 r, b = next_window_x+width, next_window_y+height
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
87 next_window_x, next_window_y = next_window_x + 8, next_window_y + 20 # jvr
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
88 return l, t, r, b
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
4162
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
90 _watch = None
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
91 def setwatchcursor():
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
92 global _watch
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
93
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
94 if _watch == None:
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
95 _watch = GetCursor(4).data
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
96 SetCursor(_watch)
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
97
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
98 def setarrowcursor():
99250182c48a Added setwatchcursor() and setarrowcursor() functions
Jack Jansen <jack.jansen@cwi.nl>
parents: 3814
diff changeset
99 SetCursor(qd.arrow)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 class Application:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 "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
104
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
105 def __init__(self, nomenubar=0):
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
106 self._doing_asyncevents = 0
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
107 self.quitting = 0
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
108 self.needmenubarredraw = 0
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
109 self._windows = {}
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
110 if nomenubar:
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
111 self.menubar = None
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
112 else:
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
113 self.makemenubar()
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
114
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
115 def __del__(self):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
116 if self._doing_asyncevents:
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
117 self._doing_asyncevents = 0
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
118 MacOS.SetEventHandler()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 def makemenubar(self):
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
121 self.menubar = MenuBar(self)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 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
123 self.makeusermenus()
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
124
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
125 def makeusermenus(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
126 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
127 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
128
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
129 def _quit(self, *args):
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
130 self.quitting = 1
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
131
4819
9bda38c67f4e Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents: 4335
diff changeset
132 def cleanup(self):
9bda38c67f4e Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents: 4335
diff changeset
133 for w in self._windows.values():
9bda38c67f4e Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents: 4335
diff changeset
134 w.do_close()
9bda38c67f4e Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents: 4335
diff changeset
135 return self._windows == {}
9bda38c67f4e Added Application.cleanup method which asks all windows to close
Jack Jansen <jack.jansen@cwi.nl>
parents: 4335
diff changeset
136
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
137 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
138 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
139
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
140 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
141 del self._windows[wid]
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 def getabouttext(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 return "About %s..." % self.__class__.__name__
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 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
147 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
148
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 # 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
150 # 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
151 # 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
152 # event type.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 # 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
154 # events.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
15195
3743a6dbc4a7 Use MacOS.KeepConsole to always exit if the program calls FrameWork._quit(). Overridable with a class variable keepconsole.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11949
diff changeset
156 schedparams = (0, 0) # By default disable Python's event handling
17016
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
157 default_wait = None # By default we wait GetCaretTime in WaitNextEvent
15195
3743a6dbc4a7 Use MacOS.KeepConsole to always exit if the program calls FrameWork._quit(). Overridable with a class variable keepconsole.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11949
diff changeset
158
17016
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
159 def mainloop(self, mask = everyEvent, wait = None):
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
160 self.quitting = 0
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
161 if hasattr(MacOS, 'SchedParams'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
162 saveparams = apply(MacOS.SchedParams, self.schedparams)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 try:
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
164 while not self.quitting:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 self.do1event(mask, wait)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 except (Application, SystemExit):
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
168 # Note: the raising of "self" is old-fashioned idiom to
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
169 # exit the mainloop. Calling _quit() is better for new
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
170 # applications.
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 break
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 finally:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
173 if hasattr(MacOS, 'SchedParams'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
174 apply(MacOS.SchedParams, saveparams)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
176 def dopendingevents(self, mask = everyEvent):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
177 """dopendingevents - Handle all pending events"""
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
178 while self.do1event(mask, wait=0):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
179 pass
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
180
17016
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
181 def do1event(self, mask = everyEvent, wait = None):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
182 ok, event = self.getevent(mask, wait)
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
183 if IsDialogEvent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
184 if self.do_dialogevent(event):
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
185 return
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
186 if ok:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 self.dispatch(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
188 else:
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
189 self.idle(event)
3245
18b60d8d9e35 Added idle() method, called when no events are available.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3037
diff changeset
190
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
191 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
192 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
193
17016
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
194 def getevent(self, mask = everyEvent, wait = None):
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
195 if self.needmenubarredraw:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
196 DrawMenuBar()
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
197 self.needmenubarredraw = 0
17016
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
198 if wait is None:
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
199 wait = self.default_wait
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
200 if wait is None:
19c2f50e5395 Default waittime in the eventloop is now None. At low level it will then be set to GetCaretTime().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16599
diff changeset
201 wait = GetCaretTime()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 ok, event = WaitNextEvent(mask, wait)
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
203 return ok, event
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
204
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 def dispatch(self, event):
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
206 # The following appears to be double work (already done in do1event)
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
207 # but we need it for asynchronous event handling
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
208 if IsDialogEvent(event):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
209 if self.do_dialogevent(event):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
210 return
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 name = "do_" + eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 name = "do_%d" % what
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 handler = getattr(self, name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 except AttributeError:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 handler = self.do_unknownevent
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 handler(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
221
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
222 def asyncevents(self, onoff):
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
223 """asyncevents - Set asynchronous event handling on or off"""
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
224 if MacOS.runtimemodel == 'macho':
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
225 raise 'Unsupported in MachoPython'
5750
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
226 old = self._doing_asyncevents
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
227 if old:
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
228 MacOS.SetEventHandler()
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
229 apply(MacOS.SchedParams, self.schedparams)
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
230 if onoff:
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
231 MacOS.SetEventHandler(self.dispatch)
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
232 doint, dummymask, benice, howoften, bgyield = \
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
233 self.schedparams
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
234 MacOS.SchedParams(doint, everyEvent, benice,
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
235 howoften, bgyield)
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
236 self._doing_asyncevents = onoff
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
237 return old
5a7429ac90c8 Added dopendingevents call
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
238
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
239 def do_dialogevent(self, event):
16599
260f033ae7df DialogWindows now have a self.dlg in addition to self.wid.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16346
diff changeset
240 gotone, dlg, item = DialogSelect(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
241 if gotone:
16599
260f033ae7df DialogWindows now have a self.dlg in addition to self.wid.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16346
diff changeset
242 window = dlg.GetDialogWindow()
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
243 if self._windows.has_key(window):
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
244 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
245 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
246 print 'Dialog event for unknown dialog'
3037
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
247 return 1
f8abc037b94f Fixed dialog-window event handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 2998
diff changeset
248 return 0
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 def do_mouseDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 (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
252 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
253
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
254 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
255 # 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
256 #
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 if partname.has_key(partcode):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 name = "do_" + partname[partcode]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 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
261
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
262 if wid == None:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
263 # 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
264 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
265 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
266 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
267 # 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
268 # else's window
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
269 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
270 MacOS.HandleEvent(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
271 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
272 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
273 # 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
274 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
275 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
276 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
277 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
278 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
279 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
280 # 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
281 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
282 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
283
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 def do_inSysWindow(self, partcode, window, event):
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
285 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
286 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
287
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 def do_inDesk(self, partcode, window, event):
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
289 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
290 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
291
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 def do_inMenuBar(self, partcode, window, event):
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
293 if not self.menubar:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
294 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
295 MacOS.HandleEvent(event)
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
296 return
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 result = MenuSelect(where)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 id = (result>>16) & 0xffff # Hi word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 item = result & 0xffff # Lo word
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 self.do_rawmenu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 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
304 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 self.do_menu(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 finally:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 HiliteMenu(0)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
308
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 def do_menu(self, id, item, window, event):
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
310 if hasattr(MacOS, 'OutputSeen'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
311 MacOS.OutputSeen()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 self.menubar.dispatch(id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
313
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
314
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 def do_unknownpartcode(self, partcode, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 (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
317 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
318 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
319 if DEBUG: print "\tEvent:", self.printevent(event)
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
320 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
321 MacOS.HandleEvent(event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
322
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
323 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
324 if DEBUG: print 'Unknown window:', window
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
325 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
326 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
327
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 def do_keyDown(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
330
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 def do_autoKey(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 if not event[-1] & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 self.do_key(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
334
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 def do_key(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 c = chr(message & charCodeMask)
11576
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
338 if self.menubar:
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
339 result = MenuEvent(event)
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
340 id = (result>>16) & 0xffff # Hi word
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
341 item = result & 0xffff # Lo word
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
342 if id:
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
343 self.do_rawmenu(id, item, None, event)
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
344 return
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
345 # Otherwise we fall-through
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 if modifiers & cmdKey:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 if c == '.':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 else:
4312
937f69fd43fe - Use a flag (self.quitting) as preferred method of exiting mainloop
Jack Jansen <jack.jansen@cwi.nl>
parents: 4162
diff changeset
350 if not self.menubar:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
351 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
352 MacOS.HandleEvent(event)
11576
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
353 return
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 else:
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
355 # See whether the front window wants it
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
356 w = MyFrontWindow()
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
357 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
358 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
359 try:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
360 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
361 except AttributeError:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
362 do_char = self.do_char
3296
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
363 do_char(c, event)
0d6b60b74838 Minor bugfix in keyboard input handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 3253
diff changeset
364 # 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
365
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 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
367 if DEBUG: print "Character", `c`
2632
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 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
370 (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
371 wid = WhichWindow(message)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
372 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
373 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
374 window.do_rawupdate(wid, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 else:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
376 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
377 MacOS.HandleEvent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
378
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
379 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
380 (what, message, when, where, modifiers) = event
9962
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
381 wid = WhichWindow(message)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
382 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
383 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
384 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
385 else:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
386 if hasattr(MacOS, 'HandleEvent'):
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
387 MacOS.HandleEvent(event)
9962
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
388
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
389 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
390 (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
391 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
392 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
393 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
394 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
395 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
396 print 'unknown osEvt:',
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
397 self.printevent(event)
9962
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
398
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
399 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
400 (what, message, when, where, modifiers) = event
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
401 wid = MyFrontWindow()
9962
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
402 if wid and self._windows.has_key(wid):
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
403 window = self._windows[wid]
11573
c5abc81dd1ee Fixed buglet in Application.do_suspendresume(), it took the wrong flag to determine suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 11566
diff changeset
404 window.do_activate(message & 1, event)
9962
894960fa90bc cleaned up ugly hack related to activate events and suspend/resume -- jvr
Just van Rossum <just@lettererror.com>
parents: 9373
diff changeset
405
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 def do_kHighLevelEvent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 (what, message, when, where, modifiers) = event
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
408 if DEBUG:
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
409 print "High Level Event:",
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
410 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 try:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 AEProcessAppleEvent(event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 except:
21383
abcd2f52f316 Don't barf when an AppleEvent was not handled. It's ok to ignore.
Just van Rossum <just@letterror.com>
parents: 21329
diff changeset
414 pass
abcd2f52f316 Don't barf when an AppleEvent was not handled. It's ok to ignore.
Just van Rossum <just@letterror.com>
parents: 21329
diff changeset
415 #print "AEProcessAppleEvent error:"
abcd2f52f316 Don't barf when an AppleEvent was not handled. It's ok to ignore.
Just van Rossum <just@letterror.com>
parents: 21329
diff changeset
416 #traceback.print_exc()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
417
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 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
419 if DEBUG:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
420 print "Unhandled event:",
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
421 self.printevent(event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
422
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 def printevent(self, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 (what, message, when, where, modifiers) = event
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 nicewhat = `what`
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 if eventname.has_key(what):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 nicewhat = eventname[what]
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 print nicewhat,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 if what == kHighLevelEvent:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 h, v = where
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 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
432 else:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 print hex(message), hex(when), where,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 print hex(modifiers)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
435
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 class MenuBar:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 """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
439
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 Interface:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
441
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 - (constructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 - (destructor)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 - addmenu
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 - addpopup (normally used internally)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 - dispatch (called from Application)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
448
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 nextid = 1 # Necessarily a class variable
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 def getnextid(self):
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
452 id = MenuBar.nextid
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
453 MenuBar.nextid = id+1
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 return id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
455
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
456 def __init__(self, parent=None):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
457 self.parent = parent
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 ClearMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 self.bar = GetMenuBar()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 self.menus = {}
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
461
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
462 # XXX necessary?
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
463 def close(self):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
464 self.parent = None
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
465 self.bar = None
7429
83e7759e7297 Break circular reference on menus upon cleanup
Jack Jansen <jack.jansen@cwi.nl>
parents: 5750
diff changeset
466 self.menus = None
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
467
21329
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
468 def addmenu(self, title, after = 0, id=None):
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
469 if id == None:
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
470 id = self.getnextid()
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
471 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
472 m = NewMenu(id, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 m.InsertMenu(after)
8226
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
474 if after >= 0:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
475 if self.parent:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
476 self.parent.needmenubarredraw = 1
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
477 else:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
478 DrawMenuBar()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 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
480
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
481 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
482 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
483 DeleteMenu(id)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
484
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 def addpopup(self, title = ''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 return self.addmenu(title, -1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
487
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
488 # Useless:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
489 # def install(self):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
490 # if not self.bar: return
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
491 # SetMenuBar(self.bar)
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
492 # if self.parent:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
493 # self.parent.needmenubarredraw = 1
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
494 # else:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
495 # DrawMenuBar()
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
496
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
497 def fixmenudimstate(self):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
498 for m in self.menus.keys():
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
499 menu = self.menus[m]
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
500 if menu.__class__ == FrameWork.AppleMenu:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
501 continue
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
502 for i in range(len(menu.items)):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
503 label, shortcut, callback, kind = menu.items[i]
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
504 if type(callback) == types.StringType:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
505 wid = MyFrontWindow()
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
506 if wid and self.parent._windows.has_key(wid):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
507 window = self.parent._windows[wid]
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
508 if hasattr(window, "domenu_" + callback):
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
509 menu.menu.EnableMenuItem(i + 1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
510 elif hasattr(self.parent, "domenu_" + callback):
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
511 menu.menu.EnableMenuItem(i + 1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
512 else:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
513 menu.menu.DisableMenuItem(i + 1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
514 elif hasattr(self.parent, "domenu_" + callback):
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
515 menu.menu.EnableMenuItem(i + 1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
516 else:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
517 menu.menu.DisableMenuItem(i + 1)
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
518 elif callback:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
519 pass
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
520
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
522 if self.menus.has_key(id):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 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
524 else:
2991
448edc923cad Various fixes: missing imports, missing calls to
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
525 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
526 (id, item, window, event)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
527
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
528
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
529 # 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
530
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 class Menu:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
532 "One menu."
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
533
21329
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
534 def __init__(self, bar, title, after=0, id=None):
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 self.bar = bar
21329
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
536 self.id, self.menu = self.bar.addmenu(title, after, id)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 bar.menus[self.id] = self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 self.items = []
9373
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
539 self._parent = None
3449
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
540
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
541 def delete(self):
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
542 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
543 del self.bar.menus[self.id]
11949
5e48d83c0fce Fixed multi-arg appends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11576
diff changeset
544 self.menu.DisposeMenu()
3449
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
545 del self.bar
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
546 del self.items
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
547 del self.menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
548 del self.id
9373
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
549 del self._parent
8668
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
550
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
551 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
552 self.menu.AppendMenu('x') # add a dummy string
11949
5e48d83c0fce Fixed multi-arg appends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11576
diff changeset
553 self.items.append((label, shortcut, callback, kind))
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 item = len(self.items)
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
555 self.menu.SetMenuItemText(item, label) # set the actual text
11566
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
556 if shortcut and type(shortcut) == type(()):
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
557 modifiers, char = shortcut[:2]
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
558 self.menu.SetItemCmd(item, ord(char))
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
559 self.menu.SetMenuItemModifiers(item, modifiers)
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
560 if len(shortcut) > 2:
11576
f57ff4289fc6 Fixed menu glyph stuff.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11573
diff changeset
561 self.menu.SetMenuItemKeyGlyph(item, shortcut[2])
11566
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
562 elif shortcut:
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 self.menu.SetItemCmd(item, ord(shortcut))
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 return item
8668
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
565
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
566 def delitem(self, item):
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
567 if item != len(self.items):
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
568 raise 'Can only delete last item of a menu'
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
569 self.menu.DeleteMenuItem(item)
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
570 del self.items[item-1]
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
571
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 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
573 return self.additem(label, shortcut, callback, 'check')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
574
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 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
576 return self.additem(label, shortcut, callback, 'radio')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
577
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
578 def addseparator(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
579 self.menu.AppendMenu('(-')
11949
5e48d83c0fce Fixed multi-arg appends.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11576
diff changeset
580 self.items.append(('', None, None, 'separator'))
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
581
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 def addsubmenu(self, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
583 sub = Menu(self.bar, title, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
584 item = self.additem(label, '\x1B', None, 'submenu')
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
585 self.menu.SetItemMark(item, sub.id)
9373
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
586 sub._parent = self
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
587 sub._parent_item = item
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
588 return sub
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
589
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 def dispatch(self, id, item, window, event):
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
591 title, shortcut, callback, mtype = self.items[item-1]
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
592 if callback:
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
593 if not self.bar.parent or type(callback) <> types.StringType:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
594 menuhandler = callback
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
595 else:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
596 # callback is string
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
597 wid = MyFrontWindow()
4335
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
598 if wid and self.bar.parent._windows.has_key(wid):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
599 window = self.bar.parent._windows[wid]
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
600 if hasattr(window, "domenu_" + callback):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
601 menuhandler = getattr(window, "domenu_" + callback)
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
602 elif hasattr(self.bar.parent, "domenu_" + callback):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
603 menuhandler = getattr(self.bar.parent, "domenu_" + callback)
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
604 else:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
605 # nothing we can do. we shouldn't have come this far
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
606 # since the menu item should have been disabled...
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
607 return
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
608 elif hasattr(self.bar.parent, "domenu_" + callback):
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
609 menuhandler = getattr(self.bar.parent, "domenu_" + callback)
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
610 else:
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
611 # nothing we can do. we shouldn't have come this far
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
612 # since the menu item should have been disabled...
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
613 return
366d72f12794 Menu callbacks can be strings, in which case they will be looked up in
Jack Jansen <jack.jansen@cwi.nl>
parents: 4312
diff changeset
614 menuhandler(id, item, window, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
615
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
616 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
617 if onoff:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
618 self.menu.EnableMenuItem(0)
9373
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
619 if self._parent:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
620 self._parent.menu.EnableMenuItem(self._parent_item)
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
621 else:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
622 self.menu.DisableMenuItem(0)
9373
229f73f2c878 For submenus remember the parent and parent index, so we can grey out our
Jack Jansen <jack.jansen@cwi.nl>
parents: 8668
diff changeset
623 if self._parent:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
624 self._parent.menu.DisableMenuItem(self._parent_item)
8668
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
625 if self.bar and self.bar.parent:
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
626 self.bar.parent.needmenubarredraw = 1
8226
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
627
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
628 class PopupMenu(Menu):
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
629 def __init__(self, bar):
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
630 Menu.__init__(self, bar, '(popup)', -1)
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
631
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
632 def popup(self, x, y, event, default=1, window=None):
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
633 # NOTE that x and y are global coordinates, and they should probably
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
634 # be topleft of the button the user clicked (not mouse-coordinates),
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
635 # so the popup nicely overlaps.
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
636 reply = self.menu.PopUpMenuSelect(x, y, default)
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
637 if not reply:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
638 return
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
639 id = (reply & 0xffff0000) >> 16
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
640 item = reply & 0xffff
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
641 if not window:
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
642 wid = MyFrontWindow()
8226
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
643 try:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
644 window = self.bar.parent._windows[wid]
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
645 except:
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
646 pass # If we can't find the window we pass None
69f2e05cc378 Added a PopupMenu class.
Jack Jansen <jack.jansen@cwi.nl>
parents: 7429
diff changeset
647 self.dispatch(id, item, window, event)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
648
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
649 class MenuItem:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
650 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
651 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
652 self.menu = menu
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
653
8668
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
654 def delete(self):
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
655 self.menu.delitem(self.item)
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
656 del self.menu
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
657 del self.item
82811c6cb58f Added a delete() method to menu entries. Only the last entry of a menu
Jack Jansen <jack.jansen@cwi.nl>
parents: 8436
diff changeset
658
3449
c3e51eb1c14f Added checkmenu() method (to checkmark an entry) and delete() method
Jack Jansen <jack.jansen@cwi.nl>
parents: 3310
diff changeset
659 def check(self, onoff):
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
660 self.menu.menu.CheckMenuItem(self.item, onoff)
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
661
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
662 def enable(self, onoff):
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
663 if onoff:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
664 self.menu.menu.EnableMenuItem(self.item)
3510
a1c0c2a38883 Added enable(onoff) method to menus and menu items
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
665 else:
16336
2d8e02902d67 Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16158
diff changeset
666 self.menu.menu.DisableMenuItem(self.item)
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
667
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
668 def settext(self, text):
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
669 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
670
3540
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
671 def setstyle(self, style):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
672 self.menu.menu.SetItemStyle(self.item, style)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
673
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
674 def seticon(self, icon):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
675 self.menu.menu.SetItemIcon(self.item, icon)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
676
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
677 def setcmd(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
678 self.menu.menu.SetItemCmd(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
679
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
680 def setmark(self, cmd):
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
681 self.menu.menu.SetItemMark(self.item, cmd)
2b166b220c11 Added MenuItem methods setstyle(), seticon(), setmark()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3533
diff changeset
682
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
683
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
684 class RadioItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
685 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
686 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
687
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 class CheckItem(MenuItem):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
689 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
690 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
691
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 def Separator(menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
693 menu.addseparator()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
694
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
695 def SubMenu(menu, label, title=''):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 return menu.addsubmenu(label, title)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
697
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
698
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
699 class AppleMenu(Menu):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
700
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 def __init__(self, bar, abouttext="About me...", aboutcallback=None):
21329
848f6988829f The new menu initialization code would also add the SIOUX menus if a (frozen) Python program had installed its own menubar previously. We now guard against this, with a bit of a hack: FrameWork uses the same Menu ID as Sioux, and the init code checks that the text in the menu is "About SIOUX" before replacing it.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
702 Menu.__init__(self, bar, "\024", id=SIOUX_APPLEMENU_ID)
16346
90ede5165d1f Use FSpCreateResFile() in stead of CreateResFile().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16336
diff changeset
703 if MacOS.runtimemodel == 'ppc':
17050
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
704 self.additem(abouttext, None, aboutcallback)
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
705 self.addseparator()
16346
90ede5165d1f Use FSpCreateResFile() in stead of CreateResFile().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16336
diff changeset
706 self.menu.AppendResMenu('DRVR')
17050
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
707 else:
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
708 # Additem()'s tricks do not work for "apple" menu under Carbon
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
709 self.menu.InsertMenuItem(abouttext, 0)
7a4175e10626 Handle the apple menu differently under Carbon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17016
diff changeset
710 self.items.append((abouttext, None, aboutcallback, None))
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
711
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
712 def dispatch(self, id, item, window, event):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
713 if item == 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 Menu.dispatch(self, id, item, window, event)
16346
90ede5165d1f Use FSpCreateResFile() in stead of CreateResFile().
Jack Jansen <jack.jansen@cwi.nl>
parents: 16336
diff changeset
715 elif MacOS.runtimemodel == 'ppc':
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
716 name = self.menu.GetMenuItemText(item)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 OpenDeskAcc(name)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
718
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
719 class Window:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
720 """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
721
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
722 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
723 self.wid = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
724 self.parent = parent
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
725
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
726 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
727 if resid <> None:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
728 self.wid = GetNewWindow(resid, -1)
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
729 else:
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
730 self.wid = NewWindow(bounds, self.__class__.__name__, 1,
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
731 8, -1, 1, 0) # changed to proc id 8 to include zoom box. jvr
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
732 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
733
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
734 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
735 """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
736 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
737
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
738 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
739 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
740
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
741 def do_postclose(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
742 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
743 self.parent = None
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
744 self.wid = None
3310
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
745
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
746 def SetPort(self):
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
747 # Convinience method
604b1fc26d63 Various fixes/enhancements, thanks to Ivan and Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3296
diff changeset
748 SetPort(self.wid)
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
749
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
750 def GetWindow(self):
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
751 return self.wid
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
752
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
753 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
754 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
755 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
756
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
757 draglimit = screenbounds
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
758
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
759 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
760 where = event[3]
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
761 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
762 self.close()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
763
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
764 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
765 (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
766 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
767 window.ZoomWindow(partcode, 1)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
768 rect = window.GetWindowUserState() # so that zoom really works... jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
769 self.do_postresize(rect[2] - rect[0], rect[3] - rect[1], window) # jvr
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
770
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
771 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
772 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
773 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
774
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
775 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
776 SetPort(window) # !!!
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
777 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
778
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
779 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
780 (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
781 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
782 if result:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
783 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
784 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
785 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
786
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
787 growlimit = (50, 50, screenbounds[2] - screenbounds[0], screenbounds[3] - screenbounds[1]) # jvr
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
788
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
789 def do_resize(self, width, height, window):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
790 l, t, r, b = self.wid.GetWindowPort().portRect # jvr, forGrowIcon
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
791 self.SetPort() # jvr
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
792 self.wid.InvalWindowRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
793 window.SizeWindow(width, height, 1) # changed updateFlag to true jvr
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
794 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
795
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
796 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
797 SetPort(window)
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
798 self.wid.InvalWindowRect(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
799
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
800 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
801 #
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
802 # 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
803 # the activate event.
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
804 #
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
805 if MyFrontWindow() <> window:
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
806 window.SelectWindow()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
807 return
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
808 # 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
809 (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
810 SetPort(window)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
811 local = GlobalToLocal(where)
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
812 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
813
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
814 def do_contentclick(self, local, modifiers, event):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
815 if DEBUG:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
816 print 'Click in contents at %s, modifiers %s'%(local, modifiers)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
817
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
818 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
819 if DEBUG: print "raw update for", window
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
820 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
821 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
822 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
823 window.EndUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
824
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
825 def do_update(self, window, event):
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
826 if DEBUG:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
827 import time
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
828 for i in range(8):
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
829 time.sleep(0.1)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
830 InvertRgn(window.GetWindowPort().visRgn)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
831 FillRgn(window.GetWindowPort().visRgn, qd.gray)
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
832 else:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
833 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
834
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
835 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
836 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
837
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
838 class ControlsWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
839
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
840 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
841 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
842 SetPort(window)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
843 window.BeginUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
844 self.do_update(window, event)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
845 #DrawControls(window) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
846 UpdateControls(window, window.GetWindowPort().visRgn) # jvr
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
847 window.DrawGrowIcon()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
848 window.EndUpdate()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
849
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
850 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
851 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
852
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
853 def do_inContent(self, partcode, window, event):
22018
44edbe0f2174 Backport of 1.47, 1.48 and 1.49:
Jack Jansen <jack.jansen@cwi.nl>
parents: 21383
diff changeset
854 if MyFrontWindow() <> window:
3533
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
855 window.SelectWindow()
e67adc8b2f16 - Confine window moves to screen boundaries
Jack Jansen <jack.jansen@cwi.nl>
parents: 3527
diff changeset
856 return
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
857 (what, message, when, where, modifiers) = event
3253
f89cdda7405a Added 2 missing SetPort calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 3245
diff changeset
858 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
859 local = GlobalToLocal(where)
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
860 pcode, control = FindControl(local, window)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
861 if pcode and control:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
862 self.do_rawcontrolhit(window, control, pcode, local, event)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
863 else:
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
864 if DEBUG: print "FindControl(%s, %s) -> (%s, %s)" % \
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
865 (local, window, pcode, control)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
866 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
867
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
868 def do_rawcontrolhit(self, window, control, pcode, local, event):
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
869 pcode = control.TrackControl(local)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
870 if pcode:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
871 self.do_controlhit(window, control, pcode, event)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
872
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
873 class ScrolledWindow(ControlsWindow):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
874 def __init__(self, parent):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
875 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
876 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
877 self.activated = 1
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
878 ControlsWindow.__init__(self, parent)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
879
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
880 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
881 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
882 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
883 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
884 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
885 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
886 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
887 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
888 if wantx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
889 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
890 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
891 if not self.barx_enabled: self.barx.HiliteControl(255)
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
892 ## self.wid.InvalWindowRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
893 if wanty:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
894 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
895 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
896 if not self.bary_enabled: self.bary.HiliteControl(255)
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
897 ## self.wid.InvalWindowRect(rect)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
898
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
899 def do_postclose(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
900 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
901 ControlsWindow.do_postclose(self)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
902
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
903 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
904 self.activated = onoff
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
905 if onoff:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
906 if self.barx and self.barx_enabled:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
907 self.barx.ShowControl() # jvr
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
908 if self.bary and self.bary_enabled:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
909 self.bary.ShowControl() # jvr
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
910 else:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
911 if self.barx:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
912 self.barx.HideControl() # jvr; An inactive window should have *hidden*
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
913 # scrollbars, not just dimmed (no matter what
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
914 # BBEdit does... look at the Finder)
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
915 if self.bary:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
916 self.bary.HideControl() # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
917 self.wid.DrawGrowIcon() # jvr
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
918
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
919 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
920 l, t, r, b = self.wid.GetWindowPort().portRect
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
921 self.SetPort()
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
922 if self.barx:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
923 self.barx.HideControl() # jvr
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
924 self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1))
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
925 self.barx.SizeControl((r-l)-(SCROLLBARWIDTH-3), SCROLLBARWIDTH) # jvr
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
926 if self.bary:
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
927 self.bary.HideControl() # jvr
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
928 self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1)
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
929 self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-3)) # jvr
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
930 if self.barx:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
931 self.barx.ShowControl() # jvr
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
932 self.wid.ValidWindowRect((l, b - SCROLLBARWIDTH + 1, r - SCROLLBARWIDTH + 2, b)) # jvr
3814
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
933 if self.bary:
31e100d9d929 Mods by Just:
Jack Jansen <jack.jansen@cwi.nl>
parents: 3540
diff changeset
934 self.bary.ShowControl() # jvr
16158
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
935 self.wid.ValidWindowRect((r - SCROLLBARWIDTH + 1, t, r, b - SCROLLBARWIDTH + 2)) # jvr
6396cc6b1f7a Sigh... First test before committing. InvalWindowRect and friends are window object methods. Fixed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16156
diff changeset
936 self.wid.InvalWindowRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr, growicon
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
937
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
938
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
939 def do_rawcontrolhit(self, window, control, pcode, local, event):
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
940 if control == self.barx:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
941 which = 'x'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
942 elif control == self.bary:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
943 which = 'y'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
944 else:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
945 return 0
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
946 if pcode in (inUpButton, inDownButton, inPageUp, inPageDown):
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
947 # We do the work for the buttons and grey area in the tracker
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
948 dummy = control.TrackControl(local, self.do_controltrack)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
949 else:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
950 # but the thumb is handled here
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
951 pcode = control.TrackControl(local)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
952 if pcode == inThumb:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
953 value = control.GetControlValue()
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
954 print 'setbars', which, value #DBG
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
955 self.scrollbar_callback(which, 'set', value)
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
956 self.updatescrollbars()
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
957 else:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
958 print 'funny part', pcode #DBG
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
959 return 1
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
960
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
961 def do_controltrack(self, control, pcode):
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
962 if control == self.barx:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
963 which = 'x'
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
964 elif control == self.bary:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
965 which = 'y'
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
966 else:
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
967 return
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
968
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
969 if pcode == inUpButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
970 what = '-'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
971 elif pcode == inDownButton:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
972 what = '+'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
973 elif pcode == inPageUp:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
974 what = '--'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
975 elif pcode == inPageDown:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
976 what = '++'
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
977 else:
8436
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
978 return
a9a788c74d6e For ControlWindow there is a new method do_rawcontrolhit(), which gets
Jack Jansen <jack.jansen@cwi.nl>
parents: 8226
diff changeset
979 self.scrollbar_callback(which, what, None)
3514
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
980 self.updatescrollbars()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
981
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
982 def updatescrollbars(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
983 SetPort(self.wid)
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
984 vx, vy = self.getscrollbarvalues()
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
985 if self.barx:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
986 if vx == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
987 self.barx.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
988 self.barx_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
989 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
990 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
991 self.barx_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
992 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
993 self.barx.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
994 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
995 if self.bary:
3527
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
996 if vy == None:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
997 self.bary.HiliteControl(255)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
998 self.bary_enabled = 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
999 else:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1000 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
1001 self.bary_enabled = 1
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1002 if self.activated:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1003 self.bary.HiliteControl(0)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1004 self.bary.SetControlValue(vy)
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1005
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1006 # 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
1007 # 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
1008 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
1009 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
1010 return None
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1011 if curmin <= absmin:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1012 return 0
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1013 if curmax >= absmax:
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1014 return 32767
510dbfa8c599 Fixed ScrolledWindow to disable scrollbars if everything is visible.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3514
diff changeset
1015 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
1016 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
1017
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1018 # To be overridden:
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1019
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1020 def getscrollbarvalues(self):
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1021 return 0, 0
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1022
05af29e8df0e Added ScrolledWindow (a window with one or two scrollbars)
Jack Jansen <jack.jansen@cwi.nl>
parents: 3510
diff changeset
1023 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
1024 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
1025
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1026 class DialogWindow(Window):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1027 """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
1028
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1029 def open(self, resid):
16599
260f033ae7df DialogWindows now have a self.dlg in addition to self.wid.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16346
diff changeset
1030 self.dlg = GetNewDialog(resid, -1)
260f033ae7df DialogWindows now have a self.dlg in addition to self.wid.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16346
diff changeset
1031 self.wid = self.dlg.GetDialogWindow()
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1032 self.do_postopen()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1033
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1034 def close(self):
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1035 self.do_postclose()
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1036
18962
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17050
diff changeset
1037 def do_postclose(self):
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17050
diff changeset
1038 self.dlg = None
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17050
diff changeset
1039 Window.do_postclose(self)
d7590122f9a2 Merging appropriate 2.1.1 fixes back into the main trunk.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17050
diff changeset
1040
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1041 def do_itemhit(self, item, event):
16599
260f033ae7df DialogWindows now have a self.dlg in addition to self.wid.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16346
diff changeset
1042 print 'Dialog %s, item %d hit'%(self.dlg, item)
2998
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1043
9bca94a36a08 Made separate window class (and subclasses for special windows like
Jack Jansen <jack.jansen@cwi.nl>
parents: 2991
diff changeset
1044 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
1045 pass
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1046
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1047 def ostypecode(x):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1048 "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
1049 s = ''
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1050 for i in range(4):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1051 x, c = divmod(x, 256)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1052 s = chr(c) + s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1053 return s
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1054
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1055
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1056 class TestApp(Application):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1057
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1058 "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
1059
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1060 def makeusermenus(self):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1061 self.filemenu = m = Menu(self.menubar, "File")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1062 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
1063 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1064 self.optionsmenu = mm = SubMenu(m, "Options")
11566
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
1065 self.opt1 = CheckItem(mm, "Arguments", "A")
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
1066 self.opt2 = CheckItem(mm, "Being hit on the head lessons", (kMenuOptionModifier, "A"))
e2660afdc381 If a menu shortcut is a tuple in stead of a char it is a tuple (modifierkeys, char [, glyph]).
Jack Jansen <jack.jansen@cwi.nl>
parents: 11520
diff changeset
1067 self.opt3 = CheckItem(mm, "Complaints", (kMenuOptionModifier|kMenuNoCommandModifier, "A"))
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1068 Separator(m)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1069 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
1070
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1071 def save(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1072 print "Save"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1073
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1074 def quit(self, *args):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1075 raise self
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1076
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1077
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1078 def test():
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1079 "Test program"
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1080 app = TestApp()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1081 app.mainloop()
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1082
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1083
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1084 if __name__ == '__main__':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1085 test()