Skip to content

Use translated key labels when identifying emulated system keyboard keys #6212#6267

Merged
jcsteh merged 3 commits into
nvaccess:masterfrom
BabbageCom:fix_emulated_key_names
Oct 18, 2016
Merged

Use translated key labels when identifying emulated system keyboard keys #6212#6267
jcsteh merged 3 commits into
nvaccess:masterfrom
BabbageCom:fix_emulated_key_names

Conversation

@LeonarddeR

@LeonarddeR LeonarddeR commented Aug 16, 2016

Copy link
Copy Markdown
Collaborator

This pull request includes the following:

* In keyboard help for emulated system keyboard keys, the translated version of a key is now spoken instead of the raw, untranslated version
* Also, the script name for emulated system keyboard keys is now localized

Both changes are based on a new simple function in keyLabels in which you insert a raw key combination string, which is than converted to a localised key combination identifier.
Fixes #6212.

What's New entry: in Bug fixes:

- Emulated system keyboard keys (e.g. a button on a braille display which emulates pressing the tab key) are now presented in the configured NVDA language in input help and the Input Gestures dialog. Previously, they were always presented in English. (#6212)

…rsion of a key is now spoken instead of the raw, untranslated version. Also, the script name for emulated system keyboard keys is now localized

Both changes are based on a new simple function called getKeyCombinationLabel in keyLabels in which you insert a raw key combination string, which is than converted to a localised key combination identifier. (Re #6212)

@jcsteh jcsteh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work!

Comment thread source/keyLabels.py
'tab': pgettext("keyLabel", "tab"),
}

def getKeyCombinationLabel(keyCombination):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring explaining what this does. It need only be one or two lines.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
Furthermore, I noticed that my code failed if a particular key wasn't in localizedKeyLabels. When that happens now, the code falls back to the lowercase version of the originally provided key. Yay for list comprehension power!

Comment thread source/scriptHandler.py Outdated
scriptName = scriptName.encode("mbcs")
func.__name__ = "script_%s" % scriptName
func.__doc__ = _("Emulates pressing %s on the system keyboard") % keyName
func.__doc__ = _("Emulates pressing %s on the system keyboard") % keyLabels.getKeyCombinationLabel(keyName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can instead use emuGesture.displayName here. This does more or less the same thing, but it is the same code used to retrieve display names for normal keyboard keys in input help, and since we have the gesture, we may as well use it. There's actually a slight difference in the output too because it accounts for the set ordering that NVDA uses for modifier keys. You could of course do this in your keylabels function, but it's not really important.

You still need your keyLabels function for the Gestures dialog stuff because we don't build the actual gesture in that case, so we can't use the displayname property.

…mbinationLabel would fail if a particular key, such as f4 which is not in keyLabels.localizedKeyLabels, was asked for.
Comment thread source/keyLabels.py Outdated
@returns: A localized key combination
@rtype: string
"""
return "+".join(localizedKeyLabels[key.lower()] if key.lower() in localizedKeyLabels.keys() else key.lower() for key in keyCombination.split("+"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This certainly demonstrates the power of comprehensions :), but it does mean you end up calling key.lower() twice per key.
  2. Calling dict.keys generates a list of keys you then have to search, which is unnecessary here. For future reference, use key in dict, not key in dict.keys().
  3. You can eliminate the existence check by using dict.get with a default.

While premature optimisation is the root of all evil, I think it's worth eliminating unnecessary calls, especially if it makes things more readable. Perhaps something like this:

keys = keyCombination.lower().split("+")
return "+".join(localizedKeyLabels.get(key, key) for key in keys)

jcsteh added a commit that referenced this pull request Sep 28, 2016
@jcsteh jcsteh merged commit 6ab85ec into nvaccess:master Oct 18, 2016
@nvaccessAuto nvaccessAuto added this to the 2016.4 milestone Oct 18, 2016
@LeonarddeR LeonarddeR added the BabbageWork Pull requests filed on behalf of Babbage B.V. label Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BabbageWork Pull requests filed on behalf of Babbage B.V.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Translation system not used for emulated system keyboard keys in some cases

3 participants