Skip to content

Commit eeecc62

Browse files
authored
Merge 0976433 into 544ccb1
2 parents 544ccb1 + 0976433 commit eeecc62

File tree

8 files changed

+109
-17
lines changed

8 files changed

+109
-17
lines changed

source/braille.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
TetherTo,
4646
BrailleMode,
4747
ReportTableHeaders,
48+
OutputMode,
4849
)
4950
from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag
5051
from logHandler import log
@@ -1148,7 +1149,7 @@ def _setCursor(self, info: textInfos.TextInfo):
11481149

11491150
def _getTypeformFromFormatField(self, field, formatConfig):
11501151
typeform = louis.plain_text
1151-
if not formatConfig["reportFontAttributes"]:
1152+
if not formatConfig["reportFontAttributes"] & OutputMode.BRAILLE:
11521153
return typeform
11531154
if field.get("bold", False):
11541155
typeform |= louis.bold

source/config/configFlags.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,23 @@ def _displayStringLabels(self):
220220
# Translators: This is a label for the automatic update behaviour for add-ons.
221221
self.DISABLED: _("Disabled"),
222222
}
223+
224+
@unique
225+
class OutputMode(DisplayStringIntEnum):
226+
OFF = 0
227+
SPEECH = 1
228+
BRAILLE = 2
229+
SPEECH_AND_BRAILLE = 3
230+
231+
@property
232+
def _displayStringLabels(self):
233+
return {
234+
# Translators: This is a way of reporting information.
235+
self.OFF: _("Off"),
236+
# Translators: This is a way of reporting information.
237+
self.SPEECH: _("Speech"),
238+
# Translators: This is a way of reporting information.
239+
self.BRAILLE: _("Braille"),
240+
# Translators: This is a way of reporting information.
241+
self.SPEECH_AND_BRAILLE: _("Speech and braille"),
242+
}

source/config/configSpec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#: provide an upgrade step (@see profileUpgradeSteps.py). An upgrade step does not need to be added when
1414
#: just adding a new element to (or removing from) the schema, only when old versions of the config
1515
#: (conforming to old schema versions) will not work correctly with the new schema.
16-
latestSchemaVersion = 11
16+
latestSchemaVersion = 12
1717

1818
#: The configuration specification string
1919
#: @type: String
@@ -205,7 +205,8 @@
205205
detectFormatAfterCursor = boolean(default=false)
206206
reportFontName = boolean(default=false)
207207
reportFontSize = boolean(default=false)
208-
reportFontAttributes = boolean(default=false)
208+
# 0: Off, 1: Speech, 2: Braille, 3: Speech and Braille
209+
reportFontAttributes = integer(0, 3, default=0)
209210
reportRevisions = boolean(default=true)
210211
reportEmphasis = boolean(default=false)
211212
reportHighlight = boolean(default=true)

source/config/profileUpgradeSteps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ReportLineIndentation,
2323
ReportTableHeaders,
2424
ReportCellBorders,
25+
OutputMode,
2526
)
2627
import configobj.validate
2728
from configobj import ConfigObj
@@ -376,3 +377,18 @@ def upgradeConfigFrom_10_to_11(profile: ConfigObj) -> None:
376377
"hidBrailleStandard added to braille display auto detection excluded displays. "
377378
f"List is now: {profile['braille']['auto']['excludedDisplays']}"
378379
)
380+
381+
382+
def upgradeConfigFrom_11_to_12(profile: ConfigObj) -> None:
383+
"""Convert reportFontAttributes from a boolean to a choice of speech and/or braille."""
384+
try:
385+
reportFontAttributes: bool = profile["documentFormatting"].as_bool("reportFontAttributes")
386+
except KeyError:
387+
log.debug("reportFontAttributes not present in config, no action taken.")
388+
return
389+
except ValueError:
390+
log.debug("reportFontAttributes is not a boolean, deleting from config.")
391+
del profile["documentFormatting"]["reportFontAttributes"]
392+
return
393+
profile['documentFormatting']['reportFontAttributes'] = OutputMode.SPEECH_AND_BRAILLE if reportFontAttributes else OutputMode.OFF
394+
log.debug(f"documentFormatting.reportFontAttributes converted to {profile['documentFormatting']['reportFontAttributes']}.")

