I’m probably trying to do something I shouldn’t but I’m trying anyway!
Essentially, I want to make a template for an AdwExpanderRow and it’s ‘on-the-way’ but the gtype_name doesn’t seem to be working right. If I debug my Python module I get…
RuntimeError: could not create new GType: ContactRow (subclass of GtkWidget)
My code it kind of working, I get a row in my GtkListBox, but not the row in my template… presumably because it ‘could not create new GType…’
Initially, I was using an sql database and loading it into a GListStore then binding the GListStore and a definition that creates an AdwExpanderRow into a model for the GtkListBox. Whenever I wanted to re/load the GtkListBox I simply used…
for row in record:
liststore.append(ContactDataObject(row))
It worked great. I setup a callback so that when you click on a row it prints the row’s name (in my case the sql rowid) but I have a huge amount of code in my .py file that creates the AdwExpanderRow. I don’t like looking at it!
So, I decided to make a template of a GtkWidget whose child is an AdwExpanderRow and try binding that with the GtkListStore.
If I run the app I get a blank row in my GtkListBox but when I click on it the callback prints “GtkListBoxRow”. It does, however, throw up…
(main.py:3204): Gtk-CRITICAL **: 15:03:40.108: Error building template class 'ContactRow' for an instance of type 'ContactRow': .:0:0 'version' attribute has malformed value '1'
When I’ve created the AdwExpanderRows in my .py file without filling it with data from the sql database it would read AdwExpanderRow so in the case of my template I would expect the same, not a Gtk row.
To try to keep it brief, this is what I have…
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1"/>
<template class="ContactRow" parent="GtkWidget">
<child>
<object class="AdwExpanderRow" id="contact_expander_row">
<child> Lots of lines that provide the AdwExpanderRow content.....
@Gtk.Template(filename='expander.ui')
class ContactRow(Gtk.Widget):
__gtype_name__ = "ContactRow"
contact_expander_row = Gtk.Template.Child()
def __init__(self, row):
super().__init__()
I’ve got the expander.ui file in the same directory as my .py modules and window.ui and there’s no errors related to not finding the .ui file.
Any ideas would be appreciated! Thank you