Skip to content

Commit 19e37f8

Browse files
authored
Merge 2641927 into a380b6a
2 parents a380b6a + 2641927 commit 19e37f8

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

source/mathPres/mathPlayer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# A part of NonVisual Desktop Access (NVDA)
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
5-
# Copyright (C) 2014-2022 NV Access Limited
5+
# Copyright (C) 2014-2023 NV Access Limited, Cyrille Bougot
66

77
"""Support for math presentation using MathPlayer 4.
88
"""
@@ -20,6 +20,7 @@
2020
from keyboardHandler import KeyboardInputGesture
2121
import braille
2222
import mathPres
23+
import config
2324

2425
from speech.commands import (
2526
PitchCommand,
@@ -68,7 +69,10 @@ def _processMpSpeech(text, language):
6869
if m.lastgroup == "break":
6970
out.append(BreakCommand(time=int(m.group("break")) * breakMulti))
7071
elif m.lastgroup == "char":
71-
out.extend((CharacterModeCommand(True), m.group("char"), CharacterModeCommand(False)))
72+
if config.conf["speech"][synth.name]["useSpellingFunctionality"]:
73+
out.extend((CharacterModeCommand(True), m.group("char"), CharacterModeCommand(False)))
74+
else:
75+
out.append(m.group("char"))
7276
elif m.lastgroup == "comma":
7377
out.append(BreakCommand(time=100))
7478
elif m.lastgroup in PROSODY_COMMANDS:

source/speech/shortcutKeys.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import characterProcessing
1313
from logHandler import log
14+
from synthDriverHandler import getSynth
15+
import config
1416

1517
from .commands import CharacterModeCommand
1618
from .types import SpeechSequence
@@ -79,6 +81,10 @@ def _getKeyboardShortcutSpeech(keyboardShortcut: str) -> SpeechSequence:
7981
return seq
8082

8183

84+
def shouldUseSpellingFunctionality() -> bool:
85+
synth = getSynth()
86+
return config.conf["speech"][synth.name]["useSpellingFunctionality"]
87+
8288
def _getKeySpeech(key: str) -> SpeechSequence:
8389
"""Gets the speech sequence for a string describing a key.
8490
@param key: the key string.
@@ -91,6 +97,8 @@ def _getKeySpeech(key: str) -> SpeechSequence:
9197
keySymbol = characterProcessing.processSpeechSymbol(locale, key)
9298
if keySymbol != key:
9399
return [keySymbol]
100+
if not shouldUseSpellingFunctionality():
101+
return [key]
94102
return [
95103
CharacterModeCommand(True),
96104
key,

tests/unit/test_speechShortcutKeys.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77
"""
88

99
import unittest
10+
from unittest.mock import patch
1011

1112
from speech.shortcutKeys import (
1213
_getKeyboardShortcutSpeech,
1314
getKeyboardShortcutsSpeech,
1415
)
16+
import speech.shortcutKeys
1517
from speech.commands import CharacterModeCommand
1618

1719

20+
original_shouldUseSpellingFunctionality = speech.shortcutKeys.shouldUseSpellingFunctionality
21+
1822
class Test_getKeyboardShortcutSpeech(unittest.TestCase):
1923

24+
@patch('speech.shortcutKeys.shouldUseSpellingFunctionality', lambda: True)
2025
def test_simpleLetterKey(self):
2126
"""A shortcut consisting in only one letter."""
2227

@@ -30,6 +35,21 @@ def test_simpleLetterKey(self):
3035
)
3136
self.assertEqual(repr(output), expected)
3237

38+
@patch('speech.shortcutKeys.shouldUseSpellingFunctionality', lambda: False)
39+
def test_simpleLetterKeyWithSpellingFunctionalityDisabled(self):
40+
"""A shortcut consisting in only one letter in the case where "Use spelling functionality" is disabled
41+
(see #15566).
42+
."""
43+
44+
expected = repr([
45+
'A',
46+
])
47+
output = _getKeyboardShortcutSpeech(
48+
keyboardShortcut='A',
49+
)
50+
self.assertEqual(repr(output), expected)
51+
52+
3353
def test_simpleSymbolKey(self):
3454
"""A shortcut consisting in only one symbol present in symbols.dic."""
3555

@@ -52,6 +72,7 @@ def test_simpleKeyName(self):
5272
)
5373
self.assertEqual(repr(output), expected)
5474

75+
@patch('speech.shortcutKeys.shouldUseSpellingFunctionality', lambda: True)
5576
def test_modifiersAndLetterKey(self):
5677
"""A shortcut consisting in modifiers and a letter key."""
5778

@@ -110,6 +131,7 @@ def test_modifierAndPlusKeyDescription(self):
110131
)
111132
self.assertEqual(repr(output), expected)
112133

134+
@patch('speech.shortcutKeys.shouldUseSpellingFunctionality', lambda: True)
113135
def test_sequentialShortcutCombiningSpacesAndCommas(self):
114136
"""A sequential shortcut found in ribbons (e.g. Word)."""
115137

@@ -136,6 +158,7 @@ def test_sequentialShortcutCombiningSpacesAndCommas(self):
136158

137159
class Test_getKeyboardShortcutsSpeech(unittest.TestCase):
138160

161+
@patch('speech.shortcutKeys.shouldUseSpellingFunctionality', lambda: True)
139162
def test_twoShortcutKeys(self):
140163
"""A shortcut key indication indicating two shortcut keys (a sequential one and a simultaneous one)
141164
as found in ribbons (e.g. Word).

0 commit comments

Comments
 (0)