3

I'm 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 a __gchild_properties__ dictionary. These object properties that are not specific to either the container or the contained widget, but to the relationship. The library also uses it to connect to the child-widget notification for updates to the property value.

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

I am then trying to install the child properties using this for-loop on the above dictionary (DockPaned is the 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 get a

TypeError: argument pspec: Expected GObject.ParamSpec, but got tuple

I understand that built in GObject class properties use the GObject. ParamSpec as an object structure to hold the properties. What I don't see is a way in PyGObject to create my 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 the use of GObject.Property as a constructor to create the property, also shows its use as a decorator, and a verbose dictionary form. However, there is no mention of child properties.

Things I have tried:

  1. Searching for the API (pgi-docs) for a GObject.ParamSpec constructor, I don't see how to create one unless I created it in C first as a struct and then passed it back to pygobject somehow.
  2. Defining this weight property directly to the child object. This doesn't work since then I get errors that the child property doesn't exist since a child property is not the same as a property applied to a child object.
  3. Searching the API for any alternatives to install_child_property that doesn't require a ParamSpec, so that I could use the tuple I have defined.
taras
  • 6,566
  • 10
  • 39
  • 50
Dan Yeaw
  • 741
  • 8
  • 16
  • Today I also tried adding the weight property as a property of DockPaned, and then replaced the for loop with: – Dan Yeaw Jul 16 '17 at 02:39
  • `Gtk.ContainerClass.install_child_property(DockPaned, 2, GObject.list_properties(DockPaned))` Unfortunately, I am getting the same error. – Dan Yeaw Jul 16 '17 at 02:52
  • I also determined that the GObject.param_spec_float method can create a pspec. Unfortunately now I am still getting a different type error: Expected GObject.ParamSpec, but got gobject.GParamSpec. I have submitted a [bug](https://bugzilla.gnome.org/show_bug.cgi?id=784991) the the GNOME Bugzilla – Dan Yeaw Jul 20 '17 at 00:24

0 Answers0