Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/macosxSupport.py

    r2 r391  
    55import sys
    66import Tkinter
     7from os import path
     8
     9
     10_appbundle = None
    711
    812def runningAsOSXApp():
     
    1014    Returns True if Python is running from within an app on OSX.
    1115    If so, assume that Python was built with Aqua Tcl/Tk rather than
    12     X11 Tck/Tk.
     16    X11 Tcl/Tk.
    1317    """
    14     return (sys.platform == 'darwin' and '.app' in sys.executable)
     18    global _appbundle
     19    if _appbundle is None:
     20        _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable)
     21    return _appbundle
     22
     23_carbonaquatk = None
     24
     25def isCarbonAquaTk(root):
     26    """
     27    Returns True if IDLE is using a Carbon Aqua Tk (instead of the
     28    newer Cocoa Aqua Tk).
     29    """
     30    global _carbonaquatk
     31    if _carbonaquatk is None:
     32        _carbonaquatk = (runningAsOSXApp() and
     33                         'aqua' in root.tk.call('tk', 'windowingsystem') and
     34                         'AppKit' not in root.tk.call('winfo', 'server', '.'))
     35    return _carbonaquatk
     36
     37def tkVersionWarning(root):
     38    """
     39    Returns a string warning message if the Tk version in use appears to
     40    be one known to cause problems with IDLE.
     41    1. Apple Cocoa-based Tk 8.5.7 shipped with Mac OS X 10.6 is unusable.
     42    2. Apple Cocoa-based Tk 8.5.9 in OS X 10.7 and 10.8 is better but
     43        can still crash unexpectedly.
     44    """
     45
     46    if (runningAsOSXApp() and
     47            ('AppKit' in root.tk.call('winfo', 'server', '.')) ):
     48        patchlevel = root.tk.call('info', 'patchlevel')
     49        if patchlevel not in ('8.5.7', '8.5.9'):
     50            return False
     51        return (r"WARNING: The version of Tcl/Tk ({0}) in use may"
     52                r" be unstable.\n"
     53                r"Visit http://www.python.org/download/mac/tcltk/"
     54                r" for current information.".format(patchlevel))
     55    else:
     56        return False
    1557
    1658def addOpenEventSupport(root, flist):
    1759    """
    18     This ensures that the application will respont to open AppleEvents, which
    19     makes is feaseable to use IDLE as the default application for python files.
     60    This ensures that the application will respond to open AppleEvents, which
     61    makes is feasible to use IDLE as the default application for python files.
    2062    """
    2163    def doOpenFile(*args):
     
    5294    # menu.
    5395    from Tkinter import Menu, Text, Text
    54     from EditorWindow import prepstr, get_accelerator
    55     import Bindings
    56     import WindowList
    57     from MultiCall import MultiCallCreator
     96    from idlelib.EditorWindow import prepstr, get_accelerator
     97    from idlelib import Bindings
     98    from idlelib import WindowList
     99    from idlelib.MultiCall import MultiCallCreator
    58100
    59101    menubar = Menu(root)
     
    74116    WindowList.register_callback(postwindowsmenu)
    75117
    76     menudict['application'] = menu = Menu(menubar, name='apple')
    77     menubar.add_cascade(label='IDLE', menu=menu)
    78 
    79118    def about_dialog(event=None):
    80         import aboutDialog
     119        from idlelib import aboutDialog
    81120        aboutDialog.AboutDialog(root, 'About IDLE')
    82121
    83122    def config_dialog(event=None):
    84         import configDialog
     123        from idlelib import configDialog
    85124        root.instance_dict = flist.inversedict
    86125        configDialog.ConfigDialog(root, 'Settings')
    87126
     127    def help_dialog(event=None):
     128        from idlelib import textView
     129        fn = path.join(path.abspath(path.dirname(__file__)), 'help.txt')
     130        textView.view_file(root, 'Help', fn)
    88131
    89132    root.bind('<<about-idle>>', about_dialog)
    90133    root.bind('<<open-config-dialog>>', config_dialog)
     134    root.createcommand('::tk::mac::ShowPreferences', config_dialog)
    91135    if flist:
    92136        root.bind('<<close-all-windows>>', flist.close_all_callback)
    93137
     138        # The binding above doesn't reliably work on all versions of Tk
     139        # on MacOSX. Adding command definition below does seem to do the
     140        # right thing for now.
     141        root.createcommand('exit', flist.close_all_callback)
    94142
    95     ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding
    96     tkversion = root.tk.eval('info patchlevel')
    97     # Note: we cannot check if the string tkversion >= '8.4.14', because
    98     # the string '8.4.7' is greater than the string '8.4.14'.
    99     if tuple(map(int, tkversion.split('.'))) >= (8, 4, 14):
    100         Bindings.menudefs[0] =  ('application', [
     143    if isCarbonAquaTk(root):
     144        # for Carbon AquaTk, replace the default Tk apple menu
     145        menudict['application'] = menu = Menu(menubar, name='apple')
     146        menubar.add_cascade(label='IDLE', menu=menu)
     147        Bindings.menudefs.insert(0,
     148            ('application', [
    101149                ('About IDLE', '<<about-idle>>'),
    102                 None,
    103             ])
    104         root.createcommand('::tk::mac::ShowPreferences', config_dialog)
     150                    None,
     151                ]))
     152        tkversion = root.tk.eval('info patchlevel')
     153        if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
     154            # for earlier AquaTk versions, supply a Preferences menu item
     155            Bindings.menudefs[0][1].append(
     156                    ('_Preferences....', '<<open-config-dialog>>'),
     157                )
    105158    else:
    106         for mname, entrylist in Bindings.menudefs:
    107             menu = menudict.get(mname)
    108             if not menu:
    109                 continue
    110             else:
    111                 for entry in entrylist:
    112                     if not entry:
    113                         menu.add_separator()
    114                     else:
    115                         label, eventname = entry
    116                         underline, label = prepstr(label)
    117                         accelerator = get_accelerator(Bindings.default_keydefs,
    118                         eventname)
    119                         def command(text=root, eventname=eventname):
    120                             text.event_generate(eventname)
    121                         menu.add_command(label=label, underline=underline,
    122                         command=command, accelerator=accelerator)
     159        # assume Cocoa AquaTk
     160        # replace default About dialog with About IDLE one
     161        root.createcommand('tkAboutDialog', about_dialog)
     162        # replace default "Help" item in Help menu
     163        root.createcommand('::tk::mac::ShowHelp', help_dialog)
     164        # remove redundant "IDLE Help" from menu
     165        del Bindings.menudefs[-1][1][0]
    123166
    124167def setupApp(root, flist):
Note: See TracChangeset for help on using the changeset viewer.