Still attempting to fix imports.

This commit is contained in:
Storm Dragon 2025-03-25 07:48:08 -04:00
parent 20f294d840
commit 05645ae5f5
3 changed files with 55 additions and 23 deletions

View File

@ -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

49
src/cthulhu/gi_setup.py Normal file
View File

@ -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']

View File

@ -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):