Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to speak next and previous lines/paragraphs when navigati… #17256

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ def nextLine(self):
return
dest.collapse()
self._setCursor(dest)
dest.expand(self._getReadingUnit())
_speakOnNavigatingByUnit(dest)

def previousLine(self, start=False):
dest = self._readingInfo.copy()
Expand All @@ -1677,11 +1679,13 @@ def previousLine(self, start=False):
pass
else:
dest = dest.obj.makeTextInfo(textInfos.POSITION_LAST)
dest.expand(unit)
else: # no page turn support
else:
# no page turn supportcode ..\nvda
return
dest.collapse()
self._setCursor(dest)
dest.expand(self._getReadingUnit())
_speakOnNavigatingByUnit(dest)


class CursorManagerRegion(TextInfoRegion):
Expand Down Expand Up @@ -3841,3 +3845,18 @@ def _speakOnRouting(info: textInfos.TextInfo):

info.expand(textInfos.UNIT_CHARACTER)
spellTextInfo(info)


def _speakOnNavigatingByUnit(info: textInfos.TextInfo):
"""Speaks the reading unit after navigating by it with braille.

:param info: The reading unit TextInfo at the cursor position after navigating.
"""
if not config.conf["braille"]["speakOnNavigatingByUnit"]:
return
# Import late to avoid circular import.
from speech.speech import cancelSpeech, speakTextInfo

readingUnit = handler.buffer.regions[-1]._getReadingUnit()
cancelSpeech()
speakTextInfo(info, unit=readingUnit, reason=controlTypes.OutputReason.CARET)
1 change: 1 addition & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
focusContextPresentation = option("changedContext", "fill", "scroll", default="changedContext")
interruptSpeechWhileScrolling = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
speakOnRouting = boolean(default=false)
speakOnNavigatingByUnit = boolean(default=false)
showSelection = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
reportLiveRegions = featureFlag(optionsEnum="BoolFlag", behaviorOfDefault="enabled")
fontFormattingDisplay = featureFlag(optionsEnum="FontFormattingBrailleModeFlag", behaviorOfDefault="LIBLOUIS")
Expand Down
19 changes: 18 additions & 1 deletion source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3556,7 +3556,8 @@ def script_toggleBrailleMode(self, gesture: inputCore.InputGesture):

@script(
# Translators: Input help mode message for cycle through
# braille move system caret when routing review cursor command.
# braille move system caret when routing
# review cursor command.
description=_("Cycle through the braille move system caret when routing review cursor states"),
category=SCRCAT_BRAILLE,
)
Expand Down Expand Up @@ -3654,6 +3655,22 @@ def script_braille_toggleSpeakOnRouting(self, gesture):
state = _("Disabled speak character when routing cursor in text")
ui.message(state)

@script(
# Translators: Input help mode message for toggle speaking when navigating by lines or paragraphs with braille.
description=_("Toggles on and off speaking when navigating by lines or paragraph with braille"),
category=SCRCAT_BRAILLE,
)
@gui.blockAction.when(gui.blockAction.Context.BRAILLE_MODE_SPEECH_OUTPUT)
def script_toggleSpeakingOnNavigatingByUnit(self, gesture: inputCore.InputGesture):
toggleBooleanValue(
configSection="braille",
configKey="speakOnNavigatingByUnit",
# Translators: The message announced when toggling the speaking on navigating by unit braille setting.
enabledMsg=_("Speak whenn navigating by line or paragraph with braille on"),
# Translators: The message announced when toggling the speaking on navigating by unit braille setting.
disabledMsg=_("Speak when navigating by line or paragraph with braille off"),
)

@script(
# Translators: Input help mode message for cycle braille cursor shape command.
description=_("Cycle through the braille cursor shapes"),
Expand Down
9 changes: 9 additions & 0 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,14 @@ def makeSettings(self, settingsSizer):
self.bindHelpEvent("BrailleSpeakOnRouting", self.speakOnRoutingCheckBox)
self.speakOnRoutingCheckBox.Value = config.conf["braille"]["speakOnRouting"]

# Translators: The label for a setting in braille settings to speak the current line or paragraph when navigating by them with braille.
speakOnNavigatingText = _("Speak &line or paragraph when navigating by them with braille")
self.speakOnNavigatingCheckBox = followCursorGroupHelper.addItem(
wx.CheckBox(self.followCursorGroupBox, label=speakOnNavigatingText),
)
self.bindHelpEvent("BrailleSpeakOnNavigating", self.speakOnNavigatingCheckBox)
self.speakOnNavigatingCheckBox.Value = config.conf["braille"]["speakOnNavigatingByUnit"]

self.followCursorGroupBox.Enable(
list(braille.BrailleMode)[self.brailleModes.GetSelection()] is braille.BrailleMode.FOLLOW_CURSORS,
)
Expand Down Expand Up @@ -4681,6 +4689,7 @@ def onSave(self):
self.paragraphStartMarkersComboBox.GetSelection()
]
config.conf["braille"]["speakOnRouting"] = self.speakOnRoutingCheckBox.Value
config.conf["braille"]["speakOnNavigatingByUnit"] = self.speakOnNavigatingCheckBox.Value
config.conf["braille"]["wordWrap"] = self.wordWrapCheckBox.Value
self.unicodeNormalizationCombo.saveCurrentValueToConf()
config.conf["braille"]["focusContextPresentation"] = self.focusContextPresentationValues[
Expand Down