Skip to content

Commit

Permalink
access focus and ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Feb 22, 2024
1 parent 08e0ba9 commit 259ba2b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
7 changes: 3 additions & 4 deletions core/screenreader_ipc/ipc_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from talon import Module, Context, actions, settings
import os, ipaddress, json, socket
import threading
import os, ipaddress, json, socket, threading
from typing import Tuple
from .ipc_schema import IPC_COMMAND

Expand Down Expand Up @@ -92,13 +91,13 @@ def send_ipc_commands(commands: list[IPC_COMMAND]):
except socket.timeout as e:
print(f"Clientside connection with {ip}:{port} timed out")
print(e)
if "debug" in commands:
if "debug" in commands:
actions.user.tts("Clientside connection timed out")
except:
print("Error Communicating with NVDA extension")
if "debug" in commands:
actions.user.tts("Error Communicating with NVDA extension")
finally:
finally:
sock.close()

def send_ipc_command(command: IPC_COMMAND):
Expand Down
2 changes: 1 addition & 1 deletion nvda/nvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def nvda_tts(text: str, use_clipboard: bool= False):
if res != 0:
errorMessage = str(ctypes.WinError(res))
# ctypes.windll.user32.MessageBoxW(0, "Error: %s" % errorMessage, "Error communicating between Talon and NVDA", 0)
raise Exception("Error communicating between Talon and NVDA: %s" % errorMessage)
raise Exception(f"Error communicating between Talon and NVDA: {errorMessage}")

# Text can be sent via the clipboard or directly to NVDA using the dll
if use_clipboard:
Expand Down
35 changes: 35 additions & 0 deletions utils/access-focus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from talon import Module, ui, Context
from talon.windows import ax as ax

mod = Module()

def get_every_child(element: ax.Element):
if element.children:
for child in element.children:
yield child
yield from get_every_child(child)

ctx = Context()

mod.list("dynamic_children", desc="List of children of the active window")

@ctx.dynamic_list("user.dynamic_children")
def dynamic_children() -> dict[str,str]:
root = ui.active_window().element
elements = list(get_every_child(root))

return {str(i.name): str(i.name) for i in elements}

@mod.action_class
class Actions:
def focus_element_by_name(name: str):
"""Focuses on an element by name"""
root = ui.active_window().element
elements = list(get_every_child(root))
for element in elements:
if element.name == name or \
str(element.name).lower() == name:
element.invoke_pattern.invoke()
break
else:
print("Element not found")
2 changes: 2 additions & 0 deletions utils/access-focus.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^access {user.dynamic_children}$:
user.focus_element_by_name(dynamic_children)

0 comments on commit 259ba2b

Please sign in to comment.