Commit aedd2899 authored by Georg Brandl's avatar Georg Brandl

#6075: make idle work with both Carbon AquaTk and Cocoa AquaTk. Patch by Kevin...

#6075: make idle work with both Carbon AquaTk and Cocoa AquaTk. Patch by Kevin Walzer and Ned Deily.
parent 75043028
...@@ -98,14 +98,6 @@ if macosxSupport.runningAsOSXApp(): ...@@ -98,14 +98,6 @@ if macosxSupport.runningAsOSXApp():
# menu # menu
del menudefs[-1][1][0:2] del menudefs[-1][1][0:2]
menudefs.insert(0,
('application', [
('About IDLE', '<<about-idle>>'),
None,
('_Preferences....', '<<open-config-dialog>>'),
]))
default_keydefs = idleConf.GetCurrentKeySet() default_keydefs = idleConf.GetCurrentKeySet()
del sys del sys
...@@ -387,7 +387,7 @@ class EditorWindow(object): ...@@ -387,7 +387,7 @@ class EditorWindow(object):
underline, label = prepstr(label) underline, label = prepstr(label)
menudict[name] = menu = Menu(mbar, name=name) menudict[name] = menu = Menu(mbar, name=name)
mbar.add_cascade(label=label, menu=menu, underline=underline) mbar.add_cascade(label=label, menu=menu, underline=underline)
if macosxSupport.runningAsOSXApp(): if macosxSupport.isCarbonAquaTk(self.root):
# Insert the application menu # Insert the application menu
menudict['application'] = menu = Menu(mbar, name='apple') menudict['application'] = menu = Menu(mbar, name='apple')
mbar.add_cascade(label='IDLE', menu=menu) mbar.add_cascade(label='IDLE', menu=menu)
......
...@@ -4,6 +4,7 @@ GUI application (as opposed to an X11 application). ...@@ -4,6 +4,7 @@ GUI application (as opposed to an X11 application).
""" """
import sys import sys
import tkinter import tkinter
from os import path
_appbundle = None _appbundle = None
...@@ -19,6 +20,20 @@ def runningAsOSXApp(): ...@@ -19,6 +20,20 @@ def runningAsOSXApp():
_appbundle = (sys.platform == 'darwin' and '.app' in sys.executable) _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable)
return _appbundle return _appbundle
_carbonaquatk = None
def isCarbonAquaTk(root):
"""
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
newer Cocoa Aqua Tk).
"""
global _carbonaquatk
if _carbonaquatk is None:
_carbonaquatk = (runningAsOSXApp() and
'aqua' in root.tk.call('tk', 'windowingsystem') and
'AppKit' not in root.tk.call('winfo', 'server', '.'))
return _carbonaquatk
def addOpenEventSupport(root, flist): def addOpenEventSupport(root, flist):
""" """
This ensures that the application will respont to open AppleEvents, which This ensures that the application will respont to open AppleEvents, which
...@@ -79,9 +94,6 @@ def overrideRootMenu(root, flist): ...@@ -79,9 +94,6 @@ def overrideRootMenu(root, flist):
WindowList.add_windows_to_menu(menu) WindowList.add_windows_to_menu(menu)
WindowList.register_callback(postwindowsmenu) WindowList.register_callback(postwindowsmenu)
menudict['application'] = menu = Menu(menubar, name='apple')
menubar.add_cascade(label='IDLE', menu=menu)
def about_dialog(event=None): def about_dialog(event=None):
from idlelib import aboutDialog from idlelib import aboutDialog
aboutDialog.AboutDialog(root, 'About IDLE') aboutDialog.AboutDialog(root, 'About IDLE')
...@@ -97,9 +109,14 @@ def overrideRootMenu(root, flist): ...@@ -97,9 +109,14 @@ def overrideRootMenu(root, flist):
root.instance_dict = flist.inversedict root.instance_dict = flist.inversedict
configDialog.ConfigDialog(root, 'Settings') configDialog.ConfigDialog(root, 'Settings')
def help_dialog(event=None):
from idlelib import textView
fn = path.join(path.abspath(path.dirname(__file__)), 'help.txt')
textView.view_file(root, 'Help', fn)
root.bind('<<about-idle>>', about_dialog) root.bind('<<about-idle>>', about_dialog)
root.bind('<<open-config-dialog>>', config_dialog) root.bind('<<open-config-dialog>>', config_dialog)
root.createcommand('::tk::mac::ShowPreferences', config_dialog)
if flist: if flist:
root.bind('<<close-all-windows>>', flist.close_all_callback) root.bind('<<close-all-windows>>', flist.close_all_callback)
...@@ -108,35 +125,29 @@ def overrideRootMenu(root, flist): ...@@ -108,35 +125,29 @@ def overrideRootMenu(root, flist):
# right thing for now. # right thing for now.
root.createcommand('exit', flist.close_all_callback) root.createcommand('exit', flist.close_all_callback)
if isCarbonAquaTk(root):
###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding # for Carbon AquaTk, replace the default Tk apple menu
tkversion = root.tk.eval('info patchlevel') menudict['application'] = menu = Menu(menubar, name='apple')
# Note: we cannot check if the string tkversion >= '8.4.14', because menubar.add_cascade(label='IDLE', menu=menu)
# the string '8.4.7' is greater than the string '8.4.14'. Bindings.menudefs.insert(0,
if tuple(map(int, tkversion.split('.'))) >= (8, 4, 14): ('application', [
Bindings.menudefs[0] = ('application', [
('About IDLE', '<<about-idle>>'), ('About IDLE', '<<about-idle>>'),
None, None,
]) ]))
root.createcommand('::tk::mac::ShowPreferences', config_dialog) tkversion = root.tk.eval('info patchlevel')
if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
# for earlier AquaTk versions, supply a Preferences menu item
Bindings.menudefs[0][1].append(
('_Preferences....', '<<open-config-dialog>>'),
)
else: else:
for mname, entrylist in Bindings.menudefs: # assume Cocoa AquaTk
menu = menudict.get(mname) # replace default About dialog with About IDLE one
if not menu: root.createcommand('tkAboutDialog', about_dialog)
continue # replace default "Help" item in Help menu
else: root.createcommand('::tk::mac::ShowHelp', help_dialog)
for entry in entrylist: # remove redundant "IDLE Help" from menu
if not entry: del Bindings.menudefs[-1][1][0]
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): def setupApp(root, flist):
""" """
......
...@@ -881,6 +881,7 @@ Wojtek Walczak ...@@ -881,6 +881,7 @@ Wojtek Walczak
Charles Waldman Charles Waldman
Richard Walker Richard Walker
Larry Wall Larry Wall
Kevin Walzer
Rodrigo Steinmuller Wanderley Rodrigo Steinmuller Wanderley
Greg Ward Greg Ward
Barry Warsaw Barry Warsaw
......
...@@ -93,6 +93,9 @@ Tests ...@@ -93,6 +93,9 @@ Tests
Tools/Demos Tools/Demos
----------- -----------
- Issue #6075: IDLE on Mac OS X now works with both Carbon AquaTk and
Cocoa AquaTk.
- Issue #10710: ``Misc/setuid-prog.c`` is removed from the source tree. - Issue #10710: ``Misc/setuid-prog.c`` is removed from the source tree.
- Issue #10706: Remove outdated script runtests.sh. Either ``make test`` - Issue #10706: Remove outdated script runtests.sh. Either ``make test``
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment