PyGObject Setting child properties by creating a ParamSpec

I am trying to convert a pygtk library called etk.docking to pygobject. As part of this, I have a Gtk.Container class that has child properties defined in the __gchild_properties__ dictionary. These are object properties that are not specific to the container or the contained widget, but to the relationship. The library also uses it to connect to the notification child widget for property value updates.

__gchild_properties__ = {
    'weight': (GObject.TYPE_FLOAT,
               'item weight',
               'item weight',
               0,  # min
               1,  # max
               .2,  # default
               GObject.ParamFlags.READWRITE
               ),
}

      

Then I try to set child properties using this for loop in this dictionary (DockPaned is a container):

for index, (name, pspec) in enumerate(six.iteritems(DockPaned.__gchild_properties__)):
    pspec = list(pspec)
    pspec.insert(0, name)
    Gtk.ContainerClass.install_child_property(DockPaned, index + 1, tuple(pspec))

      

From the last line I am getting TypeError argument: pspec: GObject.ParamSpec expected but got tuple

I understand that the built-in properties of the GObject class use GObject.ParamSpec as an object structure to store properties. What I don't see is PyGObject's way to create its own ParamSpec.

For normal properties, the PyGObject User Guide uses GObject.Property as a decorator to create new properties. The Python GTK + 3 Tutorial also shows that using GObject.Property as a constructor to create a property also shows its use as a decorator, and an advanced vocabulary form. However, there is no mention of child properties.

Things I've tried:

  • Searching the API (pgi-docs) for the GObject.ParamSpec constructor, I can't see how to create it unless I created it in C first as a struct and then somehow passed it to pygobject.
  • Defining this weight property directly to the child object. Since then this doesn't work, I get errors that the child property does not exist because the child property does not match the property being applied to the child object.
  • Looking for an API for any alternatives to install_child_property that doesn't require a ParamSpec parameter so that I can use the tuple I defined.
+3


source to share





All Articles