Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • pygobject pygobject
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 303
    • Issues 303
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • pygobjectpygobject
  • Merge requests
  • !199

Support Gtk.Template on sub-classed Python classes

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Christoph Böhme requested to merge cboehme/pygobject:fix-400-template-hierarchy into master Feb 18, 2022
  • Overview 0
  • Commits 2
  • Pipelines 3
  • Changes 2

If Gtk.Template is applied to a Python class which is a sub class of another Python class then instance initialisation fails with the error message: "gtk_widget_init_template: assertion 'template != NULL' failed".

When initialising the GObject instance which corresponds to Python object that is being created, pygobject_g_instance_init() is called once for each Python class in the inheritance hierarchy of the Python object. This method then calls __dontuse_ginstance_init__() on the Python object which in turn calls GtkWidget.init_template(). However this method must only be called once the GObject instance is fully instantiated because it is only then that the template member is initialised. This means pygobject_g_instance_init() should only call __dontuse_ginstance_init__() during its call to initialise the most-derived class.

In order to achive this, this commit adds a check which compares the current type id of the GObject being initialised with the type id of the final class of the object. Only if these to are equal __dontuse_ginstance_init__() is called.

This fixes #400.

Edited Feb 18, 2022 by Christoph Böhme
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: fix-400-template-hierarchy