Skip to content

Commit 7b192d8

Browse files
authored
Merge aa32f5c into 345154a
2 parents 345154a + aa32f5c commit 7b192d8

3 files changed

Lines changed: 60 additions & 7 deletions

File tree

source/globalCommands.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,12 +2577,13 @@ def script_reportStatusLine(self, gesture):
25772577
def script_reportFocusObjectAccelerator(self, gesture: inputCore.InputGesture) -> None:
25782578
obj = api.getFocusObject()
25792579
if obj.keyboardShortcut:
2580-
res = obj.keyboardShortcut
2580+
shortcut = obj.keyboardShortcut
2581+
speech.speak(speech.getKeyboardShortcutSpeech(shortcut))
2582+
braille.handler.message(shortcut)
25812583
else:
25822584
# Translators: reported when a user requests the accelerator key
25832585
# of the currently focused object, but there is none set.
2584-
res = _("No shortcut key")
2585-
ui.message(res)
2586+
ui.message(_("No shortcut key"))
25862587

25872588
@script(
25882589
# Translators: Input help mode message for toggle mouse tracking command.

source/speech/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2006-2021 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Babbage B.V., Bill Dengler,
5-
# Julien Cochuyt
4+
# Copyright (C) 2006-2023 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Babbage B.V., Bill Dengler,
5+
# Julien Cochuyt, Cyrille Bougot
66

77
from .speech import (
88
_extendSpeechSequence_addMathForTextInfo,
@@ -25,6 +25,7 @@
2525
getCurrentLanguage,
2626
getFormatFieldSpeech,
2727
getIndentationSpeech,
28+
getKeyboardShortcutSpeech,
2829
getObjectPropertiesSpeech,
2930
getObjectSpeech,
3031
getPreselectedTextSpeech,

source/speech/speech.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,7 @@ def getPropertiesSpeech( # noqa: C901
17251725
textList.append(description)
17261726
# sometimes keyboardShortcut key is present but value is None
17271727
keyboardShortcut: Optional[str] = propertyValues.get('keyboardShortcut')
1728-
if keyboardShortcut:
1729-
textList.append(keyboardShortcut)
1728+
textList.extend(getKeyboardShortcutSpeech(keyboardShortcut))
17301729
if includeTableCellCoords and cellCoordsText:
17311730
textList.append(cellCoordsText)
17321731
if cellCoordsText or rowNumber or columnNumber:
@@ -1861,6 +1860,58 @@ def getPropertiesSpeech( # noqa: C901
18611860
return textList
18621861

18631862

1863+
def getKeyboardShortcutSpeech(keyboardShortcut: Optional[str]) -> SpeechSequence:
1864+
log.info(f'Calling getKeyboardShortcutSequence with keyboardShortcut={keyboardShortcut}')
1865+
SHORTCUT_KEY_LIST_SEPARATOR = ' '
1866+
seq = []
1867+
if not keyboardShortcut:
1868+
return seq
1869+
locale = getCurrentLanguage()
1870+
for shortcut in keyboardShortcut.split(SHORTCUT_KEY_LIST_SEPARATOR):
1871+
if len(seq) > 0:
1872+
seq.append(SHORTCUT_KEY_LIST_SEPARATOR)
1873+
keyList, separator = splitShortcut(shortcut)
1874+
log.info(f'keyList={keyList}, separator={separator}')
1875+
seqShortcut = []
1876+
for key in keyList:
1877+
if len(seqShortcut) > 0:
1878+
seqShortcut.append(separator)
1879+
if len(key) > 1:
1880+
seqShortcut.append(key)
1881+
continue
1882+
keySymbol = characterProcessing.processSpeechSymbol(locale, key)
1883+
if keySymbol != key:
1884+
seqShortcut.append(keySymbol)
1885+
continue
1886+
seqShortcut.append(CharacterModeCommand(True))
1887+
seqShortcut.append(key)
1888+
seqShortcut.append(CharacterModeCommand(False))
1889+
seq.extend(seqShortcut)
1890+
seqOut = []
1891+
for item in seq:
1892+
if len(seqOut) > 0 and isinstance(seqOut[-1], str) and isinstance(item, str):
1893+
seqOut[-1] = seqOut[-1] + SHORTCUT_KEY_LIST_SEPARATOR + item
1894+
else:
1895+
seqOut.append(item)
1896+
return seqOut
1897+
1898+
1899+
def splitShortcut(shortcut):
1900+
if ', ' in shortcut:
1901+
separator = ', '
1902+
elif ' + ' in shortcut:
1903+
separator = ' + '
1904+
elif '+' in shortcut:
1905+
separator = '+'
1906+
else:
1907+
separator = None
1908+
if separator:
1909+
keyList = shortcut.split(separator)
1910+
else:
1911+
keyList = [shortcut]
1912+
return keyList, separator
1913+
1914+
18641915
def _shouldSpeakContentFirst(
18651916
reason: OutputReason,
18661917
role: int,

0 commit comments

Comments
 (0)