summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/macosxSupport.py
blob: 10b9aa57038e1c5f2eae106fc1b768689f9a008a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
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

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):
    root.tk.call('console', 'hide')


def setupApp(root, flist):
    """
    Perform setup for the OSX application bundle.
    """
    if not runningAsOSXApp(): return

    hideTkConsole(root)
    addOpenEventSupport(root, flist)