[pygtk] Re: Re: Cannot subclass gtk.Widget

Jeffrey Barish jeff_barish at earthlink.net
Sun Mar 11 01:54:09 WST 2007


Gustavo J. A. M. Carneiro wrote:

> Another, more complex, example can be found here:
> http://telecom.inescporto.pt/~gjc/higcontainer/higcontainer.py

By studying the examples, I have learned a lot about subclassing.  I have
two questions about this example.  It seems desirable to me that it be
possible to call the subclass in the same manner used to call other PyGTK
classes.  Thus, in the case of your example, the subclass would be
instantiated with

group = HIGContainer(title='Hello')

instead of

group = gobject.new(HIGContainer, title="Hello")

(In fact, I think it would be even more consistent to have

group = HIGContainer()
group.set_title("Hello")
)

When I make this change, I get the error message

'HIGContainer' object has no attribute '_HIGContainer__title'

The error vanishes when I drop the gobject.PARAM_CONSTRUCT, so evidently
gobject.new does something with __gproperties__ that does not happen
otherwise.  What is the implication of dropping the gobject.PARAM_CONSTRUCT
flag and invoking the HIGContainer this way?  

Also, I read in gobject-tutorial that it is "absolutely necessary" to use
gobject.type_register, yet you didn't.  The program seems to work fine
whether or not gobject.type_register is present.  What are the
ramifications of omitting this call?
-- 
Jeffrey Barish



More information about the pygtk mailing list