source/globalCommands.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
TetherTo,
4545
ShowMessages,
4646
BrailleMode,
47+
OutputMode,
4748
)
4849
from config.featureFlag import FeatureFlag
4950
from config.featureFlagEnums import BoolFlag
@@ -558,19 +559,26 @@ def script_toggleReportFontSize(self,gesture):
558559

559560
@script(
560561
# Translators: Input help mode message for toggle report font attributes command.
561-
description=_("Toggles on and off the reporting of font attributes"),
562+
description=_("Toggles between speaking, brailling, speaking and brailling, and not reporting font attributes."),
562563
category=SCRCAT_DOCUMENTFORMATTING
563564
)
564565
def script_toggleReportFontAttributes(self,gesture):
565-
if config.conf["documentFormatting"]["reportFontAttributes"]:
566-
# Translators: The message announced when toggling the report font attributes document formatting setting.
567-
state = _("report font attributes off")
568-
config.conf["documentFormatting"]["reportFontAttributes"]=False
569-
else:
570-
# Translators: The message announced when toggling the report font attributes document formatting setting.
571-
state = _("report font attributes on")
572-
config.conf["documentFormatting"]["reportFontAttributes"]=True
573-
ui.message(state)
566+
currentValue = config.conf["documentFormatting"]["reportFontAttributes"]
567+
nextValue = OutputMode((currentValue + 1) % len(OutputMode))
568+
if nextValue == OutputMode.OFF:
569+
# Translators: A state in which font attributes are not reported.
570+
status = _("Do not report font attributes")
571+
if nextValue == OutputMode.SPEECH:
572+
# Translators: A state in which font attributes are only spoken.
573+
status = _("Speak font attributes")
574+
if nextValue == OutputMode.BRAILLE:
575+
# Translators: A state in which font attributes are only brailled.
576+
status = _("Braille font attributes")
577+
if nextValue == OutputMode.SPEECH_AND_BRAILLE:
578+
# Translators: A state in which font attributes are both spoken and brailled.
579+
status = _("Speak and braille font attributes")
580+
config.conf["documentFormatting"]["reportFontAttributes"]=nextValue
581+
ui.message(status)
574582

575583
@script(
576584
# Translators: Input help mode message for toggle superscripts and subscripts command.

source/gui/settingsDialogs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,8 +2392,11 @@ def makeSettings(self, settingsSizer):
23922392
# Translators: This is the label for a checkbox in the
23932393
# document formatting settings panel.
23942394
fontAttributesText = _("Font attrib&utes")
2395-
self.fontAttrsCheckBox = fontGroup.addItem(wx.CheckBox(fontGroupBox, label=fontAttributesText))
2396-
self.fontAttrsCheckBox.SetValue(config.conf["documentFormatting"]["reportFontAttributes"])
2395+
from config.configFlags import OutputMode
2396+
fontAttributesOptions = [i.displayString for i in OutputMode]
2397+
self.fontAttrsCheckBox = fontGroup.addLabeledControl(fontAttributesText, wx.Choice, choices=fontAttributesOptions)
2398+
# self.fontAttrsCheckBox = fontGroup.addItem(wx.CheckBox(fontGroupBox, label=fontAttributesText))
2399+
self.fontAttrsCheckBox.SetSelection(config.conf["documentFormatting"]["reportFontAttributes"])
23972400

23982401
# Translators: This is the label for a checkbox in the
23992402
# document formatting settings panel.
@@ -2657,7 +2660,7 @@ def onSave(self):
26572660
config.conf["documentFormatting"]["detectFormatAfterCursor"]=self.detectFormatAfterCursorCheckBox.IsChecked()
26582661
config.conf["documentFormatting"]["reportFontName"]=self.fontNameCheckBox.IsChecked()
26592662
config.conf["documentFormatting"]["reportFontSize"]=self.fontSizeCheckBox.IsChecked()
2660-
config.conf["documentFormatting"]["reportFontAttributes"]=self.fontAttrsCheckBox.IsChecked()
2663+
config.conf["documentFormatting"]["reportFontAttributes"]=self.fontAttrsCheckBox.GetSelection()
26612664
config.conf["documentFormatting"]["reportSuperscriptsAndSubscripts"] = (
26622665
self.superscriptsAndSubscriptsCheckBox.IsChecked()
26632666
)

source/speech/speech.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
ReportLineIndentation,
6868
ReportTableHeaders,
6969
ReportCellBorders,
70+
OutputMode,
7071
)
7172
import aria
7273
from .priorities import Spri
@@ -2717,7 +2718,7 @@ def getFormatFieldSpeech( # noqa: C901
27172718
# Translators: Reported when text is no longer marked as emphasised
27182719
else _("not emphasised"))
27192720
textList.append(text)
2720-
if formatConfig["reportFontAttributes"]:
2721+
if formatConfig["reportFontAttributes"] & OutputMode.SPEECH:
27212722
bold=attrs.get("bold")
27222723
oldBold=attrsCache.get("bold") if attrsCache is not None else None
27232724
if (bold or oldBold is not None) and bold!=oldBold:

