blob: e0ca756498bf7e3ef7e8be54b19317efd7e46936 [file] [log] [blame]
Jack Jansen6ad8d131997-01-15 16:53:37 +00001<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 Jansenae4300f1998-01-06 16:50:44 +00008<B>Note</B>: if you have a binary-only release of MacPython you will not
Jack Jansene67dab32001-10-09 23:14:06 +00009have this demo installed. Install the developer option (in the standard installer) or
10a source release if you want to embed
Jack Jansenae4300f1998-01-06 16:50:44 +000011Python in other applications. <p>
Jack Jansen6ad8d131997-01-15 16:53:37 +000012
13Embedding Python on the mac is pretty similar to embedding it on other
14platforms, 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>.
19This call initializes the toolbox, GUSI (if needed), sets up the correct
20resource files and calls Py_Initialize.
21
22<LI> You have to be consequent in your use of GUSI. If the library uses
23it so should your program and vice versa.
24
Jack Jansene67dab32001-10-09 23:14:06 +000025<LI> The console-behaviour (close-on-exit, etc) is controlled by Python
26but you can overwrite this with <code>PyMac_SetConsoleHandler()</code>.
Jack Jansen6ad8d131997-01-15 16:53:37 +000027</UL>
28
29The Python environment is started with a dummy argc and argv, and initial
30startup options are obtained through the usual means, except that the
31user pression the option-key will not result in an interactive dialog.
32You can, however, set startup options on your program in the same way as you
33do for applets, by dragging your application to <code>EditPythonPrefs</code>. <p>
34
Jack Jansen3412c5d1997-08-27 14:08:22 +000035The most logical way to embed Python is to link it against the shared
36library <code>PythonCore</code>. An example project and source can be
Jack Jansena2139fe1998-02-25 15:40:35 +000037found in the <a href="embed">embed</a> folder. <p>
Jack Jansen6ad8d131997-01-15 16:53:37 +000038
Jack Jansene67dab32001-10-09 23:14:06 +000039This 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
41pass 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 Jansen6ad8d131997-01-15 16:53:37 +000043</BODY>
44</HTML>