GtkApplication and Python singleton

Hi! I am trying to dive into Gtk+ development once again. I am trying to use GtkApplication as core of my new app and I was wondering is there any built in functionality that would allow it to act like true singleton within Python paradigm (so I wouldn’t have to pass pointer to it to all critical parts of app), or it is something to create custom for myself.
I understand it acts like singleton within system paradigm, thus allowing running command line arguments and pass to existing instances, etc.

GtkApplication is automatically a singleton in the process: the first instance will be set as the “default” instance, and it’s accessible using g_application_get_default(), which in Python is Gio.Application.get_default().

In general, though, there’s very little reason to use the application singleton: most of the time you’ll either deal with actions on the application instance; or with actions on the application’s window, which lets you go back to the application’s instance that owns them via the GtkWindow:application property. Even if you’re deep into a signal handler for a widget, you can go back to the top-level window that contains the widget, and from there you can get to the application’s instance.

1 Like

Amazing, thanks for info :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.