blob: 10b9aa57038e1c5f2eae106fc1b768689f9a008a [file] [log] [blame]
Tim Peters231c3c82006-06-11 19:43:49 +00001"""
2A number of function that enhance IDLE on MacOSX when it used as a normal
3GUI application (as opposed to an X11 application).
4"""
5import sys
6
7def runningAsOSXApp():
8 """ Returns True iff running from the IDLE.app bundle on OSX """
9 return (sys.platform == 'darwin' and 'IDLE.app' in sys.argv[0])
10
11def addOpenEventSupport(root, flist):
12 """
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.
15 """
16 def doOpenFile(*args):
17 for fn in args:
18 flist.open(fn)
19
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)
24
25def hideTkConsole(root):
26 root.tk.call('console', 'hide')
27
28
29def setupApp(root, flist):
30 """
31 Perform setup for the OSX application bundle.
32 """
33 if not runningAsOSXApp(): return
34
35 hideTkConsole(root)
36 addOpenEventSupport(root, flist)