From 05645ae5f5cba80b4ab481c282dd80f30c700b92 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 25 Mar 2025 07:48:08 -0400 Subject: [PATCH] Still attempting to fix imports. --- src/cthulhu/cthulhu.py | 13 +++----- src/cthulhu/gi_setup.py | 49 ++++++++++++++++++++++++++++ src/cthulhu/plugin_system_manager.py | 16 +-------- 3 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 src/cthulhu/gi_setup.py diff --git a/src/cthulhu/cthulhu.py b/src/cthulhu/cthulhu.py index ba0a3b4..4dc29fd 100644 --- a/src/cthulhu/cthulhu.py +++ b/src/cthulhu/cthulhu.py @@ -34,7 +34,6 @@ __copyright__ = "Copyright (c) 2004-2009 Sun Microsystems Inc." \ __license__ = "LGPL" import faulthandler -import gi import importlib import os import re @@ -42,15 +41,13 @@ import signal import subprocess import sys -gi.require_version("Atspi", "2.0") -gi.require_version("Gdk", "3.0") -from gi.repository import Atspi -from gi.repository import Gdk -from gi.repository import GObject +# Import from centralized GI setup +from cthulhu.gi_setup import gi, GObject, Atspi, Gdk +# Try to import Gio from gi_setup (add it to gi_setup.py) try: - from gi.repository.Gio import Settings - a11yAppSettings = Settings(schema_id='org.gnome.desktop.a11y.applications') + from cthulhu.gi_setup import Gio + a11yAppSettings = Gio.Settings(schema_id='org.gnome.desktop.a11y.applications') except Exception: a11yAppSettings = None diff --git a/src/cthulhu/gi_setup.py b/src/cthulhu/gi_setup.py new file mode 100644 index 0000000..62f38c0 --- /dev/null +++ b/src/cthulhu/gi_setup.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Stormux +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., Franklin Street, Fifth Floor, +# Boston MA 02110-1301 USA. + +"""Centralized setup for GObject Introspection (GI) in Cthulhu.""" + +import gi + +# Set the GIRepository version first - handle different versions for compatibility +try: + gi.require_version('GIRepository', '3.0') +except ValueError: + gi.require_version('GIRepository', '2.0') + +# Now set versions for all other required GI modules +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: + gi.require_version('Gio', '2.0') + from gi.repository import Gio +except ValueError: + Gio = None + + +# Export all the imported modules for convenience +__all__ = ['gi', 'GObject', 'Atspi', 'Gdk', 'Peas', 'Gio'] diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index a33c54b..642edc1 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -31,22 +31,8 @@ if version in ["3.3","3.4"]: from importlib.machinery import SourceFileLoader else: # Python 3.5+, no support for python < 3.3. import importlib.util -import gi -# First handle GIRepository version -try: - gi.require_version('GIRepository', '3.0') -except ValueError: - gi.require_version('GIRepository', '2.0') - -# IMPORTANT: No gi.repository imports should happen before GIRepository version is set -gi.require_version('Peas', '1.0') -gi.require_version('Atspi', '2.0') - -# Now it's safe to import from gi.repository -from gi.repository import GObject -from gi.repository import Peas -from gi.repository import Atspi +from cthulhu.gi_setup import GObject, Peas, Atspi, gi from cthulhu import resource_manager class API(GObject.GObject):