[Python-checkins] r88090 - in python/branches/release27-maint: Lib/idlelib/Bindings.py Lib/idlelib/EditorWindow.py Lib/idlelib/macosxSupport.py Misc/ACKS Misc/NEWS

ned.deily python-checkins at python.org
Tue Jan 18 05:33:22 CET 2011


Author: ned.deily
Date: Tue Jan 18 05:33:22 2011
New Revision: 88090

Log:
Merged revisions 87394 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87394 | georg.brandl | 2010-12-19 02:10:32 -0800 (Sun, 19 Dec 2010) | 1 line
  
  #6075: make idle work with both Carbon AquaTk and Cocoa AquaTk. Patch by Kevin Walzer and Ned Deily.
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/idlelib/Bindings.py
   python/branches/release27-maint/Lib/idlelib/EditorWindow.py
   python/branches/release27-maint/Lib/idlelib/macosxSupport.py
   python/branches/release27-maint/Misc/ACKS
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/idlelib/Bindings.py
==============================================================================
--- python/branches/release27-maint/Lib/idlelib/Bindings.py	(original)
+++ python/branches/release27-maint/Lib/idlelib/Bindings.py	Tue Jan 18 05:33:22 2011
@@ -98,14 +98,6 @@
     # menu
     del menudefs[-1][1][0:2]
 
-    menudefs.insert(0,
-            ('application', [
-                ('About IDLE', '<<about-idle>>'),
-                None,
-                ('_Preferences....', '<<open-config-dialog>>'),
-            ]))
-
-
 default_keydefs = idleConf.GetCurrentKeySet()
 
 del sys

Modified: python/branches/release27-maint/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/branches/release27-maint/Lib/idlelib/EditorWindow.py	(original)
+++ python/branches/release27-maint/Lib/idlelib/EditorWindow.py	Tue Jan 18 05:33:22 2011
@@ -392,7 +392,7 @@
             menudict[name] = menu = Menu(mbar, name=name)
             mbar.add_cascade(label=label, menu=menu, underline=underline)
 
-        if macosxSupport.runningAsOSXApp():
+        if macosxSupport.isCarbonAquaTk(self.root):
             # Insert the application menu
             menudict['application'] = menu = Menu(mbar, name='apple')
             mbar.add_cascade(label='IDLE', menu=menu)

Modified: python/branches/release27-maint/Lib/idlelib/macosxSupport.py
==============================================================================
--- python/branches/release27-maint/Lib/idlelib/macosxSupport.py	(original)
+++ python/branches/release27-maint/Lib/idlelib/macosxSupport.py	Tue Jan 18 05:33:22 2011
@@ -4,6 +4,7 @@
 """
 import sys
 import Tkinter
+from os import path
 
 
 _appbundle = None
@@ -19,6 +20,20 @@
         _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable)
     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):
     """
     This ensures that the application will respont to open AppleEvents, which
@@ -79,9 +94,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):
         from idlelib import aboutDialog
         aboutDialog.AboutDialog(root, 'About IDLE')
@@ -91,9 +103,14 @@
         root.instance_dict = flist.inversedict
         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('<<open-config-dialog>>', config_dialog)
+    root.createcommand('::tk::mac::ShowPreferences', config_dialog)
     if flist:
         root.bind('<<close-all-windows>>', flist.close_all_callback)
 
@@ -102,35 +119,29 @@
         # right thing for now.
         root.createcommand('exit', 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', [
+    if isCarbonAquaTk(root):
+        # for Carbon AquaTk, replace the default Tk apple menu
+        menudict['application'] = menu = Menu(menubar, name='apple')
+        menubar.add_cascade(label='IDLE', menu=menu)
+        Bindings.menudefs.insert(0,
+            ('application', [
                 ('About IDLE', '<<about-idle>>'),
-                None,
-            ])
-        root.createcommand('::tk::mac::ShowPreferences', config_dialog)
+                    None,
+                ]))
+        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:
-        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)
+        # assume Cocoa AquaTk
+        # replace default About dialog with About IDLE one
+        root.createcommand('tkAboutDialog', about_dialog)
+        # replace default "Help" item in Help menu
+        root.createcommand('::tk::mac::ShowHelp', help_dialog)
+        # remove redundant "IDLE Help" from menu
+        del Bindings.menudefs[-1][1][0]
 
 def setupApp(root, flist):
     """

Modified: python/branches/release27-maint/Misc/ACKS
==============================================================================
--- python/branches/release27-maint/Misc/ACKS	(original)
+++ python/branches/release27-maint/Misc/ACKS	Tue Jan 18 05:33:22 2011
@@ -834,6 +834,7 @@
 Charles Waldman
 Richard Walker
 Larry Wall
+Kevin Walzer
 Greg Ward
 Barry Warsaw
 Steve Waterbury

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Tue Jan 18 05:33:22 2011
@@ -32,6 +32,9 @@
 Library
 -------
 
+- Issue #6075: IDLE on Mac OS X now works with both Carbon AquaTk and
+  Cocoa AquaTk.
+
 - Issue #10916: mmap should not segfault when a file is mapped using 0 as
   length and a non-zero offset, and an attempt to read past the end of file
   is made (IndexError is raised instead).  Patch by Ross Lagerwall.


More information about the Python-checkins mailing list