Re: [Pyobjc-dev] How to get Python class into Objc namespace
Brought to you by:
ronaldoussoren
|
From: Steve S. <sst...@ma...> - 2008-05-12 01:53:21
|
On May 8, 2008, at 9:44 PM, Bill Bumgarner wrote: > On May 8, 2008, at 5:38 PM, Steve Steiner wrote: >> If someone will just point me to the right resource, I'll blog it >> and >> make it findable by the next poor sot. > > [[NSClassFromString(@"MyPythonClass") alloc] init]; > > Your challenge will be where you define the method prototypes to > keep the compiler happy. > > Personally, I would create a dummy class that has NO methods, then > declare categories against that dummy class that has all of the > methods w/appropriate signature that are needed... then declare the > result of the above to be a pointer to an instance of that class. > > Makes the compiler happy and the runtime doesn't care. That all worked, thanks! I'm finishing up blog entries and will post back to the list when I'm finished. > Unless you are jumping through hoops to declare the method > signatures, everything will be of an object type. > > If you want to provide subclasses of specific objc classes that are > implemented in python, then declare an abstract subclass that > contains all the method declarations and implementations that do > nothing, then subclass that from Python. That'll give the bridge > all (if you run gen_bridge_metadata, if needed) to do the > conversions across the bridge for the types that need it. Even though I went through this all, including the gen_bridge_metadata build step, it turned out that nothing I was doing wouldn't be automatically bridged. Cool! The mistake I made that lead me down this path was that I didn't realize that objc.ivar() just set up a KVC hook and thought I was doing something wrong when I couldn't access my Python ivars. What I realized, as I was working through all of this, is that what I'd really like to do is insure that my Python class implements a protocol. This is a plug-in architecture and I really need to verify that what is claiming to implement required functionality actually does. I've set up: SSDummyProtocol -- with a couple of dummy "- (NSObject) getData;" style declarations SSDummyObject -- declared as implementing the SSDummyProtocol SSDummyObjectPython -- with SSDummyObject as the parent, and I've implemented all the required methods, all in Python. What is the correct way to call conformsToProtocol: on my SSDummyObjectPython instance? I've tried several ways and they all result in (null). Thanks, S |