Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Split speakSelectionMessage and speakPreselectedText to return speech…
… sequences
  • Loading branch information
feerrenrut committed Jan 29, 2020
commit ed9b9ff145d132ce34ca9b953bd06fb51a434bec
51 changes: 40 additions & 11 deletions source/speech/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,33 @@ def speakPreselectedText(
inform a user that the newly focused control has content that is selected,
which they may unintentionally overwrite.

@remarks: Implemented using L{speakSelectionMessage}, which allows for
speaking text with an arbitrary attached message.
@remarks: Implemented using L{getPreselectedTextSpeech}
"""
seq = getPreselectedTextSpeech(text)
if seq:
speak(seq, symbolLevel=None, priority=priority)


def getPreselectedTextSpeech(
text: str
) -> SpeechSequence:
""" Helper method to get the speech sequence to announce a newly focused control already has
text selected.
This method will speak the word "selected" with the provided text appended.
The announcement order is different from L{speakTextSelected} in order to
inform a user that the newly focused control has content that is selected,
which they may unintentionally overwrite.

@remarks: Implemented using L{_getSelectionMessageSpeech}, which allows for
creating a speech sequence with an arbitrary attached message.
"""
# Translators: This is spoken to indicate that some text is already selected.
# 'selected' preceding text is intentional.
# For example 'selected hello world'
speakSelectionMessage(_("selected %s"), text, priority)
return _getSelectionMessageSpeech(
# Translators: This is spoken to indicate that some text is already selected.
# 'selected' preceding text is intentional.
# For example 'selected hello world'
_("selected %s"),
text
)


def speakTextSelected(
Expand All @@ -752,13 +772,22 @@ def speakSelectionMessage(
text: str,
priority: Optional[Spri] = None
):
if len(text) < 512:
speakMessage(message % text,priority=priority)
else:
# Translators: This is spoken when the user has selected a large portion of text. Example output "1000 characters"
speakMessage(message % _("%d characters") % len(text),priority=priority)
seq = _getSelectionMessageSpeech(message, text)
if seq:
speak(seq, symbolLevel=None, priority=priority)


def _getSelectionMessageSpeech(
message: str,
text: str,
) -> SpeechSequence:
if len(text) < 512:
return _getSpeakMessageSpeech(message % text)
# Translators: This is spoken when the user has selected a large portion of text.
# Example output "1000 characters"
numCharactersText = _("%d characters") % len(text)
return _getSpeakMessageSpeech(message % numCharactersText)

# C901 'speakSelectionChange' is too complex
# Note: when working on speakSelectionChange, look for opportunities to simplify
# and move logic out into smaller helper functions.
Expand Down