Skip to content

Commit

Permalink
help help menu to make it work on windows / linux w update
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus committed Jan 30, 2024
1 parent c01916d commit 06dd3b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
15 changes: 10 additions & 5 deletions core/addon_communication/ipc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
@mod.action_class
class Actions:
def addon_server_endpoint() -> Tuple[str, str, str]:
"""Returns the address and port of the addon server"""
"""Returns the address, port, and valid commands for the addon server"""

def send_ipc_commands(commands: list[str] | str):
"""Sends a command to the screenreader"""
"""Sends a command or commands to the screenreader"""


NVDAContext = Context()
Expand Down Expand Up @@ -44,7 +44,7 @@ def addon_server_endpoint() -> Tuple[str, str, str]:


def send_ipc_commands(commands: list[str] | str):
"""Sends a list of commands to the NVDA screenreader"""
"""Sends a list of commands or a single command string to the NVDA screenreader"""
ip, port, valid_commands = actions.user.addon_server_endpoint()

if isinstance(commands, str):
Expand All @@ -53,13 +53,16 @@ def send_ipc_commands(commands: list[str] | str):
for command in commands:
if command not in valid_commands:
raise ValueError(f"Invalid command: {command}")

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.1)
encoded = json.dumps(commands).encode()

if settings.get("user.addon_debug"):
print(f"Sending {commands} to {ip}:{port}")


# Although the screenreader server will block while processing commands,
# having a lock clientside reduces errors when sending multiple commands
with lock:
try:
sock.connect((ip, int(port)))
Expand All @@ -70,8 +73,10 @@ def send_ipc_commands(commands: list[str] | str):
response = sock.recv(1024)
if settings.get("user.addon_debug"):
print('Received', repr(response))
if command == ['debug'] or command == 'debug':

if 'debug' in commands:
actions.user.tts("Sent Message to NVDA Successfully")

except socket.timeout:
print("NVDA Addon Connection timed out")
except:
Expand Down
9 changes: 9 additions & 0 deletions nvda/debug-nvda.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
os: windows

-

test reader add on:
user.send_ipc_commands("debug")

test controller client:
user.test_controller_client()
3 changes: 3 additions & 0 deletions nvda/nvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def is_nvda_running() -> bool:
def nvda_tts(text: str, use_clipboard: bool= False):
'''text to speech with NVDA'''

def test_controller_client():
"""Tests the NVDA controller client"""
actions.user.tts(f"Controller client value is: {nvda_client.nvdaController_testIfRunning()}")

ctxWindowsNVDARunning = Context()
ctxWindowsNVDARunning.matches = r"""
Expand Down
2 changes: 0 additions & 2 deletions nvda/nvda.talon
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,3 @@ pass through next:
restart reader:
user.restart_nvda()

test reader add on:
user.send_ipc_commands("debug")
28 changes: 15 additions & 13 deletions utils/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ def get_active_commands():
"""Returns a list of all commands"""
command_dict = {}
for ctx in registry.active_contexts():
phrases = [html.escape(command.trigger) for command in ctx.commands.values()]
line_numbers = [command.lineno for command in ctx.commands.values()]
code = [html.escape(
str(command.script).replace("TalonScript(code='", "")[0:-2]
)
phrases = [str(command.rule).replace('Rule("', "")[0:-2]
for command in ctx.commands.values()]


# line_numbers = [command.lineno for command in ctx.commands.values()]
code = [html.escape(str(command.script)
)
for command in
ctx.commands.values()
]

ctx_name = html.escape(ctx.__repr__().replace("Context(", "")[0:-1])
ctx_name = ctx
command_dict[ctx_name] = {
"phrases": phrases,
"line_numbers": line_numbers,
# "line_numbers": line_numbers,
"code": code
}
return command_dict
Expand All @@ -37,15 +39,15 @@ def open_command_list():
for ctx in commands_list:

phrases = commands_list[ctx]["phrases"]
line_numbers = commands_list[ctx]["line_numbers"]
# line_numbers = commands_list[ctx]["line_numbers"]
fns = commands_list[ctx]["code"]

if len(phrases) == 0 or len(line_numbers) == 0:
continue
if len(phrases) == 0:
continue

builder.h1(ctx)
builder.start_table(["Command Phrase", "Code", "Line Number"]) # Removed extra comma
for phrase, line_number, code in zip(phrases, line_numbers, fns):
builder.add_row([phrase, code, line_number])
builder.start_table(["Command Phrase", "Code"]) # Removed extra comma
for phrase, code in zip(phrases, fns):
builder.add_row([phrase, code])
builder.end_table()
builder.render()

0 comments on commit 06dd3b9

Please sign in to comment.