mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
  r56454 | kurt.kaiser | 2007-07-18 22:26:14 -0700 (Wed, 18 Jul 2007) | 2 lines
  Make relative imports explicit for py3k
................
  r56455 | kurt.kaiser | 2007-07-18 23:12:15 -0700 (Wed, 18 Jul 2007) | 2 lines
  Was modifying dict during iteration.
................
  r56457 | guido.van.rossum | 2007-07-19 07:33:19 -0700 (Thu, 19 Jul 2007) | 2 lines
  Fix failing test.
................
  r56466 | guido.van.rossum | 2007-07-19 20:58:16 -0700 (Thu, 19 Jul 2007) | 35 lines
  Merged revisions 56413-56465 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ........
    r56439 | georg.brandl | 2007-07-17 23:37:55 -0700 (Tue, 17 Jul 2007) | 2 lines
    Use "Unix" as platform name, not "UNIX".
  ........
    r56441 | guido.van.rossum | 2007-07-18 10:19:14 -0700 (Wed, 18 Jul 2007) | 3 lines
    SF patch# 1755885 by Kurt Kaiser: show location of Unicode escape errors.
    (Slightly tweaked for style and refcounts.)
  ........
    r56444 | kurt.kaiser | 2007-07-18 12:58:42 -0700 (Wed, 18 Jul 2007) | 2 lines
    Fix failing unicode test caused by change to ast.c at r56441
  ........
    r56451 | georg.brandl | 2007-07-18 15:36:53 -0700 (Wed, 18 Jul 2007) | 2 lines
    Add description for wave.setcomptype() values
  ........
    r56456 | walter.doerwald | 2007-07-19 06:04:38 -0700 (Thu, 19 Jul 2007) | 3 lines
    Document that codecs.lookup() returns a CodecInfo object.
    (fixes SF bug #1754453).
  ........
    r56463 | facundo.batista | 2007-07-19 16:57:38 -0700 (Thu, 19 Jul 2007) | 6 lines
    Added a select.select call in the test server loop to make sure the
    socket is ready to be read from before attempting a read (this
    prevents an error 10035 on some Windows platforms). [GSoC - Alan
    McIntyre]
  ........
................
		
	
			
		
			
				
	
	
		
			125 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""
 | 
						|
A number of function that enhance IDLE on MacOSX when it used as a normal
 | 
						|
GUI application (as opposed to an X11 application).
 | 
						|
"""
 | 
						|
import sys
 | 
						|
import Tkinter
 | 
						|
 | 
						|
def runningAsOSXApp():
 | 
						|
    """ Returns True iff running from the IDLE.app bundle on OSX """
 | 
						|
    return (sys.platform == 'darwin' and 'IDLE.app' in sys.argv[0])
 | 
						|
 | 
						|
def addOpenEventSupport(root, flist):
 | 
						|
    """
 | 
						|
    This ensures that the application will respont to open AppleEvents, which
 | 
						|
    makes is feaseable to use IDLE as the default application for python files.
 | 
						|
    """
 | 
						|
    def doOpenFile(*args):
 | 
						|
        for fn in args:
 | 
						|
            flist.open(fn)
 | 
						|
 | 
						|
    # The command below is a hook in aquatk that is called whenever the app
 | 
						|
    # receives a file open event. The callback can have multiple arguments,
 | 
						|
    # one for every file that should be opened.
 | 
						|
    root.createcommand("::tk::mac::OpenDocument", doOpenFile)
 | 
						|
 | 
						|
def hideTkConsole(root):
 | 
						|
    try:
 | 
						|
        root.tk.call('console', 'hide')
 | 
						|
    except Tkinter.TclError:
 | 
						|
        # Some versions of the Tk framework don't have a console object
 | 
						|
        pass
 | 
						|
 | 
						|
def overrideRootMenu(root, flist):
 | 
						|
    """
 | 
						|
    Replace the Tk root menu by something that's more appropriate for
 | 
						|
    IDLE.
 | 
						|
    """
 | 
						|
    # The menu that is attached to the Tk root (".") is also used by AquaTk for
 | 
						|
    # all windows that don't specify a menu of their own. The default menubar
 | 
						|
    # contains a number of menus, none of which are appropriate for IDLE. The
 | 
						|
    # Most annoying of those is an 'About Tck/Tk...' menu in the application
 | 
						|
    # menu.
 | 
						|
    #
 | 
						|
    # 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
 | 
						|
    # menu.
 | 
						|
    from Tkinter import Menu, Text, Text
 | 
						|
    from .EditorWindow import prepstr, get_accelerator
 | 
						|
    from . import Bindings
 | 
						|
    from . import WindowList
 | 
						|
    from .MultiCall import MultiCallCreator
 | 
						|
 | 
						|
    menubar = Menu(root)
 | 
						|
    root.configure(menu=menubar)
 | 
						|
    menudict = {}
 | 
						|
 | 
						|
    menudict['windows'] = menu = Menu(menubar, name='windows')
 | 
						|
    menubar.add_cascade(label='Window', menu=menu, underline=0)
 | 
						|
 | 
						|
    def postwindowsmenu(menu=menu):
 | 
						|
        end = menu.index('end')
 | 
						|
        if end is None:
 | 
						|
            end = -1
 | 
						|
 | 
						|
        if end > 0:
 | 
						|
            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):
 | 
						|
        from . import aboutDialog
 | 
						|
        aboutDialog.AboutDialog(root, 'About IDLE')
 | 
						|
 | 
						|
    def config_dialog(event=None):
 | 
						|
        from . import configDialog
 | 
						|
        configDialog.ConfigDialog(root, 'Settings')
 | 
						|
 | 
						|
 | 
						|
    root.bind('<<about-idle>>', about_dialog)
 | 
						|
    root.bind('<<open-config-dialog>>', config_dialog)
 | 
						|
    if flist:
 | 
						|
        root.bind('<<close-all-windows>>', flist.close_all_callback)
 | 
						|
 | 
						|
 | 
						|
    ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding
 | 
						|
    tkversion = root.tk.eval('info patchlevel')
 | 
						|
    if tkversion >= '8.4.14':
 | 
						|
        Bindings.menudefs[0] =  ('application', [
 | 
						|
                ('About IDLE', '<<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):
 | 
						|
    """
 | 
						|
    Perform setup for the OSX application bundle.
 | 
						|
    """
 | 
						|
    if not runningAsOSXApp(): return
 | 
						|
 | 
						|
    hideTkConsole(root)
 | 
						|
    overrideRootMenu(root, flist)
 | 
						|
    addOpenEventSupport(root, flist)
 |