GNOME Bugzilla – Bug 731091
Add option to skip gdk_init and gtk_init calls when importing Gdk and Gtk
Last modified: 2018-01-10 20:43:07 UTC
Auto initialization gives rise to some technical problems and confusion with the rest of the GNOME stack (bug 729643). We really should not implicitly use or modify sys.argv as a side effect of an import statement anyhow. The reason this is bad is because it removes control of command line parsing from application developers. For example, if an app wanted to use the "--name" option, this conflicts with Gdk which parses "--name" in its init. So you'd have to hack around that with: old_args = sys.argv sys.argv = [''] from gi.repository import Gdk sys.argv = old_args The proposal is a add a switch to gi that the Gdk and Gtk overrides can look at when they are imported: import gi gi.options['no_repo_auto_init'] = True from gi.repository import Gtk ... Gtk.init() Eventually, the auto initialization should be removed if possible.
Created attachment 277704 [details] [review] Add option to disable automatic init_check calls upon import of Gtk and Gdk Add gi.options['gtk_gdk_init_on_import'] which is True by default. Setting to False prior to importing Gtk or Gdk allows better control over sys.argv and init ordering after import statements (bug 729643). Notes: There is currently not a lot we can do to test this because we first need more robust testing features to support tests run in a new process (a generic approach to how pygtkcompat is tested).
Another couple of reasons why it's bad: * modules may end up importing Gdk/Gtk implicitly and end up initializing things out of order * we have a bunch of API that ought to be called before initialization, which is impossible to do with init-on-import
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/72.