On Tue, 2005-09-13 at 00:08 -0400, Chris Hoefler wrote:
> Hi,
> 
> I have a bit of gtk experience, but I am still fairly new to 
> python/pygtk and I don't quite understand how GObject properties work. 
> I've been digging through all of the documentation/examples I can find. 
> As far as I can tell there have been some changes to how custom 
> properties of subclassed widgets are handled.
> 
> My working pygtk 2.6 code looks like this,
>    class newWidget(gtk.Widget):
>      __gproperties__ = {
>        'newProp' : (gobject.TYPE_STRING,....,gobject.PARAM_READWRITE)
>      }
> 
>      def __init__(self):
>        self.__gobject_init__()
>        self.newProp = None
> 
>      def do_get_property(self, property):
>        if property.name == 'newProp':
>          return self.newProp
> 
>      def do_set_property(self, property, value):
>        if property.name == 'newProp':
>          self.newProp = value
> 
>      <snip>more widget functions: do_realize, etc...</snip>
> 
>    gobject.type_register(newWidget)
> 
> and my understanding of the last line is that it handles the GType 
> declaration for the new widget, the GParamSpec stuff for the properties, 
> and all of the gtk_widget_install_property stuff you would normally have 
> to do yourself if you were writing in C.
> 
> In pygtk 2.8, I believe the same code should become this,
>    class newWidget(gtk.Widget):
>      def __init__(self):
>        gtk.Widget.__init__(self)
>        self.newProp = None
> 
>      <snip>more widget functions: do_realize, etc...</snip>
> 
> because all of the properties are now treated as object attributes. So a 
> do_set/get_property function is no longer needed, and __gproperties__ no 
> longer needs to be predefined. The type_register is also no longer 
> needed, but I really don't understand how all of the internals work. Am 
> I on the right track here?

  Not exactly.  In PyGTK 2.8 you still need __gproperties__, and
do_(get|set)_property methods.  "Properties as attributes" only means
that properties can be get/set as attributes (obj.props.propname), but
that is only from the "client side" perspective.  The GObject
implementing (or "serving") a new property still needs do_(get|
set)_property.

> 
> On a related note, I am also subclassing a gtk.Container. As far as I 
> can tell, everything should be treated the same as if I was subclassing 
> a gtk.Widget, but how do you handle child properties? Do you need a 
> different __gproperties__ construct? What about 
> do_set/get_child_property? And 
> gtk.container_class_install_child_property is defined in the API, but I 
> can't figure out where or if it is used.

  From a quick look (never used this myself) it appears you must call
gtk.container_class_install_child_property after class registration.
Then you have methods gtk.Container.child_(get|set)_property.  But then
you'd need to override do_set_child_property and do_get_child_property,
which is currently not supported, alas...  If you need this, please open
a bug report.

  Regards.

> 
> Any help would be much appreciated.
> 
> -Chris
> _______________________________________________
> pygtk mailing list   [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
-- 
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to