diff --git a/src/cthulhu/gi_setup.py b/src/cthulhu/gi_setup.py index 62f38c0..f683867 100644 --- a/src/cthulhu/gi_setup.py +++ b/src/cthulhu/gi_setup.py @@ -21,29 +21,48 @@ import gi -# Set the GIRepository version first - handle different versions for compatibility +# FIRST: Load GIRepository with the correct version +# This is critical: get GIRepository loaded BEFORE anything else try: gi.require_version('GIRepository', '3.0') -except ValueError: - gi.require_version('GIRepository', '2.0') + from gi.repository import GIRepository +except (ValueError, ImportError): + try: + gi.require_version('GIRepository', '2.0') + from gi.repository import GIRepository + except (ValueError, ImportError): + print("WARNING: Could not load GIRepository with either version 2.0 or 3.0") -# Now set versions for all other required GI modules +# SECOND: Set versions for other modules and import them gi.require_version('Atspi', '2.0') gi.require_version('Gdk', '3.0') gi.require_version('Peas', '1.0') -# Import all commonly used gi modules to make them available through this module -from gi.repository import GObject -from gi.repository import Atspi -from gi.repository import Gdk -from gi.repository import Peas +try: + from gi.repository import GObject +except ImportError: + GObject = None + +try: + from gi.repository import Atspi +except ImportError: + Atspi = None + +try: + from gi.repository import Gdk +except ImportError: + Gdk = None + +try: + from gi.repository import Peas +except ImportError: + Peas = None try: gi.require_version('Gio', '2.0') from gi.repository import Gio -except ValueError: +except (ValueError, ImportError): Gio = None - -# Export all the imported modules for convenience -__all__ = ['gi', 'GObject', 'Atspi', 'Gdk', 'Peas', 'Gio'] +# Export all the imported modules +__all__ = ['gi', 'GObject', 'Atspi', 'Gdk', 'Peas', 'Gio', 'GIRepository']