Jack Jansen | 6ad8d13 | 1997-01-15 16:53:37 +0000 | [diff] [blame] | 1 | <HTML> |
| 2 | <HEAD> |
| 3 | <TITLE>Embedding Python on the Mac</TITLE> |
| 4 | </HEAD> |
| 5 | <BODY> |
| 6 | <H1>Embedding Python on the Mac</H1> |
| 7 | <HR> |
Jack Jansen | ae4300f | 1998-01-06 16:50:44 +0000 | [diff] [blame] | 8 | <B>Note</B>: if you have a binary-only release of MacPython you will not |
Jack Jansen | e67dab3 | 2001-10-09 23:14:06 +0000 | [diff] [blame^] | 9 | have this demo installed. Install the developer option (in the standard installer) or |
| 10 | a source release if you want to embed |
Jack Jansen | ae4300f | 1998-01-06 16:50:44 +0000 | [diff] [blame] | 11 | Python in other applications. <p> |
Jack Jansen | 6ad8d13 | 1997-01-15 16:53:37 +0000 | [diff] [blame] | 12 | |
| 13 | Embedding Python on the mac is pretty similar to embedding it on other |
| 14 | platforms, but a few points need mentioning: |
| 15 | |
| 16 | <UL> |
| 17 | <LI> You call <CODE>PyMac_Initialize()</CODE> in stead of |
| 18 | <CODE>Py_Initialize()</CODE>. The prototype is in <CODE>macglue.h</CODE>. |
| 19 | This call initializes the toolbox, GUSI (if needed), sets up the correct |
| 20 | resource files and calls Py_Initialize. |
| 21 | |
| 22 | <LI> You have to be consequent in your use of GUSI. If the library uses |
| 23 | it so should your program and vice versa. |
| 24 | |
Jack Jansen | e67dab3 | 2001-10-09 23:14:06 +0000 | [diff] [blame^] | 25 | <LI> The console-behaviour (close-on-exit, etc) is controlled by Python |
| 26 | but you can overwrite this with <code>PyMac_SetConsoleHandler()</code>. |
Jack Jansen | 6ad8d13 | 1997-01-15 16:53:37 +0000 | [diff] [blame] | 27 | </UL> |
| 28 | |
| 29 | The Python environment is started with a dummy argc and argv, and initial |
| 30 | startup options are obtained through the usual means, except that the |
| 31 | user pression the option-key will not result in an interactive dialog. |
| 32 | You can, however, set startup options on your program in the same way as you |
| 33 | do for applets, by dragging your application to <code>EditPythonPrefs</code>. <p> |
| 34 | |
Jack Jansen | 3412c5d | 1997-08-27 14:08:22 +0000 | [diff] [blame] | 35 | The most logical way to embed Python is to link it against the shared |
| 36 | library <code>PythonCore</code>. An example project and source can be |
Jack Jansen | a2139fe | 1998-02-25 15:40:35 +0000 | [diff] [blame] | 37 | found in the <a href="embed">embed</a> folder. <p> |
Jack Jansen | 6ad8d13 | 1997-01-15 16:53:37 +0000 | [diff] [blame] | 38 | |
Jack Jansen | e67dab3 | 2001-10-09 23:14:06 +0000 | [diff] [blame^] | 39 | This example code also shows how to override the console: if you pass the |
| 40 | <code>-q</code> argument in the argument box output is thrown away. If you |
| 41 | pass the <code>-d</code> option the output is sent to <code>DebugStr</code> |
| 42 | (so be sure to use this only when running the example under a debugger). |
Jack Jansen | 6ad8d13 | 1997-01-15 16:53:37 +0000 | [diff] [blame] | 43 | </BODY> |
| 44 | </HTML> |