--- /Users/kevin/Python-2.6.2/Lib/idlelib/macosxSupport.py 2009-03-04 16:35:38.000000000 -0500 +++ /Library/Frameworks/Python64.framework/Versions/2.6/lib/python2.6/idlelib/macosxSupport.py 2009-05-21 10:45:38.000000000 -0400 @@ -4,6 +4,7 @@ """ import sys import Tkinter +import os def runningAsOSXApp(): """ @@ -13,6 +14,18 @@ """ return (sys.platform == 'darwin' and '.app' in sys.executable) + +def checkForAppKit(root): + """ + Returns True if Tk is built on top of Cocoa; if false, assume Carbon. + Different API's require different handling of some Mac-specific menu items. + """ + + hasAppKit = root.tk.call('winfo', 'server', '.') + if 'AppKit' in hasAppKit: + return True + + def addOpenEventSupport(root, flist): """ This ensures that the application will respont to open AppleEvents, which @@ -48,7 +61,7 @@ # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # - # Due to a (mis-)feature of TkAqua the user will also see an empty Help + # Due to a (mis-)feature of TkAqua the user may also see an empty Help # menu. from Tkinter import Menu, Text, Text from EditorWindow import prepstr, get_accelerator @@ -59,6 +72,7 @@ menubar = Menu(root) root.configure(menu=menubar) menudict = {} + root.instance_dict = {} menudict['windows'] = menu = Menu(menubar, name='windows') menubar.add_cascade(label='Window', menu=menu, underline=0) @@ -73,9 +87,6 @@ WindowList.add_windows_to_menu(menu) WindowList.register_callback(postwindowsmenu) - menudict['application'] = menu = Menu(menubar, name='apple') - menubar.add_cascade(label='IDLE', menu=menu) - def about_dialog(event=None): import aboutDialog aboutDialog.AboutDialog(root, 'About IDLE') @@ -83,7 +94,58 @@ def config_dialog(event=None): import configDialog configDialog.ConfigDialog(root, 'Settings') - + + def help_dialog(event=None): + import textView + fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt') + helpview = textView.view_file(root,'Help',fn) + + + #set up Tk menu and modify for Mac HIG standards + for mname, entrylist in Bindings.menudefs: + menu = menudict.get(mname) + if not menu: + continue + else: + for entry in entrylist: + if not entry: + menu.add_separator() + else: + label, eventname = entry + underline, label = prepstr(label) + accelerator = get_accelerator(Bindings.default_keydefs, + eventname) + def command(text=root, eventname=eventname): + text.event_generate(eventname) + menu.add_command(label=label, underline=underline, + command=command, accelerator=accelerator) + + + + ###modify help menu and app menu if Tk is built on Cocoa + if checkForAppKit(root): + #map IDLE "about" dialog to "About" item in app menu + root.createcommand('tkAboutDialog', about_dialog) + + #map IDLE Help to default "Help" item in Cocoa help menu and delete duplication element + root.createcommand('::tk::mac::ShowHelp', help_dialog) + Bindings.menudefs[-1]= ('help', [ + ('Python _Docs', '<>'), + ]) + + + ###use traditional "Apple" menu if Tk is built on Carbon + else: + menudict['application'] = menu = Menu(menubar, name='apple') + menubar.add_cascade(label='IDLE', menu=menu) + Bindings.menudefs[0] = ('application', [ + ('About IDLE', '<>'), + None, + ]) + + #move preferences menu to the app menu + root.createcommand('::tk::mac::ShowPreferences', config_dialog) + root.bind('<>', about_dialog) root.bind('<>', config_dialog) @@ -91,35 +153,6 @@ root.bind('<>', flist.close_all_callback) - ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding - tkversion = root.tk.eval('info patchlevel') - # Note: we cannot check if the string tkversion >= '8.4.14', because - # the string '8.4.7' is greater than the string '8.4.14'. - if map(int, tkversion.split('.')) >= (8, 4, 14): - Bindings.menudefs[0] = ('application', [ - ('About IDLE', '<>'), - None, - ]) - root.createcommand('::tk::mac::ShowPreferences', config_dialog) - else: - for mname, entrylist in Bindings.menudefs: - menu = menudict.get(mname) - if not menu: - continue - else: - for entry in entrylist: - if not entry: - menu.add_separator() - else: - label, eventname = entry - underline, label = prepstr(label) - accelerator = get_accelerator(Bindings.default_keydefs, - eventname) - def command(text=root, eventname=eventname): - text.event_generate(eventname) - menu.add_command(label=label, underline=underline, - command=command, accelerator=accelerator) - def setupApp(root, flist): """ Perform setup for the OSX application bundle. @@ -127,5 +160,6 @@ if not runningAsOSXApp(): return hideTkConsole(root) + checkForAppKit(root) overrideRootMenu(root, flist) addOpenEventSupport(root, flist)