I am trying to call a specific constructor of the parent class from a subclass. I tried using the method described here, but I am getting an TypeError message.
Here is the test code:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class ComboBoxEntry(Gtk.ComboBox):
@classmethod
def new_with_entry(cls):
super(ComboBoxEntry, cls).new_with_entry()
combo1 = Gtk.ComboBox().new_with_entry()
print(combo1.get_has_entry)
combo2 = ComboBoxEntry().new_with_entry()
print(combo2.get_has_entry)
Gtk.ComboBox has several constructors. Instancing it without specifying any will create the ComboBox instance without Gtk.Entry present. Instancing it with new_with_entry() constructor create an empty ComboBox with Gtk.Entry present.
My subclass is expecting the Gtk.Entry to be present. Thus, I need to somehow invoke the new_with_entry() constructor.
Running the above code produces following Error:
TypeError: ComboBox constructor cannot be used to create instances od a subclass ComboBoxEntry
How can I call a parent class custom constructor?