tests/unit/test_config.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
_upgradeConfigFrom_8_to_9_showMessages,
3030
_upgradeConfigFrom_8_to_9_tetherTo,
3131
upgradeConfigFrom_9_to_10,
32+
upgradeConfigFrom_11_to_12,
3233
)
3334
from config.configFlags import (
3435
NVDAKey,
3536
ShowMessages,
3637
ReportLineIndentation,
3738
ReportCellBorders,
3839
TetherTo,
40+
OutputMode,
3941
)
4042
from utils.displayString import (
4143
DisplayStringEnum
@@ -782,6 +784,46 @@ def test_ManualProfile_setNumpadInsertFalseExtendedInsertFalse(self):
782784
NVDAKey.CAPS_LOCK.value,
783785
)
784786

787+
class Config_upgradeProfileSteps_upgradeProfileFrom_11_to_12(unittest.TestCase):
788+
def test_DefaultProfile_Unmodified(self):
789+
"""reportFontAttributes unmodified."""
790+
configString = "[documentFormatting]"
791+
profile = _loadProfile(configString)
792+
upgradeConfigFrom_11_to_12(profile)
793+
with self.assertRaises(KeyError):
794+
profile['documentFormatting']['reportFontAttributes']
795+
796+
def test_defaultProfile_reportFontAttributes_false(self):
797+
"""reportFontAttributes unmodified set to False."""
798+
configString = """
799+
[documentFormatting]
800+
reportFontAttributes = False
801+
"""
802+
profile = _loadProfile(configString)
803+
upgradeConfigFrom_11_to_12(profile)
804+
self.assertEqual(profile['documentFormatting']['reportFontAttributes'], OutputMode.OFF.value)
805+
806+
def test_defaultProfile_reportFontAttributes_true(self):
807+
"""reportFontAttributes set to True."""
808+
configString = """
809+
[documentFormatting]
810+
reportFontAttributes = True
811+
"""
812+
profile = _loadProfile(configString)
813+
upgradeConfigFrom_11_to_12(profile)
814+
self.assertEqual(profile['documentFormatting']['reportFontAttributes'], OutputMode.SPEECH_AND_BRAILLE.value)
815+
816+
def test_defaultProfile_reportFontAttributes_invalid(self):
817+
"""reportFontAttributes set to a non-boolean value."""
818+
configString = """
819+
[documentFormatting]
820+
reportFontAttributes = notABool
821+
"""
822+
profile = _loadProfile(configString)
823+
upgradeConfigFrom_11_to_12(profile)
824+
with self.assertRaises(KeyError):
825+
profile['documentFormatting']['reportFontAttributes']
826+
785827

786828
class Config_AggregatedSection_getitem(unittest.TestCase):
787829
def setUp(self):

0 commit comments

Comments
 (0)