2 A number of function that enhance IDLE on MacOSX when it used as a normal
3 GUI application (as opposed to an X11 application).
11 def runningAsOSXApp():
13 Returns True if Python is running from within an app on OSX.
14 If so, assume that Python was built with Aqua Tcl/Tk rather than
18 if _appbundle
is None:
19 _appbundle
= (sys
.platform
== 'darwin' and '.app' in sys
.executable
)
22 def addOpenEventSupport(root
, flist
):
24 This ensures that the application will respont to open AppleEvents, which
25 makes is feaseable to use IDLE as the default application for python files.
27 def doOpenFile(*args
):
31 # The command below is a hook in aquatk that is called whenever the app
32 # receives a file open event. The callback can have multiple arguments,
33 # one for every file that should be opened.
34 root
.createcommand("::tk::mac::OpenDocument", doOpenFile
)
36 def hideTkConsole(root
):
38 root
.tk
.call('console', 'hide')
39 except Tkinter
.TclError
:
40 # Some versions of the Tk framework don't have a console object
43 def overrideRootMenu(root
, flist
):
45 Replace the Tk root menu by something that's more appropriate for
48 # The menu that is attached to the Tk root (".") is also used by AquaTk for
49 # all windows that don't specify a menu of their own. The default menubar
50 # contains a number of menus, none of which are appropriate for IDLE. The
51 # Most annoying of those is an 'About Tck/Tk...' menu in the application
54 # This function replaces the default menubar by a mostly empty one, it
55 # should only contain the correct application menu and the window menu.
57 # Due to a (mis-)feature of TkAqua the user will also see an empty Help
59 from Tkinter
import Menu
, Text
, Text
60 from EditorWindow
import prepstr
, get_accelerator
63 from MultiCall
import MultiCallCreator
66 root
.configure(menu
=menubar
)
69 menudict
['windows'] = menu
= Menu(menubar
, name
='windows')
70 menubar
.add_cascade(label
='Window', menu
=menu
, underline
=0)
72 def postwindowsmenu(menu
=menu
):
73 end
= menu
.index('end')
79 WindowList
.add_windows_to_menu(menu
)
80 WindowList
.register_callback(postwindowsmenu
)
82 menudict
['application'] = menu
= Menu(menubar
, name
='apple')
83 menubar
.add_cascade(label
='IDLE', menu
=menu
)
85 def about_dialog(event
=None):
87 aboutDialog
.AboutDialog(root
, 'About IDLE')
89 def config_dialog(event
=None):
91 root
.instance_dict
= flist
.inversedict
92 configDialog
.ConfigDialog(root
, 'Settings')
95 root
.bind('<<about-idle>>', about_dialog
)
96 root
.bind('<<open-config-dialog>>', config_dialog
)
98 root
.bind('<<close-all-windows>>', flist
.close_all_callback
)
101 ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding
102 tkversion
= root
.tk
.eval('info patchlevel')
103 # Note: we cannot check if the string tkversion >= '8.4.14', because
104 # the string '8.4.7' is greater than the string '8.4.14'.
105 if tuple(map(int, tkversion
.split('.'))) >= (8, 4, 14):
106 Bindings
.menudefs
[0] = ('application', [
107 ('About IDLE', '<<about-idle>>'),
110 root
.createcommand('::tk::mac::ShowPreferences', config_dialog
)
112 for mname
, entrylist
in Bindings
.menudefs
:
113 menu
= menudict
.get(mname
)
117 for entry
in entrylist
:
121 label
, eventname
= entry
122 underline
, label
= prepstr(label
)
123 accelerator
= get_accelerator(Bindings
.default_keydefs
,
125 def command(text
=root
, eventname
=eventname
):
126 text
.event_generate(eventname
)
127 menu
.add_command(label
=label
, underline
=underline
,
128 command
=command
, accelerator
=accelerator
)
130 def setupApp(root
, flist
):
132 Perform setup for the OSX application bundle.
134 if not runningAsOSXApp(): return
137 overrideRootMenu(root
, flist
)
138 addOpenEventSupport(root
, flist
)