Add Orca extension for Wine accessibility
Publish the Wine Access protocol on Orca’s service connection and manage helpers per active Wine prefix. Add presentation, dialog capture, documentation, and tests. Preserve the Cthulhu default and shared helper code. Document the single-reader limit and verify Orca cleanup leaves Cthulhu-managed helpers alone. Retain integration artifacts on exceptional failures. Validation: 45 Orca unit tests passed; 11 existing test-environment checks passed; version metadata checks, Python compilation, and staged whitespace checks passed. Full Wine integration and live speech/braille remain unverified here because MinGW, Xvfb, and Orca are unavailable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b57681d159
commit
418f671066
13 files changed
+1913
-3
No files matched your search
@@ -0,0 +1,199 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
"""Wine Access for Orca.
|
||||
|
||||
Makes Orca read Windows programs running in Wine through the wine-access
|
||||
helper (https://git.stormux.org/storm/wine-access): standard dialogs, menus,
|
||||
lists and edit fields, plus NVDA Controller and Tolk speech from games and
|
||||
MUD clients. The extension publishes the Wine methods the helper calls on
|
||||
Orca's D-Bus service and starts one helper for each Wine prefix in use.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
from orca import debug, presentation_manager, typing_echo_presenter
|
||||
from orca.extension import Extension
|
||||
|
||||
from .manager import HelperManager
|
||||
from .presenter import WineEvent, WineEventPresenter
|
||||
from .review import DialogReader, gio_capture
|
||||
from .service import INTERFACE, OBJECT_PATH, WineAccessInterface
|
||||
|
||||
POLL_INTERVAL_MS = 2000
|
||||
READER_ARGUMENTS = ["--reader", "orca", "--reader-path", OBJECT_PATH,
|
||||
"--reader-interface", INTERFACE]
|
||||
# Multi-character labels the helper sends for typed whitespace.
|
||||
ACTION_LABELS = {"space", "tab", "new line"}
|
||||
|
||||
|
||||
def _log(*tokens: object) -> None:
|
||||
debug.print_tokens(debug.LEVEL_INFO, ["WINE ACCESS:", *tokens], True)
|
||||
|
||||
|
||||
class WineAccess(Extension):
|
||||
"""Reads Wine applications through the wine-access helper."""
|
||||
|
||||
GROUP_LABEL = "Wine Access"
|
||||
DESCRIPTION = "Reads Windows programs running in Wine: dialogs, menus, lists, " \
|
||||
"edit fields, and NVDA/Tolk speech from games."
|
||||
VERSION = "0.1.0"
|
||||
AUTHOR = "Devin Prater"
|
||||
WEBSITE = "https://git.stormux.org/storm/wine-access"
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._bus = None
|
||||
self._poll_id = 0
|
||||
self._retry_id = 0
|
||||
self._presenter: WineEventPresenter | None = None
|
||||
self._dialogs: DialogReader | None = None
|
||||
self._manager = HelperManager(READER_ARGUMENTS)
|
||||
|
||||
# Extension lifecycle
|
||||
|
||||
def on_ready(self) -> None:
|
||||
self._start()
|
||||
|
||||
def on_enabled(self) -> None:
|
||||
self._start()
|
||||
|
||||
def on_disabled(self) -> None:
|
||||
self._stop()
|
||||
|
||||
def on_shutdown(self) -> None:
|
||||
self._stop()
|
||||
|
||||
def _start(self) -> None:
|
||||
if self._bus is not None or self._retry_id:
|
||||
return
|
||||
if not self._publish():
|
||||
# Orca's D-Bus service may not be up yet.
|
||||
self._retry_id = GLib.timeout_add_seconds(2, self._retry_publish)
|
||||
return
|
||||
if not self._manager.helper:
|
||||
_log("wine-access helper not found; set WINE_ACCESS_HELPER or install it")
|
||||
return
|
||||
_log("helper", self._manager.helper)
|
||||
self._manager.poll()
|
||||
self._poll_id = GLib.timeout_add(POLL_INTERVAL_MS, self._manager.poll)
|
||||
|
||||
def _retry_publish(self) -> bool:
|
||||
self._retry_id = 0
|
||||
self._start()
|
||||
return False
|
||||
|
||||
def _publish(self) -> bool:
|
||||
bus = getattr(self.controller, "_bus", None)
|
||||
if bus is None:
|
||||
return False
|
||||
self._presenter = WineEventPresenter(
|
||||
self._present, self._echo, GLib.timeout_add, GLib.source_remove)
|
||||
self._dialogs = DialogReader(gio_capture(bus.connection),
|
||||
self._presenter.present_after_focus)
|
||||
try:
|
||||
bus.publish_object(OBJECT_PATH, WineAccessInterface(self))
|
||||
except Exception as error: # pylint: disable=broad-exception-caught
|
||||
_log("could not publish", OBJECT_PATH, error)
|
||||
self._presenter = None
|
||||
return False
|
||||
self._bus = bus
|
||||
_log("published", INTERFACE, "at", OBJECT_PATH)
|
||||
return True
|
||||
|
||||
def _stop(self) -> None:
|
||||
for source in (self._poll_id, self._retry_id):
|
||||
if source:
|
||||
GLib.source_remove(source)
|
||||
self._poll_id = self._retry_id = 0
|
||||
self._manager.shutdown()
|
||||
if self._presenter is not None:
|
||||
self._presenter.close()
|
||||
self._presenter = None
|
||||
self._dialogs = None
|
||||
if self._bus is not None:
|
||||
try:
|
||||
self._bus.unpublish_object(OBJECT_PATH)
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
pass
|
||||
self._bus = None
|
||||
|
||||
# Backend for WineAccessInterface
|
||||
|
||||
def speak_text(self, text: str, interrupt: bool) -> bool:
|
||||
if not text:
|
||||
return False
|
||||
manager = presentation_manager.get_manager()
|
||||
if interrupt:
|
||||
manager.interrupt_presentation(kill_flash=False)
|
||||
manager.speak_message(text)
|
||||
return True
|
||||
|
||||
def cancel_speech(self) -> bool:
|
||||
presentation_manager.get_manager().interrupt_presentation(kill_flash=False)
|
||||
return True
|
||||
|
||||
def braille_message(self, text: str) -> bool:
|
||||
if not text:
|
||||
return False
|
||||
presentation_manager.get_manager().present_braille_message(text)
|
||||
return True
|
||||
|
||||
def present_event(self, source: str, kind: str, name: str, role: str, value: str,
|
||||
states: str, description: str, position: int, count: int,
|
||||
window: str) -> bool:
|
||||
if self._presenter is None:
|
||||
return False
|
||||
return self._presenter.handle(WineEvent(
|
||||
source, kind, name, role, value, states, description, position, count, window))
|
||||
|
||||
def register_review(self, sender: str, path: str, version: int) -> bool:
|
||||
return self._dialogs is not None and self._dialogs.register(sender, path, version)
|
||||
|
||||
def review_focus(self, sender: str, window: str, focus: str, revision: int,
|
||||
title: str, role: str) -> bool:
|
||||
if self._dialogs is None:
|
||||
return False
|
||||
return self._dialogs.focus(sender, window, focus, revision, title, role)
|
||||
|
||||
# Presenter output
|
||||
|
||||
@staticmethod
|
||||
def _present(message: str, interrupt: bool) -> None:
|
||||
manager = presentation_manager.get_manager()
|
||||
if interrupt:
|
||||
manager.interrupt_presentation()
|
||||
manager.present_message(message)
|
||||
|
||||
@staticmethod
|
||||
def _key_echo_spoke(text: str) -> bool:
|
||||
"""Whether Orca's key echo already announced the key that typed text."""
|
||||
|
||||
echo = typing_echo_presenter.get_presenter()
|
||||
if not echo.get_key_echo_enabled():
|
||||
return False
|
||||
if text in ACTION_LABELS:
|
||||
return echo.get_action_keys_enabled()
|
||||
if text.isalpha():
|
||||
return echo.get_alphabetic_keys_enabled()
|
||||
if text.isdigit():
|
||||
return echo.get_numeric_keys_enabled()
|
||||
return echo.get_punctuation_keys_enabled()
|
||||
|
||||
def _echo(self, text: str, inserted: bool) -> None:
|
||||
manager = presentation_manager.get_manager()
|
||||
if inserted:
|
||||
# Typed characters follow Orca's character echo setting, and are
|
||||
# skipped when key echo has already spoken the key.
|
||||
echo = typing_echo_presenter.get_presenter()
|
||||
if not echo.get_character_echo_enabled() or self._key_echo_spoke(text):
|
||||
return
|
||||
else:
|
||||
# Caret movement replaces whatever was being said.
|
||||
manager.interrupt_presentation(kill_flash=False)
|
||||
if len(text) > 1:
|
||||
manager.present_braille_message(text)
|
||||
if len(text) == 1:
|
||||
manager.speak_character(text)
|
||||
else:
|
||||
manager.speak_message(text)
|
||||
Reference in new issue
Block a user