Hi,
I am trying to do some debugging using PyGtk and the following short app
#!/usr/bin/python
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
class MyNotebook(Gtk.Notebook):
def do_insert_page(self, child, label, menu, position):
if not menu:
menu = Gtk.Label(label.get_text())
return super(MyNotebook, self).do_insert_page(child, label, menu, position)
class App:
def __init__(self):
window = Gtk.Window()
window.connect("destroy", self.on_window_destroy)
notebook = MyNotebook()
label = Gtk.Label("Test Page")
button = Gtk.Button("Button")
notebook.append_page(button, label)
window.add(notebook)
window.show_all()
def on_window_destroy(self, window):
Gtk.main_quit()
if __name__ == "__main__":
app = App()
Gtk.main()
However, when I run it, I get the following exception:
Traceback (most recent call last):
File "./main.py", line 12, in do_insert_page
return super(MyNotebook, self).do_insert_page(child, label, menu, position)
TypeError: Gtk.Notebook.insert_page() takes exactly 5 arguments (4 given)
Looking at the help for the do_insert_page()
virtual function shows that it maps to Gtk.Notebook.insert_page()
. So, replacing the line super(MyNotebook, self).do_insert_page(child, label, menu, position)
with Gtk.Notebook.insert_page(self, child, label, menu, position)
results in the following error:
Traceback (most recent call last):
File "./main.py", line 10, in do_insert_page
return Gtk.Notebook.insert_page(self, child, label, menu, position)
TypeError: Gtk.Notebook.insert_page() takes exactly 4 arguments (5 given)
If I took out self
from the argument list, I get a different error:
Traceback (most recent call last):
File "./main.py", line 10, in do_insert_page
return Gtk.Notebook.insert_page(child, label, menu, position)
TypeError: argument self: Expected Gtk.Notebook, but got gi.overrides.Gtk.Button
What is the proper way to override the class’s insert_page
method but still call the superclass’s method at the end?
Thank you.