[Pyobjc-dev] Calling Python code from Cocoa bundle
Brought to you by:
ronaldoussoren
From: <li...@po...> - 2004-03-13 17:21:10
|
Hi, I'm a python newbie and I'm trying to call a python method from within a Obj-c Cocoa bundle. I've worked around the "undefined symbol" problem ( http://sourceforge.net/mailarchive/message.php?msg_id=7358512 ), but python doesn't find my abstract Obj-C class and therefore won't let me subclass it: > Traceback (most recent call last): > File "MyBundle.bundle/Contents/Resources/PythonGlue.py", line 36, in > ? > main() > File "MyBundle.bundle/Contents/Resources/PythonGlue.py", line 30, in > main > __import__(filename[:-3]) > File "MyBundle.bundle/Contents/Resources/Test.py", line 7, in ? > class Test (Abstract): > NameError: name 'Abstract' is not defined Here's what I have: PythonGlue.h, PythonGlue.m, PythonGlue.py from pyobjc-1.0/Doc/tutorial_embed/src/ ### file: Abstract.h @interface Abstract : NSObject + instantiateSubclassNamed: (NSString *) aClassName; @end @interface Abstract (Test) - (void) hello; @end ### file: Abstract.m @implementation Abstract + instantiateSubclassNamed:(NSString*) aClassName { Class aClass = NSClassFromString(aClassName); return [[aClass alloc] init]; } @end ### file: Test.py from objc import YES, NO from Foundation import * from AppKit import * DEBUG = 1 class Test (Abstract): def init(self): if DEBUG: print "Test.init() called" return self def hello_(self, obj): if DEBUG: print "Test.hello() called" And in my bundle's main class: [[PythonGlue alloc] init]; id test = [Abstract instantiateSubclassNamed:@"Test"]; [test hello]; Thanks in advance, -Ralph. |