]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added support for the help menu. Application.gethelpmenu() will return
authorJack Jansen <jack.jansen@cwi.nl>
Thu, 29 Aug 2002 22:04:15 +0000 (22:04 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Thu, 29 Aug 2002 22:04:15 +0000 (22:04 +0000)
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.

Mac/Lib/FrameWork.py

index b3bf55f9b1b20df8e4dccab39bde1da2cc67eccb..21a4f0ec7affbeda73b74b00ace2b3802105524a 100644 (file)
@@ -13,6 +13,7 @@ from Carbon.Dlg import *
 from Carbon.Dialogs import *
 from Carbon.Evt import *
 from Carbon.Events import *
+from Carbon.Help import *
 from Carbon.Menu import *
 from Carbon.Menus import *
 from Carbon.Qd import *
@@ -111,6 +112,7 @@ class Application:
                        self.menubar = None
                else:
                        self.makemenubar()
+               self._helpmenu = None
                        
        def __del__(self):
                if self._doing_asyncevents:
@@ -125,6 +127,11 @@ class Application:
        def makeusermenus(self):
                self.filemenu = m = Menu(self.menubar, "File")
                self._quititem = MenuItem(m, "Quit", "Q", self._quit)
+               
+       def gethelpmenu(self):
+               if self._helpmenu == None:
+                       self._helpmenu = HelpMenu(self.menubar)
+               return self._helpmenu
        
        def _quit(self, *args):
                self.quitting = 1
@@ -297,6 +304,8 @@ class Application:
                (what, message, when, where, modifiers) = event
                result = MenuSelect(where)
                id = (result>>16) & 0xffff      # Hi word
+               if id >= 0x8000:
+                       id = -65536 + id
                item = result & 0xffff          # Lo word
                self.do_rawmenu(id, item, window, event)
        
@@ -715,6 +724,18 @@ class AppleMenu(Menu):
                elif MacOS.runtimemodel == 'ppc':
                        name = self.menu.GetMenuItemText(item)
                        OpenDeskAcc(name)
+                       
+class HelpMenu(Menu):
+       def __init__(self, bar):
+               # Note we don't call Menu.__init__, we do the necessary things by hand
+               self.bar = bar
+               self.menu, index = HMGetHelpMenu()
+               self.id = self.menu.GetMenuID()
+               bar.menus[self.id] = self
+               # The next line caters for the entries the system already handles for us
+               self.items = [None]*(index-1)
+               self._parent = None
+               
 
 class Window:
        """A single window belonging to an application"""
@@ -1066,6 +1087,9 @@ class TestApp(Application):
                self.opt2 = CheckItem(mm, "Being hit on the head lessons", (kMenuOptionModifier, "A"))
                self.opt3 = CheckItem(mm, "Complaints", (kMenuOptionModifier|kMenuNoCommandModifier, "A"))
                Separator(m)
+               self.itemeh = MenuItem(m, "Enable Help", None, self.enablehelp)
+               self.itemdbg = MenuItem(m, "Debug", None, self.debug)
+               Separator(m)
                self.quititem = MenuItem(m, "Quit", "Q", self.quit)
        
        def save(self, *args):
@@ -1073,6 +1097,17 @@ class TestApp(Application):
        
        def quit(self, *args):
                raise self
+               
+       def enablehelp(self, *args):
+               hm = self.gethelpmenu()
+               self.nohelpitem = MenuItem(hm, "There isn't any", None, self.nohelp)
+               
+       def nohelp(self, *args):
+               print "I told you there isn't any!"
+               
+       def debug(self, *args):
+               import pdb
+               pdb.set_trace()
 
 
 def test():