GTK3: How can I inherit from a class that uses @Gtk.Template decorators

Hi, I’m trying to create a couple of forms for an application. All forms have things in common, so I thought of creating a Form superclass and subclass it. Like so:

Form
├── AForm
└── BForm

I’m using Glade to create the XML UI templates for the GUI, and using @Gtk.Template decorators on the classes that use the templates. For instance (minimal example):

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


@Gtk.Template(filename="form.ui")
class Form(Gtk.ScrolledWindow):
    """Base class for application forms."""
    __gtype_name__ = "Form"

    def __init__(self, title):
        super().__init__(hadjustment=None, vadjustment=None)
        self.title = title


class SpecialForm(Form):
    """Objects of this class represent forms for special objects."""
    def __init__(self, title):
        super().__init__(title)
        self.title = title
        # Some specializations below.


form = SpecialForm("Add New Special Thing")

Running the code above, however, results in these errors:

Traceback (most recent call last):
  File "/gnu/store/l44n8w2gb8xisc6w9zk0y6w31n1ijkg5-profile/lib/python3.9/site-packages/gi/_gtktemplate.py", line 169, in <lambda>
    lambda s: init_template(s, cls, base_init_template)
  File "/gnu/store/l44n8w2gb8xisc6w9zk0y6w31n1ijkg5-profile/lib/python3.9/site-packages/gi/_gtktemplate.py", line 179, in init_template
    raise TypeError(
TypeError: Inheritance from classes with @Gtk.Template decorators is not allowed at this time
Traceback (most recent call last):
  File "/gnu/store/l44n8w2gb8xisc6w9zk0y6w31n1ijkg5-profile/lib/python3.9/site-packages/gi/_gtktemplate.py", line 169, in <lambda>
    lambda s: init_template(s, cls, base_init_template)
  File "/gnu/store/l44n8w2gb8xisc6w9zk0y6w31n1ijkg5-profile/lib/python3.9/site-packages/gi/_gtktemplate.py", line 179, in init_template
    raise TypeError(
TypeError: Inheritance from classes with @Gtk.Template decorators is not allowed at this time

So, is it not possible at all to do inheritance when using XML Templates? What would be the right way to do inheritance in this case?

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