Back to index

python3.2  3.2.2
Functions | Variables
idlelib.macosxSupport Namespace Reference

Functions

def runningAsOSXApp
def isCarbonAquaTk
def tkVersionWarning
def addOpenEventSupport
def hideTkConsole
def overrideRootMenu
def setupApp

Variables

 _appbundle = None
 _carbonaquatk = None

Detailed Description

A number of function that enhance IDLE on MacOSX when it used as a normal
GUI application (as opposed to an X11 application).

Function Documentation

def idlelib.macosxSupport.addOpenEventSupport (   root,
  flist 
)
This ensures that the application will respond to open AppleEvents, which
makes is feasible to use IDLE as the default application for python files.

Definition at line 54 of file macosxSupport.py.

00054 
00055 def addOpenEventSupport(root, flist):
00056     """
00057     This ensures that the application will respond to open AppleEvents, which
00058     makes is feasible to use IDLE as the default application for python files.
00059     """
00060     def doOpenFile(*args):
00061         for fn in args:
00062             flist.open(fn)
00063 
00064     # The command below is a hook in aquatk that is called whenever the app
00065     # receives a file open event. The callback can have multiple arguments,
00066     # one for every file that should be opened.
00067     root.createcommand("::tk::mac::OpenDocument", doOpenFile)

Here is the caller graph for this function:

Definition at line 68 of file macosxSupport.py.

00068 
00069 def hideTkConsole(root):
00070     try:
00071         root.tk.call('console', 'hide')
00072     except tkinter.TclError:
00073         # Some versions of the Tk framework don't have a console object
00074         pass

Here is the caller graph for this function:

Returns True if IDLE is using a Carbon Aqua Tk (instead of the
newer Cocoa Aqua Tk).

Definition at line 25 of file macosxSupport.py.

00025 
00026 def isCarbonAquaTk(root):
00027     """
00028     Returns True if IDLE is using a Carbon Aqua Tk (instead of the
00029     newer Cocoa Aqua Tk).
00030     """
00031     global _carbonaquatk
00032     if _carbonaquatk is None:
00033         _carbonaquatk = (runningAsOSXApp() and
00034                          'aqua' in root.tk.call('tk', 'windowingsystem') and
00035                          'AppKit' not in root.tk.call('winfo', 'server', '.'))
00036     return _carbonaquatk

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.macosxSupport.overrideRootMenu (   root,
  flist 
)
Replace the Tk root menu by something that's more appropriate for
IDLE.

Definition at line 75 of file macosxSupport.py.

