Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f21b706

Browse files
committed
Added support for the help menu. Application.gethelpmenu() will return
it. Also fixed menu IDs to be signed in do_menudispatch. this is an incompatible change, but I don't think it'll hurt anyone.
1 parent 983258e commit f21b706

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Mac/Lib/FrameWork.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from Carbon.Dialogs import *
1414
from Carbon.Evt import *
1515
from Carbon.Events import *
16+
from Carbon.Help import *
1617
from Carbon.Menu import *
1718
from Carbon.Menus import *
1819
from Carbon.Qd import *
@@ -111,6 +112,7 @@ def __init__(self, nomenubar=0):
111112
self.menubar = None
112113
else:
113114
self.makemenubar()
115+
self._helpmenu = None
114116

115117
def __del__(self):
116118
if self._doing_asyncevents:
@@ -125,6 +127,11 @@ def makemenubar(self):
125127
def makeusermenus(self):
126128
self.filemenu = m = Menu(self.menubar, "File")
127129
self._quititem = MenuItem(m, "Quit", "Q", self._quit)
130+
131+
def gethelpmenu(self):
132+
if self._helpmenu == None:
133+
self._helpmenu = HelpMenu(self.menubar)
134+
return self._helpmenu
128135

129136
def _quit(self, *args):
130137
self.quitting = 1
@@ -297,6 +304,8 @@ def do_inMenuBar(self, partcode, window, event):
297304
(what, message, when, where, modifiers) = event
298305
result = MenuSelect(where)
299306
id = (result>>16) & 0xffff # Hi word
307+
if id >= 0x8000:
308+
id = -65536 + id
300309
item = result & 0xffff # Lo word
301310
self.do_rawmenu(id, item, window, event)
302311

@@ -715,6 +724,18 @@ def dispatch(self, id, item, window, event):
715724
elif MacOS.runtimemodel == 'ppc':
716725
name = self.menu.GetMenuItemText(item)
717726
OpenDeskAcc(name)
727+
728+
class HelpMenu(Menu):
729+
def __init__(self, bar):
730+
# Note we don't call Menu.__init__, we do the necessary things by hand
731+
self.bar = bar
732+
self.menu, index = HMGetHelpMenu()
733+
self.id = self.menu.GetMenuID()
734+
bar.menus[self.id] = self
735+
# The next line caters for the entries the system already handles for us
736+
self.items = [None]*(index-1)
737+
self._parent = None
738+
718739

719740
class Window:
720741
"""A single window belonging to an application"""
@@ -1066,13 +1087,27 @@ def makeusermenus(self):
10661087
self.opt2 = CheckItem(mm, "Being hit on the head lessons", (kMenuOptionModifier, "A"))
10671088
self.opt3 = CheckItem(mm, "Complaints", (kMenuOptionModifier|kMenuNoCommandModifier, "A"))
10681089
Separator(m)
1090+
self.itemeh = MenuItem(m, "Enable Help", None, self.enablehelp)
1091+
self.itemdbg = MenuItem(m, "Debug", None, self.debug)
1092+
Separator(m)
10691093
self.quititem = MenuItem(m, "Quit", "Q", self.quit)
10701094

10711095
def save(self, *args):
10721096
print "Save"
10731097

10741098
def quit(self, *args):
10751099
raise self
1100+
1101+
def enablehelp(self, *args):
1102+
hm = self.gethelpmenu()
1103+
self.nohelpitem = MenuItem(hm, "There isn't any", None, self.nohelp)
1104+
1105+
def nohelp(self, *args):
1106+
print "I told you there isn't any!"
1107+
1108+
def debug(self, *args):
1109+
import pdb
1110+
pdb.set_trace()
10761111

10771112

10781113
def test():

0 commit comments

Comments
 (0)