# SPDX-License-Identifier: LGPL-2.1-or-later """The D-Bus object wine-access calls on Orca's service connection. dasbus builds the interface from these type hints, so this module must not use postponed annotations. """ from xml.etree import ElementTree from typing import Tuple from dasbus.server.interface import accepts_additional_arguments, dbus_interface from dasbus.typing import Bool, Int, ObjPath, Str, UInt32, UInt64 INTERFACE = "org.gnome.Orca1.WineAccess" OBJECT_PATH = "/org/gnome/Orca1/Service/WineAccess" ERROR_INVALID_PARAMETER = 87 ERROR_CALL_NOT_IMPLEMENTED = 120 def ssml_status(ssml: str) -> int: """Windows status for SpeakSsml: SSML timing and marks aren't supported.""" try: root = ElementTree.fromstring(ssml) except ElementTree.ParseError: return ERROR_INVALID_PARAMETER if root.tag.rsplit("}", 1)[-1].lower() != "speak": return ERROR_INVALID_PARAMETER return ERROR_CALL_NOT_IMPLEMENTED @dbus_interface(INTERFACE) class WineAccessInterface: """Forwards helper requests to a backend; a failure answers False.""" def __init__(self, backend): self._backend = backend def _call(self, name, *arguments): try: return bool(getattr(self._backend, name)(*arguments)) except Exception: # pylint: disable=broad-exception-caught return False def SpeakText(self, text: Str, interrupt: Bool) -> Bool: # pylint: disable=invalid-name return self._call("speak_text", text, interrupt) def CancelSpeech(self) -> Bool: # pylint: disable=invalid-name return self._call("cancel_speech") def BrailleMessage(self, text: Str) -> Bool: # pylint: disable=invalid-name return self._call("braille_message", text) def SpeakSsml(self, source: Str, ssml: Str) -> Int: # pylint: disable=invalid-name del source return ssml_status(ssml) def PresentAccessibleEvent( # pylint: disable=invalid-name,too-many-arguments self, source: Str, event_type: Str, name: Str, role: Str, value: Str, states: Str, description: Str, position: Int, count: Int, window_title: Str, ) -> Bool: return self._call("present_event", source, event_type, name, role, value, states, description, position, count, window_title) # Optional review protocol version 1: the helper's review object is # called back on the sender's connection, so pass the sender along. @accepts_additional_arguments def RegisterWineReviewProvider( # pylint: disable=invalid-name self, path: ObjPath, version: UInt32, **info ) -> Bool: return self._call("register_review", info["call_info"]["sender"], path, version) @accepts_additional_arguments def PresentWineReviewFocus( # pylint: disable=invalid-name,too-many-arguments self, instance: Str, window: Str, focus: Str, revision: UInt64, title: Str, role: Str, protected: Bool, bounds: Tuple[Int, Int, Int, Int], **info ) -> Bool: del instance, protected, bounds return self._call("review_focus", info["call_info"]["sender"], window, focus, revision, title, role)