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