I’m trying to migrate a small GUI I wrote years ago in python, from using Gtk.TreeView to Gtk.ColumnView. I was able to rewrite it to make use of .ui Builder files, but now I’m struggling with Gtk.BuilderListItemFactory.
The problem here is the group property of the Gtk.CheckButton. I tried to add an invisible button in my window template, but then Gtk complains with Error building template for list item: .:0:0 Object with ID next_group not found. On the other hand adding it inside the XML of the factory would be useless, because each button would have a different group…
Maybe I could iterate with code on each row and set each CheckButton’s group to the first row’s one, but I’m not sure about that.
Note that the same effect can be achieved via the GtkActionable API, by using the same action with parameter type and state type ‘s’ for all buttons in the group, and giving each button its own target value.
What is self? An Application or some other action map/group implementor? If it’s a map, your property will need the name of the map (app., win., whatever) added to it. But probably you should instead add an action group to the widget - so that e.g. if you end up having multiple instances, they won’t conflict with each other’s (or other sources’) app-level actions - using gtk_widget_insert_action_group(). Either way, I don’t see how your widget has enough info to activate whatever action you’re adding.
Generally, see if this documentation helps: Gtk – 4.0: Overview of actions in GTK, and hopefully that’ll give you enough to get it working. Let us know if you do!
self is a Gtk.ApplicationWindow, should I add it to the radio buttons? I’ve never used actions in Gtk, I think I understood what an action is, but I don’t get how to use it.
I don’t see how your widget has enough info to activate whatever action you’re adding.
I told the widget it should connect to the next_boot action, didn’t I? I also set the action-state property like this: <property name="action-target">"TEST"</property>. When that action is activated it’s state should change to “TEST”, right?
Yes, but you didn’t specify where to look for the action. As @dboles said, you should change the value of the “action-name” property to “win.next_boot”.
Now I have to find a way to set a different action-target for each button. Is it possible to do this in Gtk.Builder files? I made an attempt with this:
But unfortunately it looks like I’m out of luck, because that gives another error:
Traceback (most recent call last):
File "/nix/store/49dqxcpncsy2hd8xkj7xwbi2mbc7g4kj-python3.10-pygobject-3.44.1/lib/python3.10/site-packages/gi/_gtktemplate.py", line 64, in do_create_closure
if func_name not in current_object.__gtktemplate_methods__:
AttributeError: 'ListItem' object has no attribute '__gtktemplate_methods__'
Radio buttons and treeviews were definitely easier to manage in GTK3.
I’ve now tried using actions instead of button groups and been disappointed, so if you do figure out how to make it work from .ui files, watch out for that caveat about keynav not working the same way.
[edit] I presume we could subclass the widget containing the buttons, and override gtk_widget_move_focus() to imitate the behaviour of grouped buttons, but I just don’t think I can be bothered to be honest…