00075 
00076 def overrideRootMenu(root, flist):
00077     """
00078     Replace the Tk root menu by something that's more appropriate for
00079     IDLE.
00080     """
00081     # The menu that is attached to the Tk root (".") is also used by AquaTk for
00082     # all windows that don't specify a menu of their own. The default menubar
00083     # contains a number of menus, none of which are appropriate for IDLE. The
00084     # Most annoying of those is an 'About Tck/Tk...' menu in the application
00085     # menu.
00086     #
00087     # This function replaces the default menubar by a mostly empty one, it
00088     # should only contain the correct application menu and the window menu.
00089     #
00090     # Due to a (mis-)feature of TkAqua the user will also see an empty Help
00091     # menu.
00092     from tkinter import Menu, Text, Text
00093     from idlelib.EditorWindow import prepstr, get_accelerator
00094     from idlelib import Bindings
00095     from idlelib import WindowList
00096     from idlelib.MultiCall import MultiCallCreator
00097 
00098     menubar = Menu(root)
00099     root.configure(menu=menubar)
00100     menudict = {}
00101 
00102     menudict['windows'] = menu = Menu(menubar, name='windows')
00103     menubar.add_cascade(label='Window', menu=menu, underline=0)
00104 
00105     def postwindowsmenu(menu=menu):
00106         end = menu.index('end')
00107         if end is None:
00108             end = -1
00109 
00110         if end > 0:
00111             menu.delete(0, end)
00112         WindowList.add_windows_to_menu(menu)
00113     WindowList.register_callback(postwindowsmenu)
00114 
00115     def about_dialog(event=None):
00116         from idlelib import aboutDialog
00117         aboutDialog.AboutDialog(root, 'About IDLE')
00118 
00119     def config_dialog(event=None):
00120         from idlelib import configDialog
00121 
00122         # Ensure that the root object has an instance_dict attribute,
00123         # mirrors code in EditorWindow (although that sets the attribute
00124         # on an EditorWindow instance that is then passed as the first
00125         # argument to ConfigDialog)
00126         root.instance_dict = flist.inversedict
00127         root.instance_dict = flist.inversedict
00128         configDialog.ConfigDialog(root, 'Settings')
00129 
00130     def help_dialog(event=None):
00131         from idlelib import textView
00132         fn = path.join(path.abspath(path.dirname(__file__)), 'help.txt')
00133         textView.view_file(root, 'Help', fn)
00134 
00135     root.bind('<<about-idle>>', about_dialog)
00136     root.bind('<<open-config-dialog>>', config_dialog)
00137     root.createcommand('::tk::mac::ShowPreferences', config_dialog)
00138     if flist:
00139         root.bind('<<close-all-windows>>', flist.close_all_callback)
00140 
00141         # The binding above doesn't reliably work on all versions of Tk
00142         # on MacOSX. Adding command definition below does seem to do the
00143         # right thing for now.
00144         root.createcommand('exit', flist.close_all_callback)
00145 
00146     if isCarbonAquaTk(root):
00147         # for Carbon AquaTk, replace the default Tk apple menu
00148         menudict['application'] = menu = Menu(menubar, name='apple')
00149         menubar.add_cascade(label='IDLE', menu=menu)
00150         Bindings.menudefs.insert(0,
00151             ('application', [
00152                 ('About IDLE', '<<about-idle>>'),
00153                     None,
00154                 ]))
00155         tkversion = root.tk.eval('info patchlevel')
00156         if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
00157             # for earlier AquaTk versions, supply a Preferences menu item
00158             Bindings.menudefs[0][1].append(
00159                     ('_Preferences....', '<<open-config-dialog>>'),
00160                 )
00161     else:
00162         # assume Cocoa AquaTk
00163         # replace default About dialog with About IDLE one
00164         root.createcommand('tkAboutDialog', about_dialog)
00165         # replace default "Help" item in Help menu
00166         root.createcommand('::tk::mac::ShowHelp', help_dialog)
00167         # remove redundant "IDLE Help" from menu
00168         del Bindings.menudefs[-1][1][0]

Here is the call graph for this function:

Here is the caller graph for this function:

Returns True if Python is running from within an app on OSX.
If so, assume that Python was built with Aqua Tcl/Tk rather than
X11 Tcl/Tk.

Definition at line 12 of file macosxSupport.py.

00012 
00013 def runningAsOSXApp():
00014     """
00015     Returns True if Python is running from within an app on OSX.
00016     If so, assume that Python was built with Aqua Tcl/Tk rather than
00017     X11 Tcl/Tk.
00018     """
00019     global _appbundle
00020     if _appbundle is None:
00021         _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable)
00022     return _appbundle

Here is the caller graph for this function:

def idlelib.macosxSupport.setupApp (   root,
  flist 
)
Perform setup for the OSX application bundle.

Definition at line 169 of file macosxSupport.py.

00169 
00170 def setupApp(root, flist):
00171     """
00172     Perform setup for the OSX application bundle.
00173     """
00174     if not runningAsOSXApp(): return
00175 
00176     hideTkConsole(root)
00177     overrideRootMenu(root, flist)
00178     addOpenEventSupport(root, flist)

Here is the call graph for this function:

Returns a string warning message if the Tk version in use appears to
be one known to cause problems with IDLE.  The Apple Cocoa-based Tk 8.5
that was shipped with Mac OS X 10.6.

Definition at line 37 of file macosxSupport.py.

00037 
00038 def tkVersionWarning(root):
00039     """
00040     Returns a string warning message if the Tk version in use appears to
00041     be one known to cause problems with IDLE.  The Apple Cocoa-based Tk 8.5
00042     that was shipped with Mac OS X 10.6.
00043     """
00044 
00045     if (runningAsOSXApp() and
00046             ('AppKit' in root.tk.call('winfo', 'server', '.')) and
00047             (root.tk.call('info', 'patchlevel') == '8.5.7') ):
00048         return (r"WARNING: The version of Tcl/Tk (8.5.7) in use may"
00049                 r" be unstable.\n"
00050                 r"Visit http://www.python.org/download/mac/tcltk/"
00051                 r" for current information.")
00052     else:
00053         return False

Here is the call graph for this function:


Variable Documentation

Definition at line 10 of file macosxSupport.py.

Definition at line 23 of file macosxSupport.py.