@@ -145,6 +145,7 @@ def makeusermenus(self):
145145 self ._scripts = {}
146146 self .scriptsmenu = None
147147 self .makescriptsmenu ()
148+ self .makehelpmenu ()
148149
149150 def quitevent (self , theAppleEvent , theReply ):
150151 from Carbon import AE
@@ -278,6 +279,107 @@ def _quit(self):
278279 if rv and rv > 0 :
279280 return
280281 self .quitting = 1
282+
283+ def makehelpmenu (self ):
284+ docs = self .installdocumentation ()
285+ self .helpmenu = m = self .gethelpmenu ()
286+ docitem = FrameWork .MenuItem (m , "Python Documentation" , None , self .domenu_localdocs )
287+ docitem .enable (docs )
288+ doc2item = FrameWork .MenuItem (m , "Apple Developer Documentation" , None , self .domenu_appledocs )
289+ FrameWork .Separator (m )
290+ finditem = FrameWork .MenuItem (m , "Lookup in Python Documentation" , None , 'lookuppython' )
291+ finditem .enable (docs )
292+ find2item = FrameWork .MenuItem (m , "Lookup in Carbon Documentation" , None , 'lookupcarbon' )
293+ FrameWork .Separator (m )
294+ webitem = FrameWork .MenuItem (m , "Python Documentation on the Web" , None , self .domenu_webdocs )
295+ web2item = FrameWork .MenuItem (m , "Python on the Web" , None , self .domenu_webpython )
296+ web3item = FrameWork .MenuItem (m , "MacPython on the Web" , None , self .domenu_webmacpython )
297+
298+ def domenu_localdocs (self , * args ):
299+ from Carbon import AH
300+ AH .AHGotoPage ("Python Help" , "index.html" , "" )
301+
302+ def domenu_appledocs (self , * args ):
303+ from Carbon import AH , AppleHelp
304+ try :
305+ AH .AHGotoMainTOC (AppleHelp .kAHTOCTypeDeveloper )
306+ except AH .Error , arg :
307+ if arg [0 ] == - 50 :
308+ W .Message ("Developer documentation not installed" )
309+ else :
310+ W .Message ("AppleHelp Error: %s" % `arg` )
311+
312+ def domenu_lookuppython (self , * args ):
313+ from Carbon import AH
314+ searchstring = self ._getsearchstring ()
315+ if not searchstring :
316+ return
317+ try :
318+ AH .AHSearch ("Python Help" , searchstring )
319+ except AH .Error , arg :
320+ W .Message ("AppleHelp Error: %s" % `arg` )
321+
322+ def domenu_lookupcarbon (self , * args ):
323+ from Carbon import AH
324+ searchstring = self ._getsearchstring ()
325+ if not searchstring :
326+ return
327+ try :
328+ AH .AHSearch ("Carbon" , searchstring )
329+ except AH .Error , arg :
330+ W .Message ("AppleHelp Error: %s" % `arg` )
331+
332+ def _getsearchstring (self ):
333+ import PyEdit
334+ editor = PyEdit .findeditor (None , fromtop = 1 )
335+ if editor :
336+ text = editor .getselectedtext ()
337+ if text :
338+ return text
339+ # This is a cop-out. We should have disabled the menus
340+ # if there is no selection, but the can_ methods only seem
341+ # to work for Windows. Or not for the Help menu, maybe?
342+ import EasyDialogs
343+ text = EasyDialogs .AskString ("Search documentation for" , ok = "Search" )
344+ return text
345+
346+ def domenu_webdocs (self , * args ):
347+ import webbrowser
348+ major , minor , micro , state , nano = sys .version_info
349+ if state in ('alpha' , 'beta' ):
350+ docversion = 'dev/doc/devel'
351+ elif micro == 0 :
352+ docversion = 'doc/%d.%d' % (major , minor )
353+ else :
354+ docversion = 'doc/%d.%d.%d' % (major , minor , micro )
355+ webbrowser .open ("http://www.python.org/%s" % docversion )
356+
357+ def domenu_webpython (self , * args ):
358+ import webbrowser
359+ webbrowser .open ("http://www.python.org/" )
360+
361+ def domenu_webmacpython (self , * args ):
362+ import webbrowser
363+ webbrowser .open ("http://www.cwi.nl/~jack/macpython.html" )
364+
365+ def installdocumentation (self ):
366+ # This is rather much of a hack. Someone has to tell the Help Viewer
367+ # about the Python documentation, so why not us. The documentation
368+ # is located in the framework, but there's a symlink in Python.app.
369+ # And as AHRegisterHelpBook wants a bundle (with the right bits in
370+ # the plist file) we refer it to Python.app
371+ python_app = os .path .join (sys .prefix , 'Resources/Python.app' )
372+ doc_source = os .path .join (python_app , 'Contents/Resources/English.lproj/Documentation' )
373+ if not os .path .isdir (doc_source ):
374+ return 0
375+ try :
376+ from Carbon import AH
377+ AH .AHRegisterHelpBook (python_app )
378+ except (ImportError , MacOS .Error ), arg :
379+ W .Message ("Cannot register Python documentation: %s" % `arg` )
380+ return 0
381+ return 1
382+
281383
282384PythonIDE ()
283385
0 commit comments