GTK4 Expressions for binding to nested GObject properties

Hi, could someone help me use the new GTK4 Expressions for binding to nested properties in python.

The GTK4 documentation on Expressions suggests that expressions can be used to bind to nested GObject properties like this->item->name, and this is precisely what I am trying to achieve in python3 code.

In the following code example, the last line shows what I am trying to do:

import gi
gi.require_version("Gtk", "4.0")
from gi.repository import GObject, Gtk
from gi.repository.GObject import Property

# example classes
class Address(GObject.Object):
    line1 = Property(type=str)
    line2 = Property(type=str)
    line3 = Property(type=str)

class Person(GObject.Object):
    name = Property(type=str)
    address = Property(type=Address)

# example objects
john = Person() = "John Doe"

addr = Address()
addr.line1 = "15 My Ave"
addr.line2 = "1234 Country"
addr.line3 = "The State"
john.address = addr

widget = Gtk.Label

# question: how can I bind the label to john's address line1?
# similar to the following (disfunctional) pseudocode:
widget.bind_property_using_expression("label", john, "address.line1")

thank you! best regards, Johannes

Update: I found pygobject’s issue 457 which deals with gtk4 expression support in the python language bindings to gtk. I do not fully understand the ticket, but it looks like GTK expressions are not yet (fully) implemented in pygobject?

PyGObject currently does not support fundamental derivable types outside of GObject and GParamSpec; GTK4 introduced a few of these types—GtkExpression, GskRenderNode, and GdkEvent. This means that PyGObject will need to gain support for this set of types.

ok, thank you, Emmanuele! best regards, Johannes

In Vala I would have done something similar to the following

var address_label = new Gtk.Label("");
var object_expression = new Gtk.ObjectExpression (person);
var property_expression = new Gtk.PropertyExpression (typeof (Person), object_expression, "address");
property_expression.bind (address_label, "label", address_label);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.