Re: [pygtk] deriving classes from gtk.py
On 22 Apr 2001, Bernhard Herzog wrote: > Well, the ExtensionClass docs contain the following example, which is > actually a bit different (i.e. I did not remember correctly) from the > situation above (taken from the ExtensionClass.stx that comes with Zope > 2.3.0: > > from ExtensionClass import Base > > class Spam: > > def __init__(self, name): > self.name=name > > class ECSpam(Base, Spam): > > def __init__(self, name, favorite_color): > Spam.__init__(self,name) > self.favorite_color=favorite_color > > and the docs go on to say: > > This implementation will fail when an 'ECSpam' object is > instantiated. The problem is that 'ECSpam.__init__' calls > 'Spam.__init__', and 'Spam.__init__' can only be called with a > Python instance (an object of type '"instance"') as the first > argument. The first argument passed to 'Spam.__init__' will be an > 'ECSpam' instance (an object of type 'ECSPam'). > > So at least mixin classes are a bit of a problem with ExtensionClasses > (there's a solution to the problem given in the docs, however). It may > well be that with Python 2.0 this is not an issue anymore. This won't affect pygtk. GtkWidgets won't work if you don't chain to their constructor anyway, so I don't think this will be a problem. This hasn't been an issue with any of the examples I have tested. James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] deriving classes from gtk.py
James Henstridge <[EMAIL PROTECTED]> writes: > On 11 Apr 2001, Bernhard Herzog wrote: > > 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. Well, the ExtensionClass docs contain the following example, which is actually a bit different (i.e. I did not remember correctly) from the situation above (taken from the ExtensionClass.stx that comes with Zope 2.3.0: from ExtensionClass import Base class Spam: def __init__(self, name): self.name=name class ECSpam(Base, Spam): def __init__(self, name, favorite_color): Spam.__init__(self,name) self.favorite_color=favorite_color and the docs go on to say: This implementation will fail when an 'ECSpam' object is instantiated. The problem is that 'ECSpam.__init__' calls 'Spam.__init__', and 'Spam.__init__' can only be called with a Python instance (an object of type '"instance"') as the first argument. The first argument passed to 'Spam.__init__' will be an 'ECSpam' instance (an object of type 'ECSPam'). So at least mixin classes are a bit of a problem with ExtensionClasses (there's a solution to the problem given in the docs, however). It may well be that with Python 2.0 this is not an issue anymore. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] deriving classes from gtk.py
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
Re: [pygtk] deriving classes from gtk.py
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) 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 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? Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://mapit.de/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] deriving classes from gtk.py
On Wed, 11 Apr 2001, Tim Goetze wrote: > hi, > > i'd like to use pygtk widget classes as base classes to my own, like > > class myVBox (GtkVBox): > ... > > now if i understand correctly, the python wrapping code in gtk.py is > planned to be rewritten in c. will this break code like above? the development version of pygtk uses ExtensionClass, which is a module that allows creation of types in C extension modules that can be subclassed. So the above code will continue to work. James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] deriving classes from gtk.py
Skip writes: >I believe it should work. The new version uses Digital Creations' >ExtensionClass to allow objects to be subclassed in Python. great, thanks! ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] deriving classes from gtk.py
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. >>> import gtk ... >>> type(gtk.GtkWindow) -- Skip Montanaro ([EMAIL PROTECTED]) (847)971-7098 ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] deriving classes from gtk.py
hi, i'd like to use pygtk widget classes as base classes to my own, like class myVBox (GtkVBox): ... now if i understand correctly, the python wrapping code in gtk.py is planned to be rewritten in c. will this break code like above? tia, tim ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk