[pygobject] Do not immediately initialize Gdk and Gtk on import



commit b8bf4ec6c2478275dc9c813946a90b82ded6d9ce
Author: Martin Pitt <martinpitt gnome org>
Date:   Wed Jan 23 07:14:16 2013 +0100

    Do not immediately initialize Gdk and Gtk on import
    
    Raising an exception if Gdk/Gtk cannot be imported makes it impossible to
    merely import a module for e. g. nosetests without actually running it.
    
    Programs who want to provide a proper error message should check
    Gtk.initialized explicitly after importing. Check initialized status in
    Window.__init__() instead to provide a reasonably early error message for most
    programs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692300

 gi/overrides/Gdk.py |    2 --
 gi/overrides/Gtk.py |    5 +++--
 2 files changed, 3 insertions(+), 4 deletions(-)
---
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index dc06f92..ceda261 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -421,5 +421,3 @@ if Gdk._version >= '3.0':
 import sys
 
 initialized, argv = Gdk.init_check(sys.argv)
-if not initialized:
-    raise RuntimeError("Gdk couldn't be initialized")
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 15c0ae6..25f127f 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -401,6 +401,9 @@ __all__.append('Builder')
 
 class Window(Gtk.Window):
     def __init__(self, type=Gtk.WindowType.TOPLEVEL, **kwds):
+        if not initialized:
+            raise RuntimeError("Gtk couldn't be initialized")
+
         # type is a construct-only property; if it is already set (e. g. by
         # GtkBuilder), do not try to set it again and just ignore it
         try:
@@ -1579,5 +1582,3 @@ def stock_lookup(*args):
 
 initialized, argv = Gtk.init_check(sys.argv)
 sys.argv = list(argv)
-if not initialized:
-    raise RuntimeError("Gtk couldn't be initialized")



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]