Options for controlling how and when speech is interrupted now wired up in preferences under the speech tab.
This commit is contained in:
1 parent
e62f8c8e17
commit
3e9c4f83ce
32 files changed
+784
-47
No files matched your search
@@ -185,7 +185,35 @@ def check_flat_review(tabs, server, readerLog):
|
||||
server.snapshot()[-1]["finished"], "return to tab header was suppressed")
|
||||
|
||||
|
||||
def check_runtime(radioOnly=False, flatReviewOnly=False):
|
||||
def check_interruption_summary(controls, tabs, server):
|
||||
import pyatspi
|
||||
|
||||
def key(*keys):
|
||||
subprocess.run(["xdotool", "key", "--clearmodifiers", *keys], check=True)
|
||||
|
||||
assert tabs.querySelection().selectChild(2)
|
||||
summary = controls["Defined interruption keys"]
|
||||
assert summary.queryText().getText(0, -1) == "Tab, Enter"
|
||||
assert not summary.getState().contains(pyatspi.STATE_EDITABLE)
|
||||
assert controls["Record interruption keys"].queryComponent().grabFocus()
|
||||
offset = len(server.snapshot())
|
||||
key("Tab")
|
||||
wait_for(lambda: any(record["text"] == "Tab, Enter" and record["finished"]
|
||||
for record in server.snapshot()[offset:]), "read-only summary contents were not spoken on focus")
|
||||
assert any(record["text"] == "Defined interruption keys" for record in server.snapshot()[offset:])
|
||||
key("Home")
|
||||
for keyName, character, caret in (("Right", "a", 1), ("Left", "T", 0)):
|
||||
offset = len(server.snapshot())
|
||||
key(keyName)
|
||||
wait_for(lambda: summary.queryText().caretOffset == caret, "summary caret did not move for " + keyName)
|
||||
wait_for(lambda: any(record["text"] == character and record["finished"]
|
||||
for record in server.snapshot()[offset:]), "summary character was not spoken for " + keyName)
|
||||
key("shift+Tab")
|
||||
wait_for(lambda: controls["Record interruption keys"].getState().contains(pyatspi.STATE_FOCUSED),
|
||||
"read-only summary trapped Shift+Tab")
|
||||
|
||||
|
||||
def check_runtime(radioOnly=False, flatReviewOnly=False, interruptionOnly=False):
|
||||
import pyatspi
|
||||
directory = Path(tempfile.mkdtemp(prefix="cthulhu-echo-runtime-"))
|
||||
binary = os.environ["CTHULHU_BINARY"]
|
||||
@@ -218,6 +246,9 @@ gain = 5
|
||||
name = "Echo A"
|
||||
lang = "en"
|
||||
''')
|
||||
if interruptionOnly:
|
||||
with configPath.open("a") as settingsFile:
|
||||
settingsFile.write('\n[profiles.default.speech.interruption]\nmode = "custom"\nkeys = ["Tab", "Return"]\n')
|
||||
if radioOnly:
|
||||
configPath.write_text(configPath.read_text().replace(
|
||||
"[profiles.default.sound]\nenabled = false",
|
||||
@@ -257,6 +288,10 @@ lang = "en"
|
||||
xid = subprocess.check_output(["xdotool", "search", "--onlyvisible", "--name", "^Cthulhu Preferences$"], text=True).splitlines()[0]
|
||||
subprocess.run(["xdotool", "windowactivate", "--sync", xid], check=True)
|
||||
tabs = next(node for node in walk(window) if node.getRole() == pyatspi.ROLE_PAGE_TAB_LIST)
|
||||
if interruptionOnly:
|
||||
check_interruption_summary(controls, tabs, server)
|
||||
print(f"PASS: real reader speaks read-only interruption summary on focus and character arrows; Tab traversal preserved; evidence: {directory}")
|
||||
return
|
||||
if flatReviewOnly:
|
||||
check_flat_review(tabs, server, directory / "reader.log")
|
||||
print(f"PASS: notebook flat review has no repeated tab speech; tab changes and focus returns speak; evidence: {directory}")
|
||||
|
||||
@@ -46,6 +46,10 @@ class ResponseReader:
|
||||
|
||||
|
||||
def inside():
|
||||
if os.environ.get("CTHULHU_PREFS_INTERRUPTION_RUNTIME_ONLY") == "1":
|
||||
from native_echo_preview import check_runtime
|
||||
check_runtime(interruptionOnly=True)
|
||||
return
|
||||
if os.environ.get("CTHULHU_PREFS_FLAT_REVIEW_ONLY") == "1":
|
||||
from native_echo_preview import check_runtime
|
||||
check_runtime(flatReviewOnly=True)
|
||||
@@ -202,6 +206,103 @@ def inside():
|
||||
xid = subprocess.check_output(["xdotool", "search", "--onlyvisible", "--name", "^" + window_name + "$"], text=True).splitlines()[0]
|
||||
subprocess.run(["xdotool", "windowfocus", xid], check=True)
|
||||
assert not any(node.name == "Profiles" for node in nodes), "removed profile controls remain in preferences"
|
||||
if os.environ.get("CTHULHU_PREFS_INTERRUPTION_ONLY") == "1":
|
||||
from native_x11 import press_physical_key
|
||||
tabs = next(node for node in nodes if node.getRole() == pyatspi.ROLE_PAGE_TAB_LIST)
|
||||
assert tabs.querySelection().selectChild(2), "cannot select Speech tab"
|
||||
allKeys = named("All keys interrupt")
|
||||
commonKeys = named("Control, Enter, Space, and Escape")
|
||||
customKeys = named("Define interruption keys")
|
||||
recordButton = named("Record interruption keys")
|
||||
summary = named("Defined interruption keys")
|
||||
history = named("Speech history entries")
|
||||
statusNode = named(initial["Message"])
|
||||
applyCount = 0
|
||||
|
||||
def is_focused(node):
|
||||
return any(child.getState().contains(pyatspi.STATE_FOCUSED) for child in walk(node))
|
||||
|
||||
def apply_interruption(mode, expectedKeys):
|
||||
nonlocal applyCount
|
||||
focus(named("Apply")); key("space")
|
||||
applied = request()
|
||||
assert applied["Save"] and not applied["Close"], applied
|
||||
values = applied["Values"]
|
||||
assert values["SpeechInterruption"] == {"Mode": mode, "Keys": expectedKeys}, values["SpeechInterruption"]
|
||||
applyCount += 1
|
||||
message = f"Interruption settings saved {applyCount}."
|
||||
send(dict(initial, Values=values, Message=message))
|
||||
wait_for(lambda: statusNode.name == message and named("Apply").getState().contains(pyatspi.STATE_SENSITIVE),
|
||||
"Apply response did not finish reloading the draft")
|
||||
return values
|
||||
|
||||
def recorder():
|
||||
for app in pyatspi.Registry.getDesktop(0):
|
||||
for child in app:
|
||||
if child and child.name == "Record interruption keys" and child.getRole() == pyatspi.ROLE_DIALOG:
|
||||
return child
|
||||
return None
|
||||
|
||||
def begin_recording():
|
||||
focus(recordButton); key("space")
|
||||
dialog = wait_for(recorder, "key recorder did not open")
|
||||
dialogID = subprocess.check_output(["xdotool", "search", "--onlyvisible", "--name", "^Record interruption keys$"], text=True).splitlines()[0]
|
||||
subprocess.run(["xdotool", "windowfocus", dialogID], check=True)
|
||||
assert "Control+Enter" in dialog.description and "Control+Escape" in dialog.description
|
||||
return dialog
|
||||
|
||||
assert allKeys.getState().contains(pyatspi.STATE_CHECKED)
|
||||
assert not recordButton.getState().contains(pyatspi.STATE_SENSITIVE)
|
||||
apply_interruption("all", None)
|
||||
focus(named("Verbose")); key("Tab")
|
||||
wait_for(lambda: is_focused(allKeys), "Tab did not reach interruption group; focused: " +
|
||||
repr([(node.name, node.getRoleName()) for node in walk(window) if node.getState().contains(pyatspi.STATE_FOCUSED)]))
|
||||
key("Down")
|
||||
wait_for(lambda: commonKeys.getState().contains(pyatspi.STATE_CHECKED), "arrow did not select common keys")
|
||||
apply_interruption("common", None)
|
||||
focus(commonKeys); key("Down")
|
||||
wait_for(lambda: customKeys.getState().contains(pyatspi.STATE_CHECKED), "arrow did not select custom keys")
|
||||
key("Tab")
|
||||
wait_for(lambda: is_focused(recordButton), "Tab did not reach recording button")
|
||||
key("Tab")
|
||||
wait_for(lambda: is_focused(summary), "Tab did not reach defined keys")
|
||||
key("Home", "Right")
|
||||
wait_for(lambda: summary.queryText().caretOffset == 1, "read-only summary did not move its caret")
|
||||
key("Tab")
|
||||
wait_for(lambda: is_focused(history), "defined keys trapped Tab")
|
||||
key("shift+Tab", "shift+Tab", "shift+Tab")
|
||||
wait_for(lambda: is_focused(customKeys), "Shift+Tab did not return through new controls")
|
||||
dialog = begin_recording()
|
||||
key("Tab", "Return", "space", "Escape", "Tab")
|
||||
press_physical_key(0xFFE1) # Left Shift, without synthesized modifiers.
|
||||
press_physical_key(0xFFE4) # Right Control.
|
||||
press_physical_key(0xFF55) # Page Up: GTK calls this Page_Up, X11 calls it Prior.
|
||||
press_physical_key(0x1008FF12) # Audio mute: GTK omits the XF86 prefix.
|
||||
assert recorder() is not None, "a recordable key closed the recorder"
|
||||
key("ctrl+Return")
|
||||
wait_for(lambda: recorder() is None, "Control+Enter did not finish")
|
||||
wait_for(lambda: is_focused(recordButton), "recording did not return focus to button")
|
||||
expectedKeys = ["Tab", "Return", "space", "Escape", "Shift_L", "Control_R", "Prior", "XF86AudioMute"]
|
||||
saved = apply_interruption("custom", expectedKeys)
|
||||
assert customKeys.getState().contains(pyatspi.STATE_CHECKED), "Apply lost custom mode"
|
||||
assert "Tab" in summary.queryText().getText(0, -1), "Apply lost displayed keys"
|
||||
begin_recording(); key("F8", "ctrl+Escape")
|
||||
wait_for(lambda: recorder() is None, "Control+Escape did not cancel")
|
||||
wait_for(lambda: is_focused(recordButton), "cancellation did not return focus")
|
||||
apply_interruption("custom", expectedKeys)
|
||||
begin_recording(); key("ctrl+Return")
|
||||
assert recorder() is not None, "empty recording was accepted"
|
||||
key("F8", "ctrl+Return")
|
||||
wait_for(lambda: recorder() is None, "replacement recording did not finish")
|
||||
apply_interruption("custom", ["F8"])
|
||||
# Non-custom modes preserve the defined list for later reuse.
|
||||
focus(customKeys); key("Up", "Up")
|
||||
wait_for(lambda: allKeys.getState().contains(pyatspi.STATE_CHECKED), "arrows did not return to All keys interrupt")
|
||||
apply_interruption("all", ["F8"])
|
||||
focus(named("Cancel")); key("space")
|
||||
assert process.wait(timeout=5) == 0
|
||||
print("PASS: interruption modes, keyboard traversal, Tab/Enter/Space/Escape and modifier recording, finish/cancel, duplicates, replacement, Apply and draft reload")
|
||||
return
|
||||
if echoFocusMode:
|
||||
tabs = next(n for n in nodes if n.getRole() == pyatspi.ROLE_PAGE_TAB_LIST)
|
||||
assert tabs.querySelection().selectChild(4), "cannot select Key Echo tab"
|
||||
|
||||
@@ -45,6 +45,14 @@ def main():
|
||||
combined.get_accessible().add_relationship(Atk.RelationType.LABELLED_BY, label.get_accessible())
|
||||
box.pack_start(combined, False, False, 0)
|
||||
entries.append(combined)
|
||||
summary = Gtk.Entry()
|
||||
summary.set_text("Example summary")
|
||||
summary.set_editable(False)
|
||||
label = Gtk.Label(label="Read-only summary:")
|
||||
label.set_mnemonic_widget(summary)
|
||||
box.pack_start(label, False, False, 0)
|
||||
box.pack_start(summary, False, False, 0)
|
||||
entries.append(summary)
|
||||
window.show_all()
|
||||
Gdk.Display.get_default().sync()
|
||||
subprocess.run(["xdotool", "windowfocus", str(GdkX11.X11Window.get_xid(window.get_window()))], check=True)
|
||||
|
||||
Reference in new issue
Block a user