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).
8 """ Returns True iff running from the IDLE.app bundle on OSX """
9 return (sys
.platform
== 'darwin' and 'IDLE.app' in sys
.argv
[0])
11 def addOpenEventSupport(root
, flist
):
13 This ensures that the application will respont to open AppleEvents, which
14 makes is feaseable to use IDLE as the default application for python files.
16 def doOpenFile(*args
):
20 # The command below is a hook in aquatk that is called whenever the app
21 # receives a file open event. The callback can have multiple arguments,
22 # one for every file that should be opened.
23 root
.createcommand("::tk::mac::OpenDocument", doOpenFile
)
25 def hideTkConsole(root
):
26 root
.tk
.call('console', 'hide')
28 def overrideRootMenu(root
, flist
):
30 Replace the Tk root menu by something that's more appropriate for
33 # The menu that is attached to the Tk root (".") is also used by AquaTk for
34 # all windows that don't specify a menu of their own. The default menubar
35 # contains a number of menus, none of which are appropriate for IDLE. The
36 # Most annoying of those is an 'About Tck/Tk...' menu in the application
39 # This function replaces the default menubar by a mostly empty one, it
40 # should only contain the correct application menu and the window menu.
42 # Due to a (mis-)feature of TkAqua the user will also see an empty Help
44 from Tkinter
import Menu
, Text
, Text
45 from EditorWindow
import prepstr
, get_accelerator
48 from MultiCall
import MultiCallCreator
51 root
.configure(menu
=menubar
)
54 menudict
['windows'] = menu
= Menu(menubar
, name
='windows')
55 menubar
.add_cascade(label
='Window', menu
=menu
, underline
=0)
57 def postwindowsmenu(menu
=menu
):
58 end
= menu
.index('end')
64 WindowList
.add_windows_to_menu(menu
)
65 WindowList
.register_callback(postwindowsmenu
)
67 menudict
['application'] = menu
= Menu(menubar
, name
='apple')
68 menubar
.add_cascade(label
='IDLE', menu
=menu
)
70 def about_dialog(event
=None):
72 aboutDialog
.AboutDialog(root
, 'About IDLE')
74 def config_dialog(event
=None):
76 configDialog
.ConfigDialog(root
, 'Settings')
78 root
.bind('<<about-idle>>', about_dialog
)
79 root
.bind('<<open-config-dialog>>', config_dialog
)
81 root
.bind('<<close-all-windows>>', flist
.close_all_callback
)
83 for mname
, entrylist
in Bindings
.menudefs
:
84 menu
= menudict
.get(mname
)
87 for entry
in entrylist
:
91 label
, eventname
= entry
92 underline
, label
= prepstr(label
)
93 accelerator
= get_accelerator(Bindings
.default_keydefs
,
95 def command(text
=root
, eventname
=eventname
):
96 text
.event_generate(eventname
)
97 menu
.add_command(label
=label
, underline
=underline
,
98 command
=command
, accelerator
=accelerator
)
104 def setupApp(root
, flist
):
106 Perform setup for the OSX application bundle.
108 if not runningAsOSXApp(): return
111 overrideRootMenu(root
, flist
)
112 addOpenEventSupport(root
, flist
)