Python bindings: Virtual methods in mixins have no effect
Virtual methods (like do_get_preferred_width
for example) only have an effect if they're implemented directly in a subclass of a Gtk class, as seen here:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Mixin:
def do_get_preferred_width(self):
print('Mixin.do_get_preferred_width called')
return 500
class MyWindow(Mixin, Gtk.Window):
def do_get_preferred_height(self):
print('MyWindow.do_get_preferred_height called')
return 500
window = MyWindow()
window.show()
window.connect('destroy', Gtk.main_quit)
Gtk.main()
# Output:
# MyWindow.do_get_preferred_height called
# MyWindow.do_get_preferred_height called
As you can see, Mixin.do_get_preferred_width
is never called.
It's also not possible to work around the problem by making Mixin
a subclass of Gtk.Widget
, because Gtk doesn't allow multiple inheritance with two Gtk.Widget
s.