GtkBuilderListItemFactory: property 'scope' for type 'GtkBuilderListItemFactory' cannot be set twice

I’m trying to use the example to handle a signal in GtkBuilderListItemFactory from here and I’m getting an warning Warning: g_object_new_is_valid_property: property 'scope' for type 'GtkBuilderListItemFactory' cannot be set twice . How to fix this warning ? Maybe in pygobject Builder need check if scope exist before self.set_scope(Builder.BuilderScope(scope_object_or_map))

Minimal example

import gi
gi.require_version('Gtk', '4.0')

from gi.repository import Gtk, GLib, Gio
from gi.repository import GObject

UI_XML = """<?xml version="1.0" encoding="UTF-8"?>
  <requires lib="gtk" version="4.0"/>
  <object class="GtkWindow">
    <property name="title">Test window</property>
    <property name="visible">true</property>
      <object class="GtkBox">
        <property name="orientation">1</property>
          <object class="GtkListView">
            <property name="factory">
              <object class="GtkBuilderListItemFactory">
                <property name="scope">
                  <object class="ListItemBuilderScope"></object>
                <property name="bytes"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
  <template class="GtkListItem">
    <property name="child">
      <object class="GtkButton">
        <binding name="label">
          <lookup name="objName" type="MyObject">
            <lookup name="item" type="GtkListItem">
        <signal name="clicked" handler="test"/>
            <property name="model">
              <object class="GtkNoSelection">
                <property name="model">
                  <object class="MyList">
                      <object class="MyObject">
                        <property name="objName">first</property>
                      <object class="MyObject">
                        <property name="objName">second</property>

class MyObject(GObject.GObject):
    __gtype_name__ = "MyObject"

    def __init__(self):
        self.value = ""

    def test(self, *args):
        print("Handler ", self.value, " ", args)

    def objName(self):
        return self.value

    def objName(self, value):
        self.value = value

class MyList(GObject.GObject, Gio.ListModel, Gtk.Buildable):
    __gtype_name__ = "MyList"
    def __init__(self) -> None:
        self._list = []

    def do_add_child(self, builder, child, type):

    def do_get_item(self, index):
        return self._list[index]
    def do_get_item_type(self):
        return GObject.TYPE_OBJECT

    def do_get_n_items(self):
        return len(self._list)

class ListItemBuilderScope(GObject.GObject, Gtk.BuilderScope):
    __gtype_name__ = "ListItemBuilderScope"
    def __init__(self, scope_object=None):
            self._scope_object = scope_object

    def do_create_closure(self, builder, func_name, flags, obj):
        current_object = builder.get_current_object() or self._scope_object
        item = current_object.get_item()
        def call_signal(source):
        return call_signal

class App(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.builder = None

    def do_activate(self):
        self.builder = Gtk.Builder()

if __name__ == "__main__":
    app = App()

And maybe there are plans to add a call signal from builder to custom object in future?

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