Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d5af0b8
Added a output mode config flag
SaschaCowley Jun 26, 2024
02f5d3f
Updated configuration to separate font attribute reporting into off, …
SaschaCowley Jun 26, 2024
65b12e8
Updated configuration to separate font attribute reporting into off, …
SaschaCowley Jun 26, 2024
c8ac176
Added unittests for profile upgrade steps
SaschaCowley Jun 26, 2024
87828f9
Fixed settings so that they can now be saved again
SaschaCowley Jun 26, 2024
daf7f60
Updated speech and braille to respect the new reportFontAttributes se…
SaschaCowley Jun 26, 2024
9233587
Merge branch 'formattingSeparateSpeechAndBraille' of https://github.c…
SaschaCowley Jun 26, 2024
67092fa
Fixed upgrade steps to use as_bool
SaschaCowley Jun 26, 2024
5d277f9
Added error handling for the case where a non-boolean value is given …
SaschaCowley Jun 26, 2024
cc142ae
Updated toggle report font attributes command to cycle through the mo…
SaschaCowley Jun 26, 2024
0976433
Merge branch 'master' into formattingSeparateSpeechandBraille
SaschaCowley Jun 26, 2024
60cfc08
Updated configSpec to include a new key for the changed behaviour, an…
SaschaCowley Jun 27, 2024
9ce0378
Updated unit tests for uprade steps
SaschaCowley Jun 27, 2024
e2eec32
Added an alias from documentFormatting.reportFontAttributes to docume…
SaschaCowley Jun 27, 2024
875b9d9
Updated to use documentFormatting.fontAttributeReporting instead of d…
SaschaCowley Jun 27, 2024
b2e7310
Added unit tests for alias
SaschaCowley Jun 27, 2024
d68ce59
Merge branch 'master' into formattingSeparateSpeechandBraille
SaschaCowley Jun 27, 2024
b41545b
Added change log entries
SaschaCowley Jun 27, 2024
0172889
Merge branch 'master' into test
SaschaCowley Jul 2, 2024
8c49c2c
Moved alias unittests up for better readability
SaschaCowley Jul 2, 2024
5bb7655
Renamed fontAttrsCheckBox to fontAttrsList
SaschaCowley Jul 2, 2024
9b999b3
Updated `script_toggleReportFontAttributes` to use `if ... elif ... e…
SaschaCowley Jul 2, 2024
7ecd8d2
Apply suggestions from code review
SaschaCowley Jul 3, 2024
094ace4
Restored newline at EOF
SaschaCowley Jul 3, 2024
2879e13
Improved translator strings
SaschaCowley Jul 3, 2024
eff0626
Made config.configFlags.OutputMode a global import
SaschaCowley Jul 3, 2024
a771dec
Updated `script_toggleReportFontAttributes` to use a `match case` rat…
SaschaCowley Jul 3, 2024
ac3669e
Moved aliasing code to a helper function
SaschaCowley Jul 3, 2024
e631416
Added version check and deprecation warning.
SaschaCowley Jul 3, 2024
a3a82b0
Improved description of `script_toggleReportFontAttributes`
SaschaCowley Jul 3, 2024
98cc9c5
Added type hint
SaschaCowley Jul 3, 2024
649c9e6
Moved helper out of public API
SaschaCowley Jul 3, 2024
efffb17
Added documentation to clarify why this isn't a flag type, but that t…
SaschaCowley Jul 9, 2024
7c5c398
Added inSpeech and inBraille properties to OutputMode, and used them …
SaschaCowley Jul 9, 2024
01e3734
Renamed aliasing function
SaschaCowley Jul 9, 2024
1578186
Updated the aliasing code to use match statements, and improved the d…
SaschaCowley Jul 9, 2024
9a5d5a0
Merge branch 'master' into formattingSeparateSpeechandBraille
SaschaCowley Jul 9, 2024
f83401d
Merge branch 'master' into formattingSeparateSpeechAndBraille
SaschaCowley Jul 10, 2024
e357b23
Added tests for OutputMode.inSpeech and OutputMode.inBraille
SaschaCowley Jul 10, 2024
7d92ce8
Fixed linting errors
SaschaCowley Jul 10, 2024
f5ffc29
Improved documentation of profile upgrade function
SaschaCowley Jul 10, 2024
fd33ea1
Added documentation of the new options
SaschaCowley Jul 10, 2024
26eaebc
Added context help binding from font attributes combo box to user guide
SaschaCowley Jul 10, 2024
3352a44
Apply suggestions from code review
SaschaCowley Jul 11, 2024
7ac184a
Revert "Added inSpeech and inBraille properties to OutputMode, and us…
SaschaCowley Jul 11, 2024
c345618
Revert "Added tests for OutputMode.inSpeech and OutputMode.inBraille"
SaschaCowley Jul 11, 2024
592ab33
Fixed up lint error
SaschaCowley Jul 11, 2024
31bbe9d
Made `OutputMode` a subclass of `DisplayStringIntFlag`
SaschaCowley Jul 11, 2024
41513ad
Updated comment to reflect that the linking code will be commented, n…
SaschaCowley Jul 11, 2024
b29c96f
Merge branch 'master' into formattingSeparateSpeechandBraille
SaschaCowley Jul 11, 2024
c595180
Update user_docs/en/userGuide.md
seanbudd Jul 11, 2024
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
4 changes: 2 additions & 2 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _getFormatFieldAtRange( # noqa: C901
IDs.add(UIAHandler.UIA_FontNameAttributeId)
if formatConfig["reportFontSize"]:
IDs.add(UIAHandler.UIA_FontSizeAttributeId)
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
IDs.update(
{
UIAHandler.UIA_FontWeightAttributeId,
Expand Down Expand Up @@ -265,7 +265,7 @@ def _getFormatFieldAtRange( # noqa: C901
if isinstance(val, numbers.Number):
# Translators: Abbreviation for points, a measurement of font size.
formatField["font-size"] = pgettext("font size", "%s pt") % float(val)
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
val = fetcher.getValue(UIAHandler.UIA_FontWeightAttributeId, ignoreMixedValues=ignoreMixedValues)
if isinstance(val, int):
formatField["bold"] = val >= 700
Expand Down
4 changes: 2 additions & 2 deletions source/NVDAObjects/window/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)
fontSize = charFormat.yHeight // 20
# Translators: Abbreviation for points, a measurement of font size.
formatField["font-size"] = pgettext("font size", "%s pt") % fontSize
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
if charFormat is None:
charFormat = self._getCharFormat(offset) # noqa: E701
formatField["bold"] = bool(charFormat.dwEffects & CFE_BOLD)
Expand Down Expand Up @@ -712,7 +712,7 @@ def _getFormatFieldAtRange(self, textRange, formatConfig): # noqa: C901
fontObj = textRange.font
# Translators: Abbreviation for points, a measurement of font size.
formatField["font-size"] = pgettext("font size", "%s pt") % fontObj.size
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
if not fontObj:
fontObj = textRange.font
formatField["bold"] = bool(fontObj.bold)
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)
if formatConfig["reportFontSize"]:
# Translators: Abbreviation for points, a measurement of font size.
formatField["font-size"] = pgettext("font size", "%s pt") % fontObj.size
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
formatField["bold"] = fontObj.bold
formatField["italic"] = fontObj.italic
underline = fontObj.underline
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/scintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)
formatField["font-size"] = pgettext("font size", "%s pt") % fontSize
if formatConfig["reportLineNumber"]:
formatField["line-number"] = self._getLineNumFromOffset(offset) + 1
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
formatField["bold"] = bool(
watchdog.cancellableSendMessage(self.obj.windowHandle, SCI_STYLEGETBOLD, style, 0),
)
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class WinWordColor(IntEnum):
formatConfigFlagsMap = {
"reportFontName": 0x1,
"reportFontSize": 0x2,
"reportFontAttributes": 0x4,
"fontAttributeReporting": 0x4,
"reportColor": 0x8,
"reportAlignment": 0x10,
"reportStyle": 0x20,
Expand Down
2 changes: 1 addition & 1 deletion source/appModules/powerpnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True)
if formatConfig["reportFontSize"]:
# Translators: Abbreviation for points, a measurement of font size.
formatField["font-size"] = pgettext("font size", "%s pt") % font.size
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"]:
formatField["bold"] = bool(font.bold)
formatField["italic"] = bool(font.italic)
formatField["underline"] = bool(font.underline)
Expand Down
3 changes: 2 additions & 1 deletion source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TetherTo,
BrailleMode,
ReportTableHeaders,
OutputMode,
)
from config.featureFlagEnums import ReviewRoutingMovesSystemCaretFlag
from logHandler import log
Expand Down Expand Up @@ -1173,7 +1174,7 @@ def _setCursor(self, info: textInfos.TextInfo):

def _getTypeformFromFormatField(self, field, formatConfig):
typeform = louis.plain_text
if not formatConfig["reportFontAttributes"]:
if not (formatConfig["fontAttributeReporting"] & OutputMode.BRAILLE):
Comment thread
SaschaCowley marked this conversation as resolved.
return typeform
if field.get("bold", False):
typeform |= louis.bold
Expand Down
2 changes: 1 addition & 1 deletion source/browseMode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ def _extractStyles(
reportFormattingOptions = (
"reportFontName",
"reportFontSize",
"reportFontAttributes",
"fontAttributeReporting",
"reportSuperscriptsAndSubscripts",
"reportHighlight",
"reportColor",
Expand Down
53 changes: 52 additions & 1 deletion source/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from . import profileUpgrader
from . import aggregatedSection
from .configSpec import confspec
from .configFlags import OutputMode
from .featureFlag import (
_transformSpec_AddFeatureFlagDefault,
_validateConfig_featureFlag,
Expand All @@ -51,7 +52,7 @@
)
import NVDAState
from NVDAState import WritePaths

from buildVersion import version_year

#: True if NVDA is running as a Windows Store Desktop Bridge application
isAppX = False
Expand Down Expand Up @@ -1304,6 +1305,56 @@ def __setitem__(
self.manager._markWriteProfileDirty()
self._cache[key] = val

# Alias [documentFormatting][reportFontAttributes] for backwards compatibility.
# TODO: Comment out in 2025.1.
if version_year < 2025 and NVDAState._allowDeprecatedAPI():
self._linkDeprecatedValues(key, val)

def _linkDeprecatedValues(self, key: aggregatedSection._cacheKeyT, val: aggregatedSection._cacheValueT):
Comment thread
SaschaCowley marked this conversation as resolved.
"""Link deprecated config keys and values to their replacements.

Args:
key: The configuration key to link to its new or old counterpart.
val: The value associated with the configuration key.

postconditions:
- If self.path is "documentFormatting":
- If key is "reportFontAttributes":
- If val is True, "documentFormatting.fontAttributeReporting" is set to OutputMode.SPEECH_AND_BRAILLE, otherwise, it is set to OutputMode.OFF.
- If key is "fontAttributeReporting":
- if val is OutputMode.OFF, "documentFormatting.reportFontAttributes" is set to False, otherwise, it is set to True.
"""
match self.path:
case ("documentFormatting",):
match key:
case "fontAttributeReporting":
# Alias documentFormatting.fontAttributeReporting to documentFormatting.reportFontAttributes for backwards compatibility.
key = "reportFontAttributes"
val = bool(val)
Comment thread
seanbudd marked this conversation as resolved.

case "reportFontAttributes":
# Alias documentFormatting.reportFontAttributes to documentFormatting.fontAttributeReporting for forwards compatibility.
log.warning(
"documentFormatting.reportFontAttributes is deprecated. Use documentFormatting.fontAttributeReporting instead.",
# Include stack info so testers can report warning to add-on author.
stack_info=True,
)
key = "fontAttributeReporting"
val = OutputMode.SPEECH_AND_BRAILLE if val else OutputMode.OFF

case _:
# We don't care about other keys in this section.
return

case _:
# We don't care about other sections.
return

# Update the value in the most recently activated profile.
Comment thread
seanbudd marked this conversation as resolved.
# If we have reached this point, we must have a new key and value to set.
self._getUpdateSection()[key] = val
self._cache[key] = val

def _getUpdateSection(self):
profile = self.profiles[-1]
if profile is not None:
Expand Down
26 changes: 26 additions & 0 deletions source/config/configFlags.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,29 @@ def _displayStringLabels(self):
# Translators: This is a label for the automatic update behaviour for add-ons.
self.DISABLED: _("Disabled"),
}


@unique
class OutputMode(DisplayStringIntFlag):
"""Enumeration for ways to output information, such as formatting.
Use OutputMode.MEMBER.value to compare with the config;
use OutputMode.MEMBER.displayString in the UI for a translatable description of this member.
"""

OFF = 0b0
SPEECH = 0b01
BRAILLE = 0b10
SPEECH_AND_BRAILLE = SPEECH | BRAILLE

@property
def _displayStringLabels(self):
return {
# Translators: A label for an option to choose a method of reporting information, e.g. font attributes.
self.OFF: _("Off"),
# Translators: A label for an option to choose a method of reporting information, e.g. font attributes.
self.SPEECH: _("Speech"),
# Translators: A label for an option to choose a method of reporting information, e.g. font attributes.
self.BRAILLE: _("Braille"),
# Translators: A label for an option to choose a method of reporting information, e.g. font attributes.
self.SPEECH_AND_BRAILLE: _("Speech and braille"),
}
7 changes: 5 additions & 2 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#: provide an upgrade step (@see profileUpgradeSteps.py). An upgrade step does not need to be added when
#: just adding a new element to (or removing from) the schema, only when old versions of the config
#: (conforming to old schema versions) will not work correctly with the new schema.
latestSchemaVersion = 11
latestSchemaVersion = 12
Comment thread
seanbudd marked this conversation as resolved.

#: The configuration specification string
#: @type: String
Expand Down Expand Up @@ -205,7 +205,10 @@
detectFormatAfterCursor = boolean(default=false)
reportFontName = boolean(default=false)
reportFontSize = boolean(default=false)
reportFontAttributes = boolean(default=false)
# Deprecated in 2025.1
reportFontAttributes = boolean(default=false)
Comment thread
SaschaCowley marked this conversation as resolved.
# 0: Off, 1: Speech, 2: Braille, 3: Speech and Braille
fontAttributeReporting = integer(0, 3, default=0)
reportRevisions = boolean(default=true)
reportEmphasis = boolean(default=false)
reportHighlight = boolean(default=true)
Expand Down
19 changes: 19 additions & 0 deletions source/config/profileUpgradeSteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ReportLineIndentation,
ReportTableHeaders,
ReportCellBorders,
OutputMode,
)
import configobj.validate
from configobj import ConfigObj
Expand Down Expand Up @@ -377,3 +378,21 @@ def upgradeConfigFrom_10_to_11(profile: ConfigObj) -> None:
"hidBrailleStandard added to braille display auto detection excluded displays. "
f"List is now: {profile['braille']['auto']['excludedDisplays']}",
)


def upgradeConfigFrom_11_to_12(profile: ConfigObj) -> None:
Comment thread
seanbudd marked this conversation as resolved.
"""Add a new key, documentFormatting.fontAttributeReporting, which allows users to select between speech and/or braille, and base it on documentFormatting.reportFontAttributes."""
try:
reportFontAttributes: bool = profile["documentFormatting"].as_bool("reportFontAttributes")
except KeyError:
log.debug("reportFontAttributes not present in config, no action taken.")
return
except ValueError:
log.error("reportFontAttributes is not a boolean, no action taken.")
return
profile["documentFormatting"]["fontAttributeReporting"] = (
OutputMode.SPEECH_AND_BRAILLE if reportFontAttributes else OutputMode.OFF
)
log.debug(
f"documentFormatting.fontAttributeReporting added with value {profile['documentFormatting']['fontAttributeReporting']}."
)
37 changes: 24 additions & 13 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
TetherTo,
ShowMessages,
BrailleMode,
OutputMode,
)
from config.featureFlag import FeatureFlag
from config.featureFlagEnums import BoolFlag
Expand Down Expand Up @@ -573,20 +574,30 @@ def script_toggleReportFontSize(self, gesture):
ui.message(state)

@script(
# Translators: Input help mode message for toggle report font attributes command.
description=_("Toggles on and off the reporting of font attributes"),
description=_(
# Translators: Input help mode message for toggle report font attributes command.
"Cycles font attribute reporting between speech, braille, speech and braille, and off."
),
category=SCRCAT_DOCUMENTFORMATTING,
)
def script_toggleReportFontAttributes(self, gesture):
if config.conf["documentFormatting"]["reportFontAttributes"]:
# Translators: The message announced when toggling the report font attributes document formatting setting.
state = _("report font attributes off")
config.conf["documentFormatting"]["reportFontAttributes"] = False
else:
# Translators: The message announced when toggling the report font attributes document formatting setting.
state = _("report font attributes on")
config.conf["documentFormatting"]["reportFontAttributes"] = True
ui.message(state)
def script_toggleReportFontAttributes(self, gesture: "inputCore.InputGesture"):
currentValue = config.conf["documentFormatting"]["fontAttributeReporting"]
nextValue = OutputMode((currentValue + 1) % len(OutputMode.__members__))
match nextValue:
case OutputMode.OFF:
# Translators: A state in which font attributes are not reported.
status = _("Do not report font attributes")
case OutputMode.SPEECH:
# Translators: A state in which font attributes are only spoken.
status = _("Speak font attributes")
case OutputMode.BRAILLE:
# Translators: A state in which font attributes are only brailled.
status = _("Braille font attributes")
case OutputMode.SPEECH_AND_BRAILLE:
# Translators: A state in which font attributes are both spoken and brailled.
status = _("Speak and braille font attributes")
config.conf["documentFormatting"]["fontAttributeReporting"] = nextValue
ui.message(status)

@script(
# Translators: Input help mode message for toggle superscripts and subscripts command.
Expand Down Expand Up @@ -2366,7 +2377,7 @@ def _reportFormattingHelper(self, info, browseable=False):
reportFormattingOptions = (
"reportFontName",
"reportFontSize",
"reportFontAttributes",
"fontAttributeReporting",
"reportSuperscriptsAndSubscripts",
"reportHighlight",
"reportColor",
Expand Down
11 changes: 8 additions & 3 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ReportLineIndentation,
ReportTableHeaders,
ReportCellBorders,
OutputMode,
)
import languageHandler
import speech
Expand Down Expand Up @@ -2572,8 +2573,12 @@ def makeSettings(self, settingsSizer):
# Translators: This is the label for a checkbox in the
# document formatting settings panel.
fontAttributesText = _("Font attrib&utes")
self.fontAttrsCheckBox = fontGroup.addItem(wx.CheckBox(fontGroupBox, label=fontAttributesText))
self.fontAttrsCheckBox.SetValue(config.conf["documentFormatting"]["reportFontAttributes"])
fontAttributesOptions = [i.displayString for i in OutputMode.__members__.values()]
self.fontAttrsList = fontGroup.addLabeledControl(
fontAttributesText, wx.Choice, choices=fontAttributesOptions
)
self.bindHelpEvent("DocumentFormattingFontAttributes", self.fontAttrsList)
self.fontAttrsList.SetSelection(config.conf["documentFormatting"]["fontAttributeReporting"])

# Translators: This is the label for a checkbox in the
# document formatting settings panel.
Expand Down Expand Up @@ -2844,7 +2849,7 @@ def onSave(self):
)
config.conf["documentFormatting"]["reportFontName"] = self.fontNameCheckBox.IsChecked()
config.conf["documentFormatting"]["reportFontSize"] = self.fontSizeCheckBox.IsChecked()
config.conf["documentFormatting"]["reportFontAttributes"] = self.fontAttrsCheckBox.IsChecked()
config.conf["documentFormatting"]["fontAttributeReporting"] = self.fontAttrsList.GetSelection()
Comment thread
SaschaCowley marked this conversation as resolved.
config.conf["documentFormatting"]["reportSuperscriptsAndSubscripts"] = (
self.superscriptsAndSubscriptsCheckBox.IsChecked()
)
Expand Down
5 changes: 3 additions & 2 deletions source/speech/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
ReportLineIndentation,
ReportTableHeaders,
ReportCellBorders,
OutputMode,
)
import aria
from .priorities import Spri
Expand Down Expand Up @@ -2781,12 +2782,12 @@ def getFormatFieldSpeech( # noqa: C901
else _("not emphasised")
)
textList.append(text)
if formatConfig["reportFontAttributes"]:
if formatConfig["fontAttributeReporting"] & OutputMode.SPEECH:
Comment thread
SaschaCowley marked this conversation as resolved.
bold = attrs.get("bold")
oldBold = attrsCache.get("bold") if attrsCache is not None else None
if (bold or oldBold is not None) and bold != oldBold:
# Translators: Reported when text is bolded.
text = (
# Translators: Reported when text is bolded.
_("bold")
if bold
# Translators: Reported when text is not bolded.
Expand Down
2 changes: 1 addition & 1 deletion source/winConsoleHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def getTextWithFields(self, formatConfig: Optional[Dict] = None) -> textInfos.Te
if formatConfig["reportColor"]:
formatField["color"] = CONSOLE_COLORS_TO_RGB[c.Attributes & 0x0F]
formatField["background-color"] = CONSOLE_COLORS_TO_RGB[(c.Attributes >> 4) & 0x0F]
if formatConfig["reportFontAttributes"] and c.Attributes & COMMON_LVB_UNDERSCORE:
if formatConfig["fontAttributeReporting"] and c.Attributes & COMMON_LVB_UNDERSCORE:
formatField["underline"] = True
if formatField:
if lastText:
Expand Down
Loading