annotate Lib/plat-mac/FrameWork.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents e29a2e03e739
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 "A sort of application framework for the Mac"
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 DEBUG=0
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46197
diff changeset
5 from warnings import warnpy3k
47958
e7a6a4515ab0 fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents: 46967
diff changeset
6 warnpy3k("In 3.x, the FrameWork module is removed.", stacklevel=2)
46967
6df0394abbf1 Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents: 46197
diff changeset
7
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 import MacOS
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 import traceback
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 from Carbon.AE import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 from Carbon.AppleEvents import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 from Carbon.Ctl import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 from Carbon.Controls import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 from Carbon.Dlg import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 from Carbon.Dialogs import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 from Carbon.Evt import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 from Carbon.Events import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 from Carbon.Help import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 from Carbon.Menu import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 from Carbon.Menus import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 from Carbon.Qd import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 from Carbon.QuickDraw import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 #from Carbon.Res import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 #from Carbon.Resources import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 #from Carbon.Snd import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 #from Carbon.Sound import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 from Carbon.Win import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 from Carbon.Windows import *
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 import types
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 import EasyDialogs
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 try:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
35 MyFrontWindow = FrontNonFloatingWindow
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 except NameError:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
37 MyFrontWindow = FrontWindow
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
39 kHighLevelEvent = 23 # Don't know what header file this should come from
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
40 SCROLLBARWIDTH = 16 # Again, not a clue...
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 # Trick to forestall a set of SIOUX menus being added to our menubar
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 SIOUX_APPLEMENU_ID=32000
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 # Map event 'what' field to strings
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 eventname = {}
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 eventname[1] = 'mouseDown'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 eventname[2] = 'mouseUp'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 eventname[3] = 'keyDown'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 eventname[4] = 'keyUp'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 eventname[5] = 'autoKey'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 eventname[6] = 'updateEvt'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 eventname[7] = 'diskEvt'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 eventname[8] = 'activateEvt'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 eventname[15] = 'osEvt'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 eventname[23] = 'kHighLevelEvent'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 # Map part codes returned by WhichWindow() to strings
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60 partname = {}
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 partname[0] = 'inDesk'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62 partname[1] = 'inMenuBar'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 partname[2] = 'inSysWindow'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 partname[3] = 'inContent'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 partname[4] = 'inDrag'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 partname[5] = 'inGrow'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 partname[6] = 'inGoAway'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 partname[7] = 'inZoomIn'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 partname[8] = 'inZoomOut'
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 #
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72 # The useable portion of the screen
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
73 # ## but what happens with multiple screens? jvr
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 screenbounds = GetQDGlobalsScreenBits().bounds
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
76 screenbounds[2]-4, screenbounds[3]-4
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
77
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
78 next_window_x = 16 # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
79 next_window_y = 44 # jvr
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 def windowbounds(width, height):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
82 "Return sensible window bounds"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
83 global next_window_x, next_window_y
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
84 r, b = next_window_x+width, next_window_y+height
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
85 if r > screenbounds[2]:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
86 next_window_x = 16
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
87 if b > screenbounds[3]:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
88 next_window_y = 44
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
89 l, t = next_window_x, next_window_y
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
90 r, b = next_window_x+width, next_window_y+height
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
91 next_window_x, next_window_y = next_window_x + 8, next_window_y + 20 # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
92 return l, t, r, b
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 _watch = None
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 def setwatchcursor():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
96 global _watch
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
97
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
98 if _watch is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
99 _watch = GetCursor(4).data
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
100 SetCursor(_watch)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
101
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 def setarrowcursor():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
103 SetCursor(GetQDGlobalsArrow())
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 class Application:
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
106
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
107 "Application framework -- your application should be a derived class"
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
108
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
109 def __init__(self, nomenubar=0):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
110 self._doing_asyncevents = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
111 self.quitting = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
112 self.needmenubarredraw = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
113 self._windows = {}
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
114 self._helpmenu = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
115 if nomenubar:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
116 self.menubar = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
117 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
118 self.makemenubar()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
119
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
120 def __del__(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
121 if self._doing_asyncevents:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
122 self._doing_asyncevents = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
123 MacOS.SetEventHandler()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
124
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
125 def makemenubar(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
126 self.menubar = MenuBar(self)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
127 AppleMenu(self.menubar, self.getabouttext(), self.do_about)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
128 self.makeusermenus()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
129
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
130 def makeusermenus(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
131 self.filemenu = m = Menu(self.menubar, "File")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
132 self._quititem = MenuItem(m, "Quit", "Q", self._quit)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
133
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
134 def gethelpmenu(self):
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
135 if self._helpmenu is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
136 self._helpmenu = HelpMenu(self.menubar)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
137 return self._helpmenu
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
138
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
139 def _quit(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
140 self.quitting = 1
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
141
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
142 def cleanup(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
143 for w in self._windows.values():
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
144 w.do_close()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
145 return self._windows == {}
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
146
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
147 def appendwindow(self, wid, window):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
148 self._windows[wid] = window
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
149
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
150 def removewindow(self, wid):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
151 del self._windows[wid]
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
152
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
153 def getabouttext(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
154 return "About %s..." % self.__class__.__name__
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
155
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
156 def do_about(self, id, item, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
157 EasyDialogs.Message("Hello, world!" + "\015(%s)" % self.__class__.__name__)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
158
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
159 # The main event loop is broken up in several simple steps.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
160 # This is done so you can override each individual part,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
161 # if you have a need to do extra processing independent of the
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
162 # event type.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
163 # Normally, however, you'd just define handlers for individual
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
164 # events.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
165
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
166 schedparams = (0, 0) # By default disable Python's event handling
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
167 default_wait = None # By default we wait GetCaretTime in WaitNextEvent
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
168
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
169 def mainloop(self, mask = everyEvent, wait = None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
170 self.quitting = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
171 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
172 saveparams = MacOS.SchedParams(*self.schedparams)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
173 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
174 while not self.quitting:
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
175 try:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
176 self.do1event(mask, wait)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
177 except (Application, SystemExit):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
178 # Note: the raising of "self" is old-fashioned idiom to
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
179 # exit the mainloop. Calling _quit() is better for new
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
180 # applications.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
181 break
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
182 finally:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
183 if hasattr(MacOS, 'SchedParams'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
184 MacOS.SchedParams(*saveparams)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
186 def dopendingevents(self, mask = everyEvent):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
187 """dopendingevents - Handle all pending events"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
188 while self.do1event(mask, wait=0):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
189 pass
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
190
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
191 def do1event(self, mask = everyEvent, wait = None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
192 ok, event = self.getevent(mask, wait)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
193 if IsDialogEvent(event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
194 if self.do_dialogevent(event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
195 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
196 if ok:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
197 self.dispatch(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
198 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
199 self.idle(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
200
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
201 def idle(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
202 pass
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
203
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
204 def getevent(self, mask = everyEvent, wait = None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
205 if self.needmenubarredraw:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
206 DrawMenuBar()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
207 self.needmenubarredraw = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
208 if wait is None:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
209 wait = self.default_wait
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
210 if wait is None:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
211 wait = GetCaretTime()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
212 ok, event = WaitNextEvent(mask, wait)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
213 return ok, event
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
215 def dispatch(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
216 # The following appears to be double work (already done in do1event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
217 # but we need it for asynchronous event handling
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
218 if IsDialogEvent(event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
219 if self.do_dialogevent(event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
220 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
221 (what, message, when, where, modifiers) = event
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
222 if what in eventname:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
223 name = "do_" + eventname[what]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
224 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
225 name = "do_%d" % what
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
226 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
227 handler = getattr(self, name)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
228 except AttributeError:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
229 handler = self.do_unknownevent
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
230 handler(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
231
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
232 def asyncevents(self, onoff):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
233 """asyncevents - Set asynchronous event handling on or off"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
234 if MacOS.runtimemodel == 'macho':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
235 raise 'Unsupported in MachoPython'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
236 old = self._doing_asyncevents
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
237 if old:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
238 MacOS.SetEventHandler()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
239 MacOS.SchedParams(*self.schedparams)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
240 if onoff:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
241 MacOS.SetEventHandler(self.dispatch)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
242 doint, dummymask, benice, howoften, bgyield = \
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
243 self.schedparams
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
244 MacOS.SchedParams(doint, everyEvent, benice,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
245 howoften, bgyield)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
246 self._doing_asyncevents = onoff
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
247 return old
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
248
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
249 def do_dialogevent(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
250 gotone, dlg, item = DialogSelect(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
251 if gotone:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
252 window = dlg.GetDialogWindow()
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
253 if window in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
254 self._windows[window].do_itemhit(item, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
255 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
256 print 'Dialog event for unknown dialog'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
257 return 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
258 return 0
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
259
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
260 def do_mouseDown(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
261 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
262 partcode, wid = FindWindow(where)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
263
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
264 #
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
265 # Find the correct name.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
266 #
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
267 if partcode in partname:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
268 name = "do_" + partname[partcode]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
269 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
270 name = "do_%d" % partcode
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
271
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
272 if wid is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
273 # No window, or a non-python window
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
274 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
275 handler = getattr(self, name)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
276 except AttributeError:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
277 # Not menubar or something, so assume someone
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
278 # else's window
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
279 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
280 MacOS.HandleEvent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
281 return
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
282 elif wid in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
283 # It is a window. Hand off to correct window.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
284 window = self._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
285 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
286 handler = getattr(window, name)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
287 except AttributeError:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
288 handler = self.do_unknownpartcode
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
289 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
290 # It is a python-toolbox window, but not ours.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
291 handler = self.do_unknownwindow
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
292 handler(partcode, wid, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
293
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
294 def do_inSysWindow(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
295 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
296 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
297
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
298 def do_inDesk(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
299 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
300 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
301
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
302 def do_inMenuBar(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
303 if not self.menubar:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
304 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
305 MacOS.HandleEvent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
306 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
307 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
308 result = MenuSelect(where)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
309 id = (result>>16) & 0xffff # Hi word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
310 if id >= 0x8000:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
311 id = -65536 + id
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
312 item = result & 0xffff # Lo word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
313 self.do_rawmenu(id, item, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
314
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
315 def do_rawmenu(self, id, item, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
316 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
317 self.do_menu(id, item, window, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
318 finally:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
319 HiliteMenu(0)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
320
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
321 def do_menu(self, id, item, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
322 if hasattr(MacOS, 'OutputSeen'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
323 MacOS.OutputSeen()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
324 self.menubar.dispatch(id, item, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
325
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
326
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
327 def do_unknownpartcode(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
328 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
329 if DEBUG: print "Mouse down at global:", where
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
330 if DEBUG: print "\tUnknown part code:", partcode
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
331 if DEBUG: print "\tEvent:", self.printevent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
332 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
333 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
334
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
335 def do_unknownwindow(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
336 if DEBUG: print 'Unknown window:', window
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
337 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
338 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
339
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
340 def do_keyDown(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
341 self.do_key(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
342
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
343 def do_autoKey(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
344 if not event[-1] & cmdKey:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
345 self.do_key(event)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
347 def do_key(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
348 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
349 c = chr(message & charCodeMask)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
350 if self.menubar:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
351 result = MenuEvent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
352 id = (result>>16) & 0xffff # Hi word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
353 item = result & 0xffff # Lo word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
354 if id:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
355 self.do_rawmenu(id, item, None, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
356 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
357 # Otherwise we fall-through
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
358 if modifiers & cmdKey:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
359 if c == '.':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
360 raise self
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
361 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
362 if not self.menubar:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
363 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
364 MacOS.HandleEvent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
365 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
366 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
367 # See whether the front window wants it
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
368 w = MyFrontWindow()
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
369 if w and w in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
370 window = self._windows[w]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
371 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
372 do_char = window.do_char
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
373 except AttributeError:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
374 do_char = self.do_char
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
375 do_char(c, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
376 # else it wasn't for us, sigh...
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
377
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
378 def do_char(self, c, event):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29575
diff changeset
379 if DEBUG: print "Character", repr(c)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
380
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
381 def do_updateEvt(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
382 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
383 wid = WhichWindow(message)
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
384 if wid and wid in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
385 window = self._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
386 window.do_rawupdate(wid, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
387 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
388 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
389 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
390
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
391 def do_activateEvt(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
392 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
393 wid = WhichWindow(message)
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
394 if wid and wid in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
395 window = self._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
396 window.do_activate(modifiers & 1, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
397 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
398 if hasattr(MacOS, 'HandleEvent'):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
399 MacOS.HandleEvent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
400
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
401 def do_osEvt(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
402 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
403 which = (message >> 24) & 0xff
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
404 if which == 1: # suspend/resume
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
405 self.do_suspendresume(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
406 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
407 if DEBUG:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
408 print 'unknown osEvt:',
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
409 self.printevent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
410
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
411 def do_suspendresume(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
412 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
413 wid = MyFrontWindow()
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
414 if wid and wid in self._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
415 window = self._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
416 window.do_activate(message & 1, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
417
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
418 def do_kHighLevelEvent(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
419 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
420 if DEBUG:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
421 print "High Level Event:",
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
422 self.printevent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
423 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
424 AEProcessAppleEvent(event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
425 except:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
426 pass
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
427 #print "AEProcessAppleEvent error:"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
428 #traceback.print_exc()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
429
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
430 def do_unknownevent(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
431 if DEBUG:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
432 print "Unhandled event:",
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
433 self.printevent(event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
434
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
435 def printevent(self, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
436 (what, message, when, where, modifiers) = event
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29575
diff changeset
437 nicewhat = repr(what)
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
438 if what in eventname:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
439 nicewhat = eventname[what]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
440 print nicewhat,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
441 if what == kHighLevelEvent:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
442 h, v = where
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29575
diff changeset
443 print repr(ostypecode(message)), hex(when), repr(ostypecode(h | (v<<16))),
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
444 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
445 print hex(message), hex(when), where,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
446 print hex(modifiers)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
447
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
448
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
449 class MenuBar:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
450 """Represent a set of menus in a menu bar.
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
451
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
452 Interface:
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
453
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
454 - (constructor)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
455 - (destructor)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
456 - addmenu
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
457 - addpopup (normally used internally)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
458 - dispatch (called from Application)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
459 """
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
460
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
461 nextid = 1 # Necessarily a class variable
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
462
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
463 def getnextid(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
464 id = MenuBar.nextid
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
465 MenuBar.nextid = id+1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
466 return id
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
467
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
468 def __init__(self, parent=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
469 self.parent = parent
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
470 ClearMenuBar()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
471 self.bar = GetMenuBar()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
472 self.menus = {}
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
473
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
474 # XXX necessary?
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
475 def close(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
476 self.parent = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
477 self.bar = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
478 self.menus = None
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
479
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
480 def addmenu(self, title, after = 0, id=None):
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
481 if id is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
482 id = self.getnextid()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
483 if DEBUG: print 'Newmenu', title, id # XXXX
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
484 m = NewMenu(id, title)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
485 m.InsertMenu(after)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
486 if after >= 0:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
487 if self.parent:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
488 self.parent.needmenubarredraw = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
489 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
490 DrawMenuBar()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
491 return id, m
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
492
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
493 def delmenu(self, id):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
494 if DEBUG: print 'Delmenu', id # XXXX
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
495 DeleteMenu(id)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
496
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
497 def addpopup(self, title = ''):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
498 return self.addmenu(title, -1)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
499
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
500 # Useless:
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
501 # def install(self):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
502 # if not self.bar: return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
503 # SetMenuBar(self.bar)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
504 # if self.parent:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
505 # self.parent.needmenubarredraw = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
506 # else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
507 # DrawMenuBar()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
508
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
509 def fixmenudimstate(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
510 for m in self.menus.keys():
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
511 menu = self.menus[m]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
512 if menu.__class__ == FrameWork.AppleMenu:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
513 continue
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
514 for i in range(len(menu.items)):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
515 label, shortcut, callback, kind = menu.items[i]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
516 if type(callback) == types.StringType:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
517 wid = MyFrontWindow()
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
518 if wid and wid in self.parent._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
519 window = self.parent._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
520 if hasattr(window, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
521 menu.menu.EnableMenuItem(i + 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
522 elif hasattr(self.parent, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
523 menu.menu.EnableMenuItem(i + 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
524 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
525 menu.menu.DisableMenuItem(i + 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
526 elif hasattr(self.parent, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
527 menu.menu.EnableMenuItem(i + 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
528 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
529 menu.menu.DisableMenuItem(i + 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
530 elif callback:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
531 pass
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
532
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
533 def dispatch(self, id, item, window, event):
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
534 if id in self.menus:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
535 self.menus[id].dispatch(id, item, window, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
536 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
537 if DEBUG: print "MenuBar.dispatch(%d, %d, %s, %s)" % \
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
538 (id, item, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
539
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
540
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
541 # XXX Need a way to get menus as resources and bind them to callbacks
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
542
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
543 class Menu:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
544 "One menu."
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
545
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
546 def __init__(self, bar, title, after=0, id=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
547 self.bar = bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
548 self.id, self.menu = self.bar.addmenu(title, after, id)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
549 bar.menus[self.id] = self
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
550 self.items = []
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
551 self._parent = None
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
552
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
553 def delete(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
554 self.bar.delmenu(self.id)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
555 del self.bar.menus[self.id]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
556 self.menu.DisposeMenu()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
557 del self.bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
558 del self.items
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
559 del self.menu
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
560 del self.id
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
561 del self._parent
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
562
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
563 def additem(self, label, shortcut=None, callback=None, kind=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
564 self.menu.AppendMenu('x') # add a dummy string
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
565 self.items.append((label, shortcut, callback, kind))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
566 item = len(self.items)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
567 if isinstance(label, unicode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
568 self.menu.SetMenuItemTextWithCFString(item, label)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
569 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
570 self.menu.SetMenuItemText(item, label)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
571 if shortcut and type(shortcut) == type(()):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
572 modifiers, char = shortcut[:2]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
573 self.menu.SetItemCmd(item, ord(char))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
574 self.menu.SetMenuItemModifiers(item, modifiers)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
575 if len(shortcut) > 2:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
576 self.menu.SetMenuItemKeyGlyph(item, shortcut[2])
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
577 elif shortcut:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
578 self.menu.SetItemCmd(item, ord(shortcut))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
579 return item
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
580
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
581 def delitem(self, item):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
582 if item != len(self.items):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
583 raise 'Can only delete last item of a menu'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
584 self.menu.DeleteMenuItem(item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
585 del self.items[item-1]
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
586
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
587 def addcheck(self, label, shortcut=None, callback=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
588 return self.additem(label, shortcut, callback, 'check')
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
589
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
590 def addradio(self, label, shortcut=None, callback=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
591 return self.additem(label, shortcut, callback, 'radio')
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
592
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
593 def addseparator(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
594 self.menu.AppendMenu('(-')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
595 self.items.append(('', None, None, 'separator'))
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
596
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
597 def addsubmenu(self, label, title=''):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
598 sub = Menu(self.bar, title, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
599 item = self.additem(label, '\x1B', None, 'submenu')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
600 self.menu.SetItemMark(item, sub.id)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
601 sub._parent = self
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
602 sub._parent_item = item
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
603 return sub
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
604
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
605 def dispatch(self, id, item, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
606 title, shortcut, callback, mtype = self.items[item-1]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
607 if callback:
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
608 if not self.bar.parent or type(callback) != types.StringType:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
609 menuhandler = callback
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
610 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
611 # callback is string
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
612 wid = MyFrontWindow()
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
613 if wid and wid in self.bar.parent._windows:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
614 window = self.bar.parent._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
615 if hasattr(window, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
616 menuhandler = getattr(window, "domenu_" + callback)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
617 elif hasattr(self.bar.parent, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
618 menuhandler = getattr(self.bar.parent, "domenu_" + callback)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
619 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
620 # nothing we can do. we shouldn't have come this far
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
621 # since the menu item should have been disabled...
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
622 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
623 elif hasattr(self.bar.parent, "domenu_" + callback):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
624 menuhandler = getattr(self.bar.parent, "domenu_" + callback)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
625 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
626 # nothing we can do. we shouldn't have come this far
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
627 # since the menu item should have been disabled...
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
628 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
629 menuhandler(id, item, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
630
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
631 def enable(self, onoff):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
632 if onoff:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
633 self.menu.EnableMenuItem(0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
634 if self._parent:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
635 self._parent.menu.EnableMenuItem(self._parent_item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
636 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
637 self.menu.DisableMenuItem(0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
638 if self._parent:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
639 self._parent.menu.DisableMenuItem(self._parent_item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
640 if self.bar and self.bar.parent:
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
641 self.bar.parent.needmenubarredraw = 1
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
642
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
643 class PopupMenu(Menu):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
644 def __init__(self, bar):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
645 Menu.__init__(self, bar, '(popup)', -1)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
646
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
647 def popup(self, x, y, event, default=1, window=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
648 # NOTE that x and y are global coordinates, and they should probably
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
649 # be topleft of the button the user clicked (not mouse-coordinates),
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
650 # so the popup nicely overlaps.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
651 reply = self.menu.PopUpMenuSelect(x, y, default)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
652 if not reply:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
653 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
654 id = (reply >> 16) & 0xffff
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
655 item = reply & 0xffff
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
656 if not window:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
657 wid = MyFrontWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
658 try:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
659 window = self.bar.parent._windows[wid]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
660 except:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
661 pass # If we can't find the window we pass None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
662 self.dispatch(id, item, window, event)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
663
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
664 class MenuItem:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
665 def __init__(self, menu, title, shortcut=None, callback=None, kind=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
666 self.item = menu.additem(title, shortcut, callback)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
667 self.menu = menu
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
668
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
669 def delete(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
670 self.menu.delitem(self.item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
671 del self.menu
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
672 del self.item
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
673
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
674 def check(self, onoff):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
675 self.menu.menu.CheckMenuItem(self.item, onoff)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
676
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
677 def enable(self, onoff):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
678 if onoff:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
679 self.menu.menu.EnableMenuItem(self.item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
680 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
681 self.menu.menu.DisableMenuItem(self.item)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
682
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
683 def settext(self, text):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
684 self.menu.menu.SetMenuItemText(self.item, text)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
685
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
686 def setstyle(self, style):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
687 self.menu.menu.SetItemStyle(self.item, style)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
688
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
689 def seticon(self, icon):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
690 self.menu.menu.SetItemIcon(self.item, icon)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
691
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
692 def setcmd(self, cmd):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
693 self.menu.menu.SetItemCmd(self.item, cmd)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
694
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
695 def setmark(self, cmd):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
696 self.menu.menu.SetItemMark(self.item, cmd)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
697
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
698
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
699 class RadioItem(MenuItem):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
700 def __init__(self, menu, title, shortcut=None, callback=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
701 MenuItem.__init__(self, menu, title, shortcut, callback, 'radio')
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
702
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
703 class CheckItem(MenuItem):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
704 def __init__(self, menu, title, shortcut=None, callback=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
705 MenuItem.__init__(self, menu, title, shortcut, callback, 'check')
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
706
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
707 def Separator(menu):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
708 menu.addseparator()
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
709
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
710 def SubMenu(menu, label, title=''):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
711 return menu.addsubmenu(label, title)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
712
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
713
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
714 class AppleMenu(Menu):
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
715
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
716 def __init__(self, bar, abouttext="About me...", aboutcallback=None):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
717 Menu.__init__(self, bar, "\024", id=SIOUX_APPLEMENU_ID)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
718 if MacOS.runtimemodel == 'ppc':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
719 self.additem(abouttext, None, aboutcallback)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
720 self.addseparator()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
721 self.menu.AppendResMenu('DRVR')
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
722 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
723 # Additem()'s tricks do not work for "apple" menu under Carbon
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
724 self.menu.InsertMenuItem(abouttext, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
725 self.items.append((abouttext, None, aboutcallback, None))
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
726
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
727 def dispatch(self, id, item, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
728 if item == 1:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
729 Menu.dispatch(self, id, item, window, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
730 elif MacOS.runtimemodel == 'ppc':
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
731 name = self.menu.GetMenuItemText(item)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
732 OpenDeskAcc(name)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
733
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
734 class HelpMenu(Menu):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
735 def __init__(self, bar):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
736 # Note we don't call Menu.__init__, we do the necessary things by hand
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
737 self.bar = bar
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
738 self.menu, index = HMGetHelpMenu()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
739 self.id = self.menu.GetMenuID()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
740 bar.menus[self.id] = self
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
741 # The next line caters for the entries the system already handles for us
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
742 self.items = [None]*(index-1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
743 self._parent = None
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
744
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
745
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
746 class Window:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
747 """A single window belonging to an application"""
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
748
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
749 def __init__(self, parent):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
750 self.wid = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
751 self.parent = parent
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
752
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
753 def open(self, bounds=(40, 40, 400, 400), resid=None):
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
754 if resid != None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
755 self.wid = GetNewWindow(resid, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
756 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
757 self.wid = NewWindow(bounds, self.__class__.__name__, 1,
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
758 8, -1, 1, 0) # changed to proc id 8 to include zoom box. jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
759 self.do_postopen()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
760
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
761 def do_postopen(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
762 """Tell our parent we exist"""
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
763 self.parent.appendwindow(self.wid, self)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
764
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
765 def close(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
766 self.do_postclose()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
767
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
768 def do_postclose(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
769 self.parent.removewindow(self.wid)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
770 self.parent = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
771 self.wid = None
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
772
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
773 def SetPort(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
774 # Convinience method
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
775 SetPort(self.wid)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
776
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
777 def GetWindow(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
778 return self.wid
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
779
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
780 def do_inDrag(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
781 where = event[3]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
782 window.DragWindow(where, self.draglimit)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
783
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
784 draglimit = screenbounds
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
785
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
786 def do_inGoAway(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
787 where = event[3]
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
788 if window.TrackGoAway(where):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
789 self.close()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
790
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
791 def do_inZoom(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
792 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
793 if window.TrackBox(where, partcode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
794 window.ZoomWindow(partcode, 1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
795 rect = window.GetWindowUserState() # so that zoom really works... jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
796 self.do_postresize(rect[2] - rect[0], rect[3] - rect[1], window) # jvr
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
797
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
798 def do_inZoomIn(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
799 SetPort(window) # !!!
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
800 self.do_inZoom(partcode, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
801
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
802 def do_inZoomOut(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
803 SetPort(window) # !!!
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
804 self.do_inZoom(partcode, window, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
805
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
806 def do_inGrow(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
807 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
808 result = window.GrowWindow(where, self.growlimit)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
809 if result:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
810 height = (result>>16) & 0xffff # Hi word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
811 width = result & 0xffff # Lo word
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
812 self.do_resize(width, height, window)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
813
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
814 growlimit = (50, 50, screenbounds[2] - screenbounds[0], screenbounds[3] - screenbounds[1]) # jvr
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
815
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
816 def do_resize(self, width, height, window):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
817 l, t, r, b = self.wid.GetWindowPort().GetPortBounds() # jvr, forGrowIcon
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
818 self.SetPort() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
819 self.wid.InvalWindowRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
820 window.SizeWindow(width, height, 1) # changed updateFlag to true jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
821 self.do_postresize(width, height, window)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
822
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
823 def do_postresize(self, width, height, window):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
824 SetPort(window)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
825 self.wid.InvalWindowRect(window.GetWindowPort().GetPortBounds())
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
826
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
827 def do_inContent(self, partcode, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
828 #
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
829 # If we're not frontmost, select ourselves and wait for
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
830 # the activate event.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
831 #
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
832 if MyFrontWindow() != window:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
833 window.SelectWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
834 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
835 # We are. Handle the event.
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
836 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
837 SetPort(window)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
838 local = GlobalToLocal(where)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
839 self.do_contentclick(local, modifiers, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
840
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
841 def do_contentclick(self, local, modifiers, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
842 if DEBUG:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
843 print 'Click in contents at %s, modifiers %s'%(local, modifiers)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
844
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
845 def do_rawupdate(self, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
846 if DEBUG: print "raw update for", window
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
847 SetPort(window)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
848 window.BeginUpdate()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
849 self.do_update(window, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
850 window.EndUpdate()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
851
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
852 def do_update(self, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
853 if DEBUG:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
854 import time
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
855 for i in range(8):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
856 time.sleep(0.1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
857 InvertRgn(window.GetWindowPort().visRgn)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
858 FillRgn(window.GetWindowPort().visRgn, GetQDGlobalsGray())
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
859 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
860 EraseRgn(window.GetWindowPort().visRgn)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
861
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
862 def do_activate(self, activate, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
863 if DEBUG: print 'Activate %d for %s'%(activate, self.wid)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
864
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
865 class ControlsWindow(Window):
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
866
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
867 def do_rawupdate(self, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
868 if DEBUG: print "raw update for", window
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
869 SetPort(window)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
870 window.BeginUpdate()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
871 self.do_update(window, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
872 #DrawControls(window) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
873 UpdateControls(window, window.GetWindowPort().visRgn) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
874 window.DrawGrowIcon()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
875 window.EndUpdate()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
876
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
877 def do_controlhit(self, window, control, pcode, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
878 if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
879
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
880 def do_inContent(self, partcode, window, event):
60278
e29a2e03e739 Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents: 47958
diff changeset
881 if MyFrontWindow() != window:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
882 window.SelectWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
883 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
884 (what, message, when, where, modifiers) = event
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
885 SetPort(window) # XXXX Needed?
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
886 local = GlobalToLocal(where)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
887 pcode, control = FindControl(local, window)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
888 if pcode and control:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
889 self.do_rawcontrolhit(window, control, pcode, local, event)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
890 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
891 if DEBUG: print "FindControl(%s, %s) -> (%s, %s)" % \
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
892 (local, window, pcode, control)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
893 self.do_contentclick(local, modifiers, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
894
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
895 def do_rawcontrolhit(self, window, control, pcode, local, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
896 pcode = control.TrackControl(local)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
897 if pcode:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
898 self.do_controlhit(window, control, pcode, event)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
899
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
900 class ScrolledWindow(ControlsWindow):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
901 def __init__(self, parent):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
902 self.barx = self.bary = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
903 self.barx_enabled = self.bary_enabled = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
904 self.activated = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
905 ControlsWindow.__init__(self, parent)
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
906
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
907 def scrollbars(self, wantx=1, wanty=1):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
908 SetPort(self.wid)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
909 self.barx = self.bary = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
910 self.barx_enabled = self.bary_enabled = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
911 x0, y0, x1, y1 = self.wid.GetWindowPort().GetPortBounds()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
912 vx, vy = self.getscrollbarvalues()
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
913 if vx is None: self.barx_enabled, vx = 0, 0
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
914 if vy is None: self.bary_enabled, vy = 0, 0
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
915 if wantx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
916 rect = x0-1, y1-(SCROLLBARWIDTH-1), x1-(SCROLLBARWIDTH-2), y1+1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
917 self.barx = NewControl(self.wid, rect, "", 1, vx, 0, 32767, 16, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
918 if not self.barx_enabled: self.barx.HiliteControl(255)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
919 ## self.wid.InvalWindowRect(rect)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
920 if wanty:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
921 rect = x1-(SCROLLBARWIDTH-1), y0-1, x1+1, y1-(SCROLLBARWIDTH-2)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
922 self.bary = NewControl(self.wid, rect, "", 1, vy, 0, 32767, 16, 0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
923 if not self.bary_enabled: self.bary.HiliteControl(255)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
924 ## self.wid.InvalWindowRect(rect)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
925
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
926 def do_postclose(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
927 self.barx = self.bary = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
928 ControlsWindow.do_postclose(self)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
929
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
930 def do_activate(self, onoff, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
931 self.activated = onoff
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
932 if onoff:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
933 if self.barx and self.barx_enabled:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
934 self.barx.ShowControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
935 if self.bary and self.bary_enabled:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
936 self.bary.ShowControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
937 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
938 if self.barx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
939 self.barx.HideControl() # jvr; An inactive window should have *hidden*
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
940 # scrollbars, not just dimmed (no matter what
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
941 # BBEdit does... look at the Finder)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
942 if self.bary:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
943 self.bary.HideControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
944 self.wid.DrawGrowIcon() # jvr
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
945
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
946 def do_postresize(self, width, height, window):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
947 l, t, r, b = self.wid.GetWindowPort().GetPortBounds()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
948 self.SetPort()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
949 if self.barx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
950 self.barx.HideControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
951 self.barx.MoveControl(l-1, b-(SCROLLBARWIDTH-1))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
952 self.barx.SizeControl((r-l)-(SCROLLBARWIDTH-3), SCROLLBARWIDTH) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
953 if self.bary:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
954 self.bary.HideControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
955 self.bary.MoveControl(r-(SCROLLBARWIDTH-1), t-1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
956 self.bary.SizeControl(SCROLLBARWIDTH, (b-t)-(SCROLLBARWIDTH-3)) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
957 if self.barx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
958 self.barx.ShowControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
959 self.wid.ValidWindowRect((l, b - SCROLLBARWIDTH + 1, r - SCROLLBARWIDTH + 2, b)) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
960 if self.bary:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
961 self.bary.ShowControl() # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
962 self.wid.ValidWindowRect((r - SCROLLBARWIDTH + 1, t, r, b - SCROLLBARWIDTH + 2)) # jvr
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
963 self.wid.InvalWindowRect((r - SCROLLBARWIDTH + 1, b - SCROLLBARWIDTH + 1, r, b)) # jvr, growicon
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
964
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
965
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
966 def do_rawcontrolhit(self, window, control, pcode, local, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
967 if control == self.barx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
968 which = 'x'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
969 elif control == self.bary:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
970 which = 'y'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
971 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
972 return 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
973 if pcode in (inUpButton, inDownButton, inPageUp, inPageDown):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
974 # We do the work for the buttons and grey area in the tracker
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
975 dummy = control.TrackControl(local, self.do_controltrack)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
976 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
977 # but the thumb is handled here
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
978 pcode = control.TrackControl(local)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
979 if pcode == inThumb:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
980 value = control.GetControlValue()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
981 print 'setbars', which, value #DBG
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
982 self.scrollbar_callback(which, 'set', value)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
983 self.updatescrollbars()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
984 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
985 print 'funny part', pcode #DBG
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
986 return 1
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
987
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
988 def do_controltrack(self, control, pcode):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
989 if control == self.barx:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
990 which = 'x'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
991 elif control == self.bary:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
992 which = 'y'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
993 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
994 return
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
995
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
996 if pcode == inUpButton:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
997 what = '-'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
998 elif pcode == inDownButton:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
999 what = '+'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1000 elif pcode == inPageUp:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1001 what = '--'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1002 elif pcode == inPageDown:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1003 what = '++'
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1004 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1005 return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1006 self.scrollbar_callback(which, what, None)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1007 self.updatescrollbars()
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1008
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1009 def updatescrollbars(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1010 SetPort(self.wid)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1011 vx, vy = self.getscrollbarvalues()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1012 if self.barx:
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
1013 if vx is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1014 self.barx.HiliteControl(255)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1015 self.barx_enabled = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1016 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1017 if not self.barx_enabled:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1018 self.barx_enabled = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1019 if self.activated:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1020 self.barx.HiliteControl(0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1021 self.barx.SetControlValue(vx)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1022 if self.bary:
46197
01a7e66525c2 #2503 make singletons compared with "is" not == or !=
Benjamin Peterson <benjamin@python.org>
parents: 32736
diff changeset
1023 if vy is None:
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1024 self.bary.HiliteControl(255)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1025 self.bary_enabled = 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1026 else:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1027 if not self.bary_enabled:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1028 self.bary_enabled = 1
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1029 if self.activated:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1030 self.bary.HiliteControl(0)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1031 self.bary.SetControlValue(vy)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1032
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1033 # Auxiliary function: convert standard text/image/etc coordinate
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1034 # to something palatable as getscrollbarvalues() return
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1035 def scalebarvalue(self, absmin, absmax, curmin, curmax):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1036 if curmin <= absmin and curmax >= absmax:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1037 return None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1038 if curmin <= absmin:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1039 return 0
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1040 if curmax >= absmax:
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1041 return 32767
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1042 perc = float(curmin-absmin)/float(absmax-absmin)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1043 return int(perc*32767)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1044
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1045 # To be overridden:
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1046
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1047 def getscrollbarvalues(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1048 return 0, 0
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1049
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1050 def scrollbar_callback(self, which, what, value):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1051 print 'scroll', which, what, value
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1052
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1053 class DialogWindow(Window):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1054 """A modeless dialog window"""
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1055
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1056 def open(self, resid):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1057 self.dlg = GetNewDialog(resid, -1)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1058 self.wid = self.dlg.GetDialogWindow()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1059 self.do_postopen()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1060
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1061 def close(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1062 self.do_postclose()
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1063
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1064 def do_postclose(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1065 self.dlg = None
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1066 Window.do_postclose(self)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1067
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1068 def do_itemhit(self, item, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1069 print 'Dialog %s, item %d hit'%(self.dlg, item)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1070
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1071 def do_rawupdate(self, window, event):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1072 pass
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1073
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1074 def ostypecode(x):
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1075 "Convert a long int to the 4-character code it really is"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1076 s = ''
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1077 for i in range(4):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1078 x, c = divmod(x, 256)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1079 s = chr(c) + s
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1080 return s
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1081
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1082
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1083 class TestApp(Application):
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1084
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1085 "This class is used by the test() function"
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1086
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1087 def makeusermenus(self):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1088 self.filemenu = m = Menu(self.menubar, "File")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1089 self.saveitem = MenuItem(m, "Save", "S", self.save)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1090 Separator(m)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1091 self.optionsmenu = mm = SubMenu(m, "Options")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1092 self.opt1 = CheckItem(mm, "Arguments", "A")
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1093 self.opt2 = CheckItem(mm, "Being hit on the head lessons", (kMenuOptionModifier, "A"))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1094 self.opt3 = CheckItem(mm, "Complaints", (kMenuOptionModifier|kMenuNoCommandModifier, "A"))
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1095 Separator(m)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1096 self.itemeh = MenuItem(m, "Enable Help", None, self.enablehelp)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1097 self.itemdbg = MenuItem(m, "Debug", None, self.debug)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1098 Separator(m)
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1099 self.quititem = MenuItem(m, "Quit", "Q", self.quit)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1100
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1101 def save(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1102 print "Save"
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1103
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1104 def quit(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1105 raise self
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1106
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1107 def enablehelp(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1108 hm = self.gethelpmenu()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1109 self.nohelpitem = MenuItem(hm, "There isn't any", None, self.nohelp)
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1110
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1111 def nohelp(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1112 print "I told you there isn't any!"
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 27190
diff changeset
1113
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1114 def debug(self, *args):
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1115 import pdb
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1116 pdb.set_trace()
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1117
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1118
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1119 def test():
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1120 "Test program"
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1121 app = TestApp()
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1122 app.mainloop()
26884
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1123
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1124
f0f9acca4164 Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1125 if __name__ == '__main__':
29575
b8b57bdbfced changed 8-space indentation to 4
Just van Rossum <just@letterror.com>
parents: 28513
diff changeset
1126 test()