Tim Peters | 231c3c8 | 2006-06-11 19:43:49 +0000 | [diff] [blame^] | 1 | """ |
| 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). |
| 4 | """ |
| 5 | import sys |
| 6 | |
| 7 | def 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 | |
| 11 | def 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 | |
| 25 | def hideTkConsole(root): |
| 26 | root.tk.call('console', 'hide') |
| 27 | |
| 28 | |
| 29 | def 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) |