Hi there. I’m considering porting some python & gtk3 ( plus a LOT of builder.ui files ) stuff to gtk4. I’ve had a look at cambalache, and I think this might all work. However I don’t immediately see how to trigger the gtk main loop. In gtk3 I used to go:
Create a GtkApplication instance—either a direct one, or (better) a derived class with all your global application data—then create your window in the “activate” signal handler.
Strictly speaking, this is also recommended in GTK3.
Yes I’m aware there are no widgets in the builder ui file. When I run this, the window pops up and immediately disappears, with the application exiting.
You need to add the window to the application. The application’s lifetime is bound to the number of windows it has, so that when the last window is closed, the application automatically terminates:
def on_activate(app):
builder = Gtk.Builder.new_from_file('test.ui')
test = builder.get_object('test')
app.add_window(test)
test.present()
The next step is to create a subclass of GtkApplicationWindow, and use a template instead of creating a GtkBuilder and getting the window out of it.