From 42bfacdd2c42ce0b9ae924dd36eeaf5cefcb917d Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 7 Jan 2026 11:52:46 -0500 Subject: [PATCH] Updated version presentation to be more similar to orca. --- src/cthulhu.py | 24 +++++++++++-- src/cthulhu/cthulhu_bin.py.in | 24 +++++++++++-- src/cthulhu/dbus_service.py | 16 ++++++++- src/cthulhu/plugins/DisplayVersion/plugin.py | 36 +++++++++++++++++--- 4 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/cthulhu.py b/src/cthulhu.py index e416abd..2843c66 100644 --- a/src/cthulhu.py +++ b/src/cthulhu.py @@ -91,7 +91,7 @@ from cthulhu import messages from cthulhu import settings from cthulhu.ax_object import AXObject from cthulhu.ax_utilities import AXUtilities -from cthulhu.cthulhu_platform import version +from cthulhu.cthulhu_platform import version, revision class ListApps(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): @@ -115,6 +115,26 @@ class ListApps(argparse.Action): parser.exit() +class PrintVersion(argparse.Action): + """Action to print the version of Cthulhu.""" + + def __call__(self, parser, namespace, values, option_string=None): + msg = version + if revision: + msg += f" (rev {revision})" + + atspi_version = Atspi.get_version() + msg += f", AT-SPI2 version: {atspi_version[0]}.{atspi_version[1]}.{atspi_version[2]}" + + session_type = os.environ.get("XDG_SESSION_TYPE") or "" + session_desktop = os.environ.get("XDG_SESSION_DESKTOP") or "" + session = f"{session_type} {session_desktop}".strip() + if session: + msg += f", Session: {session}" + + print(msg) + parser.exit() + class Settings(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): settingsDict = getattr(namespace, 'settings', {}) @@ -151,7 +171,7 @@ class Parser(argparse.ArgumentParser): self.add_argument( "-h", "--help", action="help", help=messages.CLI_HELP) self.add_argument( - "-v", "--version", action="version", version=version, help=messages.CLI_VERSION) + "-v", "--version", action=PrintVersion, nargs=0, help=messages.CLI_VERSION) self.add_argument( "-r", "--replace", action="store_true", help=messages.CLI_REPLACE) self.add_argument( diff --git a/src/cthulhu/cthulhu_bin.py.in b/src/cthulhu/cthulhu_bin.py.in index f2b1ca5..98e01ad 100644 --- a/src/cthulhu/cthulhu_bin.py.in +++ b/src/cthulhu/cthulhu_bin.py.in @@ -49,7 +49,7 @@ from cthulhu import messages from cthulhu import settings from cthulhu.ax_object import AXObject from cthulhu.ax_utilities import AXUtilities -from cthulhu.cthulhu_platform import version +from cthulhu.cthulhu_platform import version, revision class ListApps(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): @@ -73,6 +73,26 @@ class ListApps(argparse.Action): parser.exit() +class PrintVersion(argparse.Action): + """Action to print the version of Cthulhu.""" + + def __call__(self, parser, namespace, values, option_string=None): + msg = version + if revision: + msg += f" (rev {revision})" + + atspi_version = Atspi.get_version() + msg += f", AT-SPI2 version: {atspi_version[0]}.{atspi_version[1]}.{atspi_version[2]}" + + session_type = os.environ.get("XDG_SESSION_TYPE") or "" + session_desktop = os.environ.get("XDG_SESSION_DESKTOP") or "" + session = f"{session_type} {session_desktop}".strip() + if session: + msg += f", Session: {session}" + + print(msg) + parser.exit() + class Settings(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): settingsDict = getattr(namespace, 'settings', {}) @@ -109,7 +129,7 @@ class Parser(argparse.ArgumentParser): self.add_argument( "-h", "--help", action="help", help=messages.CLI_HELP) self.add_argument( - "-v", "--version", action="version", version=version, help=messages.CLI_VERSION) + "-v", "--version", action=PrintVersion, nargs=0, help=messages.CLI_VERSION) self.add_argument( "-r", "--replace", action="store_true", help=messages.CLI_REPLACE) self.add_argument( diff --git a/src/cthulhu/dbus_service.py b/src/cthulhu/dbus_service.py index f77aad5..c2f5ebe 100644 --- a/src/cthulhu/dbus_service.py +++ b/src/cthulhu/dbus_service.py @@ -29,6 +29,7 @@ __license__ = "LGPL" import enum import inspect +import os from typing import Callable, Optional try: @@ -43,6 +44,10 @@ except ImportError: from gi.repository import GLib +import gi +gi.require_version("Atspi", "2.0") +from gi.repository import Atspi + from . import debug from . import cthulhu_platform # pylint: disable=no-name-in-module from . import script_manager @@ -482,12 +487,21 @@ if _dasbus_available: return True def GetVersion(self) -> str: # pylint: disable=invalid-name - """Returns Cthulhu's version and revision if available.""" + """Returns Cthulhu's version, AT-SPI version, and session information.""" result = cthulhu_platform.version if cthulhu_platform.revision: result += f" (rev {cthulhu_platform.revision})" + atspi_version = Atspi.get_version() + result += f", AT-SPI2 version: {atspi_version[0]}.{atspi_version[1]}.{atspi_version[2]}" + + session_type = os.environ.get("XDG_SESSION_TYPE") or "" + session_desktop = os.environ.get("XDG_SESSION_DESKTOP") or "" + session = f"{session_type} {session_desktop}".strip() + if session: + result += f", Session: {session}" + msg = f"DBUS SERVICE: GetVersion called, returning: {result}" debug.printMessage(debug.LEVEL_INFO, msg, True) return result diff --git a/src/cthulhu/plugins/DisplayVersion/plugin.py b/src/cthulhu/plugins/DisplayVersion/plugin.py index b3a80e5..bcd279a 100644 --- a/src/cthulhu/plugins/DisplayVersion/plugin.py +++ b/src/cthulhu/plugins/DisplayVersion/plugin.py @@ -10,21 +10,45 @@ """Display Version plugin for Cthulhu.""" import logging +import os + +import gi +gi.require_version("Atspi", "2.0") +from gi.repository import Atspi + from cthulhu.plugin import Plugin, cthulhu_hookimpl from cthulhu import cthulhuVersion +from cthulhu import cthulhu_platform from cthulhu import debug logger = logging.getLogger(__name__) class DisplayVersion(Plugin): """Plugin that announces the current Cthulhu version.""" - + def __init__(self, *args, **kwargs): """Initialize the plugin.""" super().__init__(*args, **kwargs) debug.printMessage(debug.LEVEL_INFO, "DisplayVersion: Plugin initialized", True) self._kb_binding = None self._activated = False + + def _get_version_string(self): + """Generate the full version string with AT-SPI and session information.""" + msg = f'Cthulhu screen reader version {cthulhuVersion.version}-{cthulhuVersion.codeName}' + if cthulhu_platform.revision: + msg += f' revision {cthulhu_platform.revision}' + + atspi_version = Atspi.get_version() + msg += f', AT-SPI2 version {atspi_version[0]}.{atspi_version[1]}.{atspi_version[2]}' + + session_type = os.environ.get('XDG_SESSION_TYPE') or '' + session_desktop = os.environ.get('XDG_SESSION_DESKTOP') or '' + session = f'{session_type} {session_desktop}'.strip() + if session: + msg += f', Session {session}' + + return msg @cthulhu_hookimpl def activate(self, plugin=None): @@ -51,10 +75,11 @@ class DisplayVersion(Plugin): # Register keyboard shortcut gesture_string = 'kb:cthulhu+shift+v' debug.printMessage(debug.LEVEL_INFO, f"DisplayVersion: Registering gesture: {gesture_string}", True) - + + version_message = self._get_version_string() self._kb_binding = self.registerGestureByString( - self.speakText, - f'Cthulhu screen reader version {cthulhuVersion.version}-{cthulhuVersion.codeName}', + self.speakText, + version_message, gesture_string ) @@ -87,8 +112,9 @@ class DisplayVersion(Plugin): if self.app: state = self.app.getDynamicApiManager().getAPI('CthulhuState') if state.activeScript: + version_message = self._get_version_string() state.activeScript.presentMessage( - f'Cthulhu screen reader version {cthulhuVersion.version}-{cthulhuVersion.codeName}', + version_message, resetStyles=False ) return True