[Pyobjc-dev] Newbie question : embedding pyobjc in a Cocoa app
Brought to you by:
ronaldoussoren
From: Byron W. <by...@bl...> - 2005-05-09 21:34:57
|
I am building a cocoa app and would like to embed python to extend the functionality. Ideally I would like to created a python object and and give it a callback to my objective code. Looking at the embedded Tutorial it seems that the way to embed pyobjc would be to create a bundle and instantiate that bundle to use the python modules within it. So I created a little test project and am somewhat stuck. I have the following main method : int main(int argc, char *argv[]) { //NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //PythonGlue *glue = [[PythonGlue alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *pluginPath = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"plugin"]; NSBundle *pluginBundle = [NSBundle bundleWithPath:pluginPath]; [pluginBundle load]; NSLog(@"pluginBundle = %@",pluginBundle); Class testClass = [pluginBundle classNamed:@"Test"]; NSLog(@"testClass = %@",testClass); id test = [[testClass alloc] init]; NSLog(@"Terst = %@",test); [pool release]; return NSApplicationMain(argc, (const char **) argv); } I created a Test.py that contains the following : import objc from Foundation import * class Test(NSObject): def init(self): self = super(Test, self).init() if self is None: return None # subclass specific initialization here # nib not loaded yet print "Test init()" return self The bundle loads fine but the following statments return nil : NSLog(@"testClass = %@",testClass); NSLog(@"Terst = %@",test); BTW, I am pretty new to Python, once I get over the embedding hurdle I plan to get deeper into Python. What am I doing wrong? How can I instantiate python objects via the bridge? Is what I am attempting possible (instantiating bundle and attempting to retrieve python class)? I looked around on the archive but all I could up with that was close to what I am attempting eludes to some old code that I can no longer find (PythonGlue.*). Any help is much appreciated. BTW, I am looking at RubyCocoa as an alternative and their documentation seems to lack information related to embedding and extending a cocoa app :( - Byron |