Skip to content

Commit

Permalink
Added some fixes for Windows accessibility APIs and finished testing …
Browse files Browse the repository at this point in the history
…on Linux and Windows, as well as with talon community
  • Loading branch information
chaosparrot committed Dec 1, 2024
1 parent 9ceb1f0 commit c15e9be
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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).
2 changes: 1 addition & 1 deletion accessibility/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
52 changes: 43 additions & 9 deletions accessibility/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion talon_hud_integration/index_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c15e9be

Please sign in to comment.