[Pythonmac-SIG] Embedding Python invisibly

Paul Miller paul@fxtech.com
Wed, 03 Oct 2001 12:52:46 -0500


Jon,

Yep - you can do everything you want to do. But it'll take some work...

>1. Python is embedded in the application (invisibly?)

Just link with the Python library and initialize it normally. The main 
issue here with making it "invisible" is on Mac it wants to open a Console 
no matter what you do. If anyone has figured out how to avoid this, I'd 
love to hear about it!

>2. User uses an SDK (which would probably be Python) to compile an extension
>that's written in Python (or uses Python to write the extension).

You probably won't compile anything. Just have the user put their 
"extensions" (with .py extension) in your extensions directory and have 
Python look there for them (by modifying Python's path list).

>3. The extension shows up in an extension palette and the user can click on
>it and execute away.

Couple of ways to do this - you could scan the directory yourself, pick out 
all files with .py extension, and use the base name as the extension name. 
You could also have your code "import" each extension and query it for the 
name it wants to be displayed as.

>4. Say this extension ... oh, modifies some selected geometry in a current
>context.

You'll need to "extend" your C/C++ interfaces with Python interfaces, so 
you can use them in your "extension scripts".

>5. How the heck can it be done without an interpreter ever being visible or
>opened??!?

You don't use the interpreter directly. When you want to run an extension, 
you just import it (using Python API calls), and call functions in it.

You will want to look into the Python extending/embedding APIs on 
python.org. It wouldn't hurt to get Lutz's original Programming Python book 
- it had a pretty large chapter on this.

All this stuff is pretty straightforward (one of the reasons Python makes 
such a nice extension language), but it's non-trivial.

>The good thing about being able to do this is that we'd be able to have
>Python in the application running tools, extensions, animation things, etc.
>without the user ever having to touch code or type anything (I would love to
>enable this brainless approach).  Just click and go.  Also, it would be much
>easier to expand and work with as the application grows.

We are working on a product that does exactly this (with the Power User 
extension approach you mention). It takes a bit of effort, but you can make 
a really nice environment out of this.

>Now ... question is ... can it be done, and does anyone have a clue how?

Hopefully my pointers above will get you started. Sorry I don't have time 
to go into more detail. A couple of days of research and playing around 
with the extension mechanism should get you going though!


-- 
Paul T. Miller | paul@fxtech.com | http://www.fxtech.com