diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-31 01:25:17 +0000 |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-31 01:25:17 +0000 |
commit | 24205f73fe2866f73f2b53aa38169a5c793a9950 (patch) | |
tree | 9fc015a6526ba9a9c3ae24ff8ca01653d9868f6d | |
parent | 14f971f3550d652c702a48ef6fcaa09958fd2282 (diff) | |
download | cpython-24205f73fe2866f73f2b53aa38169a5c793a9950.tar.gz |
Implemented the Help menu. The Python manual can be viewed (if installed)
and the selection can be looked up, and so can the Carbon manual. From the
help menu you can also get to the online documentation, the Python website
and the MacPython page.
Untested in MacPython-OS9.
-rw-r--r-- | Mac/Tools/IDE/PythonIDEMain.py | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Mac/Tools/IDE/PythonIDEMain.py b/Mac/Tools/IDE/PythonIDEMain.py index 0a1d90fe65..d93dc1cd32 100644 --- a/Mac/Tools/IDE/PythonIDEMain.py +++ b/Mac/Tools/IDE/PythonIDEMain.py @@ -145,6 +145,7 @@ class PythonIDE(Wapplication.Application): self._scripts = {} self.scriptsmenu = None self.makescriptsmenu() + self.makehelpmenu() def quitevent(self, theAppleEvent, theReply): from Carbon import AE @@ -278,6 +279,107 @@ class PythonIDE(Wapplication.Application): if rv and rv > 0: return self.quitting = 1 + + def makehelpmenu(self): + docs = self.installdocumentation() + self.helpmenu = m = self.gethelpmenu() + docitem = FrameWork.MenuItem(m, "Python Documentation", None, self.domenu_localdocs) + docitem.enable(docs) + doc2item = FrameWork.MenuItem(m, "Apple Developer Documentation", None, self.domenu_appledocs) + FrameWork.Separator(m) + finditem = FrameWork.MenuItem(m, "Lookup in Python Documentation", None, 'lookuppython') + finditem.enable(docs) + find2item = FrameWork.MenuItem(m, "Lookup in Carbon Documentation", None, 'lookupcarbon') + FrameWork.Separator(m) + webitem = FrameWork.MenuItem(m, "Python Documentation on the Web", None, self.domenu_webdocs) + web2item = FrameWork.MenuItem(m, "Python on the Web", None, self.domenu_webpython) + web3item = FrameWork.MenuItem(m, "MacPython on the Web", None, self.domenu_webmacpython) + + def domenu_localdocs(self, *args): + from Carbon import AH + AH.AHGotoPage("Python Help", "index.html", "") + + def domenu_appledocs(self, *args): + from Carbon import AH, AppleHelp + try: + AH.AHGotoMainTOC(AppleHelp.kAHTOCTypeDeveloper) + except AH.Error, arg: + if arg[0] == -50: + W.Message("Developer documentation not installed") + else: + W.Message("AppleHelp Error: %s" % `arg`) + + def domenu_lookuppython(self, *args): + from Carbon import AH + searchstring = self._getsearchstring() + if not searchstring: + return + try: + AH.AHSearch("Python Help", searchstring) + except AH.Error, arg: + W.Message("AppleHelp Error: %s" % `arg`) + + def domenu_lookupcarbon(self, *args): + from Carbon import AH + searchstring = self._getsearchstring() + if not searchstring: + return + try: + AH.AHSearch("Carbon", searchstring) + except AH.Error, arg: + W.Message("AppleHelp Error: %s" % `arg`) + + def _getsearchstring(self): + import PyEdit + editor = PyEdit.findeditor(None, fromtop=1) + if editor: + text = editor.getselectedtext() + if text: + return text + # This is a cop-out. We should have disabled the menus + # if there is no selection, but the can_ methods only seem + # to work for Windows. Or not for the Help menu, maybe? + import EasyDialogs + text = EasyDialogs.AskString("Search documentation for", ok="Search") + return text + + def domenu_webdocs(self, *args): + import webbrowser + major, minor, micro, state, nano = sys.version_info + if state in ('alpha', 'beta'): + docversion = 'dev/doc/devel' + elif micro == 0: + docversion = 'doc/%d.%d' % (major, minor) + else: + docversion = 'doc/%d.%d.%d' % (major, minor, micro) + webbrowser.open("http://www.python.org/%s" % docversion) + + def domenu_webpython(self, *args): + import webbrowser + webbrowser.open("http://www.python.org/") + + def domenu_webmacpython(self, *args): + import webbrowser + webbrowser.open("http://www.cwi.nl/~jack/macpython.html") + + def installdocumentation(self): + # This is rather much of a hack. Someone has to tell the Help Viewer + # about the Python documentation, so why not us. The documentation + # is located in the framework, but there's a symlink in Python.app. + # And as AHRegisterHelpBook wants a bundle (with the right bits in + # the plist file) we refer it to Python.app + python_app = os.path.join(sys.prefix, 'Resources/Python.app') + doc_source = os.path.join(python_app, 'Contents/Resources/English.lproj/Documentation') + if not os.path.isdir(doc_source): + return 0 + try: + from Carbon import AH + AH.AHRegisterHelpBook(python_app) + except (ImportError, MacOS.Error), arg: + W.Message("Cannot register Python documentation: %s" % `arg`) + return 0 + return 1 + PythonIDE() |