[Pygui] Native wrappers?

Dan Villiom Podlaski Christiansen danchr at gmail.com
Tue Dec 22 10:43:09 CET 2009


Hi Greg,

I managed to get the 01-application test running, and I'm now looking at the 02-window test. It uses multiple inheritance like you mentioned, and I can now see why you chose to use it. Without it, a lot of classes would have to contain a lot of duplicated, boilerplate code.

As you also mentioned, Objective-C doesn't support multiple inheritance, but I have an idea how it might be mimicked. The documentation suggests using forwarding,[1] but that may not work with delegates and such, so I'd suggest another approach instead:

The methods to be ‘inherited’ would be implemented as instance methods of a separate class, and this would be similar to the Components.PyGUI_NS_EventHandler Python class in this instance. This class would then provide a class method such as ‘+copyMethodsTo:(Class)aclass’ which would iterate over the instance methods of its class, and copy/add them to the given class. Rather than inheriting from this class, other classes — such as the NSWindow subclass — would call this method in their +initialize method. This should yield the same results as multiple inheritance, whilst remaining almost as simple and concise.

Oh, I just remembered that I forgot to respond to this portion:

On 21 Dec 2009, at 00:55, Greg Ewing wrote:

> (BTW, this would be another good reason to use Pyrex -- it takes
> care of all the gory details of exception handling for you.)

I understand that Pyrex would probably ease the implementation. However, it seems to me that using it would run counter to the stated goals of the project, unless Pyrex itself was to be included into the Python core library. Or perhaps I misunderstand?

[1] Section “Forwarding and Multiple Inheritance” in the “Objective-C Runtime Reference” <http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtForwarding.html#//apple_ref/doc/uid/TP40008048-CH105-SW10>

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pygui/attachments/20091222/c5ee293f/attachment.bin>


More information about the Pygui mailing list