Property Expression issues

Hi,

I am having an issue with the Gtk.PropertyExpression class. I tried different options but I always get an error similar to:

TypeError: No means to translate argument or return value for 'GtkPropertyExpression'

Below is my code snippet:

class AppColumnView(Gtk.ColumnView):
    __gtype_name__ = "app_column_view"

    def __init__(self,):
        super().__init__()

        self.folder_path = None
        self.search_entry_value = None

        self.set_show_row_separators(True)
        self.set_show_column_separators(True)

        self.single_selection = Gtk.SingleSelection()
        self.sort_list_model = Gtk.SortListModel()
        self.list_store = Gio.ListStore()

        self.set_model(self.single_selection)
        self.single_selection.set_model(self.sort_list_model)
        self.sort_list_model.set_model(self.list_store)
        self.sort_list_model.set_sorter(self.get_sorter())

        columns = [
            {"title": "Path", "property": "path", "expand": True, "setup": self.factory_setup_label, "bind": self.factory_bind_label},
            {"title": "Points (nb)", "property": "points", "expand":  False, "setup": self.factory_setup_label, "bind": self.factory_bind_label},
            {"title": "Length (km)", "property": "length", "expand":  False, "setup": self.factory_setup_label, "bind": self.factory_bind_label},
            {"title": "UpHill (m)", "property": "up_hill", "expand":  False, "setup": self.factory_setup_label, "bind": self.factory_bind_label},
            {"title": "DownHill (m)", "property": "down_hill", "expand":  False, "setup": self.factory_setup_label, "bind": self.factory_bind_label},
            {"title": "Actions", "property": None, "expand":  False, "setup": self.factory_setup_actions, "bind": None}
        ]
        
        for column in columns:
            column_view_column = Gtk.ColumnViewColumn()
            column_view_column.set_title(column["title"])
            column_view_column.set_expand(column["expand"])

            signal_list_item_factory = Gtk.SignalListItemFactory()
            signal_list_item_factory.connect("setup", column["setup"])

            if column["bind"]:
                signal_list_item_factory.connect("bind", column["bind"], column["property"])

                property_expression = Gtk.PropertyExpression.new(Item, None, column["property"])
                string_sorter = Gtk.StringSorter()
                string_sorter.set_expression(property_expression)
                column.set_sorter(string_sorter)

            column_view_column.set_factory(signal_list_item_factory)
            self.append_column(column_view_column)

KInd regards,
Vincent

I’m sorry, but GtkExpression is not supported by the Python bindings. PyGObject has never supported instance types that are not GObject, and nobody has implemented support before GTK4 was released.

You can define expressions in the UI definition files, but you cannot access them in Python code, or create them programmatically.

Sorry to interfere with this topic, but I am experiencing a similar issue with GtkExpression in Python and I do not think opening a different topic would make sense.

Regarding what @ebassi just said, does that mean that it is not possible for Python users to utilise the search option embedded in GtkDropDown? If so, is there any way to reproduce the GTK3 behaviour of coupling GtkComboBox with GtkEntryCompletion using GTK4 Python bindings? Thank you very much for any input.

As I said, it should be possible for you to define the DropDown in a UI definition file, and create the expression there as a binding, e.g. (untested code):

<object class="GtkDropDown" id="drop-down">
  <property name="model">
    <object class="GtkStringList">
      <items>
        <item>Choice 1</item>
        <item>Choice 2</item>
        <item>Choice 3</item>
        <item>Choice 4</item>
        <item>Choice 5</item>
      </items>
    </object>
  </property>
  <property name="enable-search">true</property>
  <binding name="expression">
    <lookup name="string">GtkStringObject</lookup>
  </binding>
</object>

But, otherwise, no.

The GtkComboBox and GtkEntryCompletion API still exist and work in GTK4, so you can use them both in the same way as in GTK3.

1 Like

@ebassi,

Thanks for your answer. I will give it a try with a .ui file definition.
I was not using them until now as there is no proper software like Glade managing Gtk4.
I played a bit with Cambalache but it seems to early to use it.

Regards,
Vincent

Hi @ebassi,

I found this topic How to pass the parameter to GtkSorter's expression with GtkColumnViewColumn? which is useful and I try to adapt the example to my use case.

So, I switched to a GtkBuilderListItemFactory instead of a SignalListItemFactory. I am using a Gio.Listore with an object called Item which is inherited from GObject.

class Item(GObject.GObject):
    __gtype_name__ = "item"

    path = GObject.Property(type=str)
    points = GObject.Property(type=int)
    length = GObject.Property(type=float)
    up_hill = GObject.Property(type=float)
    down_hill = GObject.Property(type=float)

    def __init__(self, path, points, length, up_hill, down_hill):
        super().__init__()

        self.path = path
        self.points = points
        self.length = length
        self.up_hill = up_hill
        self.down_hill = down_hill

In the ui file definition, if I set something like:

<lookup name="path" type="Item">
   <lookup name="item">GtkListItem</lookup>
</lookup>

The the Item type is not recognized and an error is thrown and it’s saying Invalid Type.

Regards,
Vincent

Hi,

I found the solution by myself:

<property name="sorter">
    <object class="GtkStringSorter">
        <property name="expression">
            <lookup name="path" type="Item"/>
        </property>
    </object>
</property>

Regards

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