diff -u /Users/kevin/Desktop/idle-patches/trunk-orig/Bindings.py /Users/kevin/Desktop/idle-patches/trunk-changed/Bindings.py --- /Users/kevin/Desktop/idle-patches/trunk-orig/Bindings.py 2009-10-10 12:35:31.000000000 -0400 +++ /Users/kevin/Desktop/idle-patches/trunk-changed/Bindings.py 2009-10-10 14:29:48.000000000 -0400 @@ -98,13 +98,6 @@ # menu del menudefs[-1][1][0:2] - menudefs.insert(0, - ('application', [ - ('About IDLE', '<>'), - None, - ('_Preferences....', '<>'), - ])) - default_keydefs = idleConf.GetCurrentKeySet() diff -u /Users/kevin/Desktop/idle-patches/trunk-orig/EditorWindow.py /Users/kevin/Desktop/idle-patches/trunk-changed/EditorWindow.py --- /Users/kevin/Desktop/idle-patches/trunk-orig/EditorWindow.py 2009-10-10 12:35:31.000000000 -0400 +++ /Users/kevin/Desktop/idle-patches/trunk-changed/EditorWindow.py 2009-10-10 14:32:18.000000000 -0400 @@ -385,11 +385,6 @@ menudict[name] = menu = Menu(mbar, name=name) mbar.add_cascade(label=label, menu=menu, underline=underline) - if macosxSupport.runningAsOSXApp(): - # Insert the application menu - menudict['application'] = menu = Menu(mbar, name='apple') - mbar.add_cascade(label='IDLE', menu=menu) - self.fill_menus() self.base_helpmenu_length = self.menudict['help'].index(END) self.reset_help_menu_entries() diff -u /Users/kevin/Desktop/idle-patches/trunk-orig/macosxSupport.py /Users/kevin/Desktop/idle-patches/trunk-changed/macosxSupport.py --- /Users/kevin/Desktop/idle-patches/trunk-orig/macosxSupport.py 2009-10-10 12:35:31.000000000 -0400 +++ /Users/kevin/Desktop/idle-patches/trunk-changed/macosxSupport.py 2009-10-10 14:36:13.000000000 -0400 @@ -13,6 +13,16 @@ """ 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 +58,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 +69,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) @@ -69,22 +80,69 @@ end = -1 if end > 0: - menu.delete(0, end) + menu.delete(0, end) 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') def config_dialog(event=None): import configDialog - root.instance_dict = flist.inversedict configDialog.ConfigDialog(root, 'Settings') - + + def help_dialog(event=None): + import textView + fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt') + 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) @@ -92,34 +150,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 tuple(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): """ @@ -128,5 +158,6 @@ if not runningAsOSXApp(): return hideTkConsole(root) + checkForAppKit(root) overrideRootMenu(root, flist) addOpenEventSupport(root, flist)