Signal inheritance from multiple base classes

The docs appear to show that GTK can inherit inherit signals from multiple base classes, yet in the following example creates a runtime error because the signal name in the second inherited base class inherited is not found. Am I missing a special syntax?

import gi

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

class Child1(GObject.GObject):
    __gsignals__ = {
        "one": (GObject.SignalFlags.RUN_LAST, None, ()),
    }
    
    def __init__(self):
        GObject.GObject.__init__(self)


class Child2(GObject.GObject):
    __gsignals__ = {
        "two": (GObject.SignalFlags.RUN_LAST, None, ()),
    }
    
    def __init__(self):
        GObject.GObject.__init__(self)


class Parent(Child1, Child2):
    def __init__(self):
        Child1.__init__(self)
        Child2.__init__(self)


class Foo(GObject.GObject):
    def __init__(self):
        GObject.GObject.__init__(self)
    
    def func(self, _):
        pass

if __name__ == "__main__":
    foo = Foo()
    parent = Parent()
    parent.connect("one", foo.func) # OK
    parent.connect("two", foo.func) # fails

Error

Traceback (most recent call last):
  File "./TestSignal_Inheritance.py", line 41, in <module>
    parent.connect("two", foo.func) # fails
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: <__main__.Parent object at 0x0000022bd705a380 (__main__+Parent at 0x0000022bd54c20e0)>: unknown signal name: two

GObject does not support multiple inheritance, so Parent cannot inherit from both Child1 and Child2.

GObject uses interfaces for multiple inheritance, but you cannot define an interface in pygobject, AFAIK.

1 Like

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