diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2019-01-26 21:31:02 +0100 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2019-01-28 16:16:53 +0000 |
commit | 624ea3ec615ad82d5138eb034e7c02c79608441e (patch) | |
tree | 716ee5a3b6384971b2450ab06e23fca17865370e | |
parent | 208a6295893d9da6e511d9f1a09be0ebe8eec646 (diff) | |
download | pygobject-624ea3ec615ad82d5138eb034e7c02c79608441e.tar.gz |
gtk: raise in case Gtk.Window is instantiated after init failed. See #298
gtk crashes if gtk_init() fails and we can't do much about it.
This assumes the Gtk.Window() is the first instantiated widget and
raises an exception in case init failed.
We already had such a check but it was removed in 86a37d67455d
for some reason (maybe because it only helps in some cases)
-rw-r--r-- | gi/overrides/Gtk.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index ba0a71dc..b5c2dd06 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -506,11 +506,19 @@ __all__.append('Builder') # NOTE: This must come before any other Window/Dialog subclassing, to ensure # that we have a correct inheritance hierarchy. +_window_init = deprecated_init(Gtk.Window.__init__, + arg_names=('type',), + category=PyGTKDeprecationWarning, + stacklevel=3) + class Window(Gtk.Window): - __init__ = deprecated_init(Gtk.Window.__init__, - arg_names=('type',), - category=PyGTKDeprecationWarning) + def __init__(self, *args, **kwargs): + if not initialized: + raise RuntimeError( + "Gtk couldn't be initialized. " + "Use Gtk.init_check() if you want to handle this case.") + _window_init(self, *args, **kwargs) Window = override(Window) @@ -1627,7 +1635,7 @@ if Gtk._version in ("2.0", "3.0"): __all__.append('stock_lookup') if Gtk._version == "4.0": - Gtk.init_check() + initialized = Gtk.init_check() else: initialized, argv = Gtk.init_check(sys.argv) sys.argv = list(argv) |