Python from objective-C
I've been working on getting python objects to instantiate in objective-C and have put together a little demo app as a learning tool for myself. It may not be the best way to python from objc, but it works. I hope it's helpful.
http://www.jonathansaggau.com/cocoa-dev/test.tgz
XCode should build the bundle for you when you hit Build and Go. You'll see a bunch of stuff in the log window that shows you that the python object is firing on all cylinders and that calling the super class that's written in objc works as expected, etc. You'll want to look in the NIB file to see how it's all connected.
How it works:
I subclassed an objc object (JSAbstractTest) in python (Test.py), using of the NIB file to indicate the class hierarchy. You don't necessarily *have* to subclass in this way, you could use a protocol like Bob suggests on the pythonmac-SIG. The protocol method is cleaner, for instance, when you don't really want to implement any of the functionality of the class in objc. This will allow you to do things you might want to do in the compiled language while offloading some functionality to our friendly "batteries included" python. (This is such fun).
Also useful (http://pyobjc.sourceforge.net/doc/intro.php) so we know what the bridge is expecting:
* Python numbers (int, float, long ) are translated into NSNumber instances. Their identity is not preserved across the bridge.
* Python str is proxied using OC_PythonString, a subclass of NSString. A Python str may be used anywhere a NSString is expected, but unicode should be used whenever possible. OC_PythonString will use the default encoding of NSString, which is normally MacRoman but could be something else.
* Python unicode is proxied using OC_PythonUnicode , a subclass of NSString. A Python unicode may be used anywhere a NSString is expected.
* Python dict is proxied using OC_PythonDictionary, a subclass of NSMutableDictionary. A Python dict may be used anywhere an NSDictionary is expected.
* Python list and tuple are proxied using OC_PythonArray, a subclass of NSMutableArray. Python list or tuple objects may be used anywhere an NSArray is expected.
* Python objects that implement the Python buffer API, except for str and unicode, are proxied using OC_PythonData, a NSData subclass. Objects that implement the Python buffer API such as buffer, array.array, mmap.mmap, etc. may be used anywhere a NSData is expected.
Armed with the above information, I coaxed a UDP networking toy written in python to send messages to SuperCollider based on the activity of an image stream coming from my iSight through a quartz composer project. WOO HOO!)
(I've also posted this to pythonmac-SIG, where I'm sure to get comments to refine this post. In the meantime, take this with a grain of salt.)