Skip to content

Commit

Permalink
Applied some review suggestions and improved the upgrade steps
Browse files Browse the repository at this point in the history
  • Loading branch information
cary-rowen committed Jan 9, 2025
1 parent d326bdd commit 62e5403
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
8 changes: 4 additions & 4 deletions source/config/configFlags.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ class TypingEcho(DisplayStringIntEnum):
"""

OFF = 0
ALWAYS = 1
EDIT_CONTROLS = 2
EDIT_CONTROLS = 1
ALWAYS = 2

@property
def _displayStringLabels(self):
return {
# Translators: One of the choices for typing echo in keyboard settings
TypingEcho.OFF: _("Off"),
# Translators: One of the choices for typing echo in keyboard settings
TypingEcho.ALWAYS: _("Always"),
# Translators: One of the choices for typing echo in keyboard settings
TypingEcho.EDIT_CONTROLS: _("Only in edit controls"),
# Translators: One of the choices for typing echo in keyboard settings
TypingEcho.ALWAYS: _("Always"),
}


Expand Down
8 changes: 4 additions & 4 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 = 14
latestSchemaVersion = 15

#: The configuration specification string
#: @type: String
Expand Down Expand Up @@ -178,10 +178,10 @@
# Default = 6: NumpadInsert + ExtendedInsert
NVDAModifierKeys = integer(1, 7, default=6)
keyboardLayout = string(default="desktop")
# 0: Off, 1: Always, 2: Only in edit controls
# 0: Off, 1: Only in edit controls, 2: Always
speakTypedCharacters = integer(default=2,min=0,max=2)
# 0: Off, 1: Always, 2: Only in edit controls
speakTypedWords = integer(default=2,min=0,max=2)
# 0: Off, 1: Only in edit controls, 2: Always
speakTypedWords = integer(default=0,min=0,max=2)
beepForLowercaseWithCapslock = boolean(default=true)
speakCommandKeys = boolean(default=false)
speechInterruptForCharacters = boolean(default=true)
Expand Down
29 changes: 13 additions & 16 deletions source/config/profileUpgradeSteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,30 +475,27 @@ def _friendlyNameToEndpointId(friendlyName: str) -> str | None:


def upgradeConfigFrom_14_to_15(profile: ConfigObj):
"""Convert keyboard typing echo configuration from boolean to integer values."""
_convertTypingEcho(profile, "speakTypedCharacters")
_convertTypingEcho(profile, "speakTypedWords")
"""Convert keyboard typing echo configurations from boolean to integer values."""
convertTypingEcho(profile, "speakTypedCharacters")
convertTypingEcho(profile, "speakTypedWords")


def _convertTypingEcho(profile: ConfigObj, key: str) -> None:
def convertTypingEcho(profile: ConfigObj, key: str) -> None:
"""
Convert a keyboard typing echo configuration from boolean to integer values.
This function updates the specified key in the keyboard configuration by converting its boolean value
to the corresponding TypingEcho enum value.
:param profile: The user profile containing keyboard settings.
:param profile: The `ConfigObj` instance representing the user's NVDA configuration file.
:param key: The configuration key to convert.
"""
try:
value = profile["keyboard"][key]
oldValue: bool = profile["keyboard"].as_bool(key)
except KeyError:
log.debug(f"'{key}' not present in config, no action taken.")
return
except ValueError:
log.error(f"'{key}' is not a boolean, no action taken.")
return
else:
if configobj.validate.is_boolean(value):
old_value = value
new_value = TypingEcho.EDIT_CONTROLS.value if value else TypingEcho.OFF.value
profile["keyboard"][key] = new_value
log.debug(f"Converted '{key}' from {old_value} to {new_value} ({TypingEcho(new_value).name}).")
else:
log.debug(f"'{key}' is not a boolean, no conversion performed.")
newValue = TypingEcho.EDIT_CONTROLS.value if oldValue else TypingEcho.OFF.value
profile["keyboard"][key] = newValue
log.debug(f"Converted '{key}' from {oldValue!r} to {newValue} ({TypingEcho(newValue).name}).")
4 changes: 2 additions & 2 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def script_previousSynthSetting(self, gesture):

@script(
# Translators: Input help mode message for cycling the reporting of typed words.
description=_("Cycle the reporting of typed characters: Off, Always, and Only in edit controls."),
description=_("Cycles through options for when to speak typed characters."),
category=SCRCAT_SPEECH,
gesture="kb:NVDA+2",
)
Expand All @@ -552,7 +552,7 @@ def script_toggleSpeakTypedCharacters(self, gesture):

@script(
# Translators: Input help mode message for toggle speak typed words command.
description=_("Cycle the reporting of typed words: Off, Always, and Only in edit controls."),
description=_("Cycles through options for when to speak typed words."),
category=SCRCAT_SPEECH,
gesture="kb:NVDA+3",
)
Expand Down
3 changes: 1 addition & 2 deletions source/speech/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,7 @@ def _suppressSpeakTypedCharacters(number: int):

def isFocusEditable() -> bool:
"""Check if the currently focused object is editable.
@return: C{True} if the focused object is editable, C{False} otherwise.
@rtype: bool
:return: ``True`` if the focused object is editable, ``False`` otherwise.
"""
obj = api.getFocusObject()
controls = {controlTypes.ROLE_EDITABLETEXT, controlTypes.ROLE_DOCUMENT, controlTypes.ROLE_TERMINAL}
Expand Down
4 changes: 2 additions & 2 deletions user_docs/en/userGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ If no key is chosen as the NVDA key it may be impossible to access many NVDA com

##### Speak Typed Characters {#KeyboardSettingsSpeakTypedCharacters}

Key: NVDA+2
Key: `NVDA+2`

This option controls when NVDA announces characters you type on the keyboard.
The available options are:
Expand All @@ -2601,7 +2601,7 @@ The available options are:

##### Speak Typed Words {#KeyboardSettingsSpeakTypedWords}

Key: NVDA+3
Key: `NVDA+3`

This option controls when NVDA announces words you type on the keyboard.
The available options are:
Expand Down

0 comments on commit 62e5403

Please sign in to comment.