From c15e9beb9e5ba6c65231249231e46129150d8f2a Mon Sep 17 00:00:00 2001 From: chaosparrot Date: Sun, 1 Dec 2024 14:06:02 +0100 Subject: [PATCH] Added some fixes for Windows accessibility APIs and finished testing on Linux and Windows, as well as with talon community --- README.md | 11 ++--- accessibility/macos.py | 2 +- accessibility/windows.py | 52 ++++++++++++++++---- talon_hud_integration/index_visualisation.py | 2 +- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c299a58..ac8e8ed 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,10 @@ If you want to highlight a specific set of tests, go inside of the specific test #### Documentation -[ ] - Create a usage and installation video +[] - Create a usage and installation video Videos seem to speak to people more than written text does, so accompany this with a video as well -[ ] - Extension possibilities for other packages +[] - Extension possibilities for other packages There's a ton of ways other packages can make use of our captures, settings and detections, but we will need to document them so they are easier to reuse as well. #### Dictation @@ -133,9 +133,4 @@ This is partially implemented for the current text area, but we could do it for This repository started off as a clone from the [talon community repository](https://github.com/talonhub/community), but as time went on and my changes became less and less specialized for my own needs, I decided to start making a package of its own. A lot of inspiration was gained from the community repository, like formatters, but I've tried to make this repository stand on its own as much as possible. As such, I've only included the history of that previous repository from the start of my fork on July 27th, 2023, as I hadn't done any updating of my community talon files since then because of potential merge conflicts. -Any remnants of code that maybe accidentally left over from the original community repository, has been made by [the contributors of that repository](https://github.com/talonhub/community/graphs/contributors). - -TODOs - -- Checking on Linux -- Testing with knausj_talon community repository \ No newline at end of file +Any remnants of code that maybe accidentally left over from the original community repository, has been made by [the contributors of that repository](https://github.com/talonhub/community/graphs/contributors). \ No newline at end of file diff --git a/accessibility/macos.py b/accessibility/macos.py index f920d3e..4ff4534 100644 --- a/accessibility/macos.py +++ b/accessibility/macos.py @@ -32,7 +32,7 @@ def index_element_text(self, element = None) -> AccessibilityText: if accessibility_text: caret_position = self.determine_caret_positions(element) - if len(caret_position) == 2: + if caret_position is not None and len(caret_position) == 2: accessibility_text.active_caret = caret_position[0] accessibility_text.selection_caret = caret_position[1] diff --git a/accessibility/windows.py b/accessibility/windows.py index f3cfe92..83eee79 100644 --- a/accessibility/windows.py +++ b/accessibility/windows.py @@ -12,21 +12,34 @@ def index_element_text(self, element = None) -> AccessibilityText: return None accessibility_text = None + value = None if "LegacyIAccessible" in element.patterns: - value = element.text_pattern2.document_range.text + try: + value = element.legacyiaccessible_pattern.value + # Windows sometimes just throws operation successful errors... + except OSError: + value = value accessibility_text = AccessibilityText(value) elif "Text2" in element.patterns: - value = element.text_pattern2.document_range.text + try: + value = element.text_pattern2.document_range.text + # Windows sometimes just throws operation successful errors... + except OSError: + value = value accessibility_text = AccessibilityText(value) elif "Value" in element.patterns: - value = element.value_pattern.value + try: + value = element.value_pattern.value + # Windows sometimes just throws operation successful errors... + except OSError: + value = value accessibility_text = AccessibilityText(value) if accessibility_text: caret_position = self.determine_caret_positions(element) - if len(caret_position) == 2: + if caret_position is not None and len(caret_position) == 2: accessibility_text.active_caret = caret_position[0] accessibility_text.selection_caret = caret_position[1] @@ -56,17 +69,38 @@ def determine_caret_positions(self, element = None) -> List[AccessibilityCaret]: # Move the end of the copy to the start of the selection # range_before_selection.end = selection_range.start range_before_selection.move_endpoint_by_range("End", "Start", target=selection_range) + try: + range_before_selection_text = range_before_selection.text + # Windows sometimes just throws operation successful errors... + except OSError: + pass + + try: + selection_range_text = selection_range.text + # Windows sometimes just throws operation successful errors... + except OSError: + pass + + try: + document_range_text = text_pattern.document_range.text + # Windows sometimes just throws operation successful errors... + except OSError: + pass # Find the index by using the before selection text and the indexed text - start = len(range_before_selection.text) - start_position = self.indexer.determine_caret_position(range_before_selection.text, text_pattern.document_range.text, start) - end = len(range_before_selection.text + selection_range.text) - end_position = self.indexer.determine_caret_position(range_before_selection.text + selection_range.text, text_pattern.document_range.text, end) + start = len(range_before_selection_text) + start_position = self.indexer.determine_caret_position(range_before_selection_text, document_range_text, start) + end = len(range_before_selection_text + selection_range_text) + end_position = self.indexer.determine_caret_position(range_before_selection_text + selection_range_text, document_range_text, end) if (start_position[0] > -1 and start_position[1] > -1) or (end_position[0] > -1 and end_position[1] > -1): # The selection is reversed if the caret is at the start of the selection - is_reversed = text_pattern.caret_range.compare_endpoints("Start", "Start", target=selection_ranges[0]) == 0 + try: + is_reversed = text_pattern.caret_range.compare_endpoints("Start", "Start", target=selection_ranges[0]) == 0 + # Windows sometimes just throws operation successful errors... + except OSError: + pass start_caret = AccessibilityCaret(start, start_position[0], start_position[1]) end_caret = AccessibilityCaret(end, end_position[0], end_position[1]) diff --git a/talon_hud_integration/index_visualisation.py b/talon_hud_integration/index_visualisation.py index 5e982d7..8f42ec0 100644 --- a/talon_hud_integration/index_visualisation.py +++ b/talon_hud_integration/index_visualisation.py @@ -3,7 +3,7 @@ from typing import List, Union import os -def index_document(): +def index_document(_ = None, _2 = None): actions.user.marithime_index_textarea() ctx_override = Context()