On 11 Apr 2001, Bernhard Herzog wrote:
> Skip Montanaro <[EMAIL PROTECTED]> writes:
>
> > Tim> hi,
> > Tim> i'd like to use pygtk widget classes as base classes to my own, like
> >
> > Tim> class myVBox (GtkVBox):
> > Tim> ...
> >
> > Tim> now if i understand correctly, the python wrapping code in gtk.py
> > Tim> is planned to be rewritten in c. will this break code like above?
> >
> > I believe it should work. The new version uses Digital Creations'
> > ExtensionClass to allow objects to be subclassed in Python.
>
> However, IIRC, calling a baseclass' method in a method has to be done
> slightly different. E.g.
>
> class MyBox(GtkBaseClass):
>
> def __init__(self):
> GtkBaseClass.__init__(self)
This works with ExtensionClass. ExtensionClass is designed to create
types that act as much like python classes as possible, so it would be a
bug if this didn't work.
>
>
> will fail because type(self) isn't InstanceType. James pointed out some
> other pifalls in
> http://www.daa.com.au/pipermail/pygtk/2000-June/000104.html
The isinstance and issubclass functions were fixed in python 2.0 to work
with `class like' and `instance like' objects, rather than just class and
instance objects. There are still a few problems but they haven't caused
any problems in the tests I have done so far (I think coercions still
special case InstanceType, but I don't think people will be coercing
widgets much :)
>
> AFAIK, the reason to use ExtensionClasses in the first place was to make
> sure that there is exactly one pygtk object for every GTK widget.
> Without ExtensionClasses you get circular references. In Python 2.1
> there'll be weak references which would provide a solution for this
> problem. Wouldn't it make more sense to rely on that?
Doing the 1-1 wrapper/object mapping was one of the reasons for changing.
Other reasons were making code generation easier, reducing memory usage
(due to removing one layer from the binding), and speed increase (startup
time is less because there is less python code to parse when importing
gtk).
The 2.1 weak references will help with the wrapper/object mapping circular
reference problem (I currently have an evil hack in gobjectmodule.c to get
the desired behaviour :). Just remember that this wasn't the only reason
for using ExtensionClass.
James.
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk