I’m trying to use GtkApplication
with GtkApplicationWindow
. The latter is defined in a UI file. I can’t figure out how to properly set things up.
This is my Glade UI template outline:
And this is the Python code so far:
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio, Gtk
# NOTE: Not being used for this attempt.
class AppWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class Application(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(*args, application_id="org.opensource.mynotes",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
**kwargs)
self.window = None
self.add_main_option("test", ord("t"), GLib.OptionFlags.NONE,
GLib.OptionArg.NONE, "Command line test", None)
def do_startup(self):
Gtk.Application.do_startup(self)
def do_activate(self):
if not self.window:
# self.window = AppWindow(application=self, title="My Notes")
builder = Gtk.Builder()
builder.add_from_file("./mynotes.ui")
app_window = builder.get_object("app_window")
app_window.show_all()
self.window = app_window
self.window.present()
def do_command_line(self, command_line):
options = command_line.get_options_dict()
# convert GVariantDict -> GVariant -> dict
options = options.end().unpack()
if "test" in options:
# This is printed on the main instance
print("Test argument recieved: %s" % options["test"])
self.activate()
return 0
def on_about(self, action, param):
about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True)
about_dialog.present()
def on_quit(self, action, param):
self.quit()
if __name__ == "__main__":
app = Application()
app.run(sys.argv)
How to properly use GtkApplicationWindow
from Glade instead of from Python code? In other words, how to start the Application making use of an UI file which already contains GtkApplicationWindow
? My current attempt causes the application open and immediately close. No errors on the terminal.