plover.machine.keymap – Machine key bindings¶
This module handles keymaps, mappings between keys on a physical machine and actions that produce steno strokes for a certain steno system. Keymaps exist for each combination of machine and system.
Keymaps are bidirectional, so we make a distinction between bindings and mappings: a key is bound to an action, i.e. when a key is pressed Plover performs the corresponding action, and an action is mapped to one or more keys. Each action should be mapped to at least one key, and each key to an action; otherwise, the behavior when stroking is undefined.
- class plover.machine.keymap.Keymap(keys: list[str] | tuple[str, ...], actions: list[str] | tuple[str, ...])¶
- Parameters:
keys – A list of possible keys on the physical machine. For a serial steno protocol like TX Bolt, this would be the steno keys themselves (
S-,T-, etc.); for the keyboard, this would be keyboard keys (q,w, etc.).actions –
A list of possible actions in the steno system.
In addition to the steno keys in the current system (see
system.KEYSfor more information), the actions may includeno-op, a special action that does nothing, andarpeggiate, a special action for arpeggiate mode that is only available if the current machine is a keyboard.
- get_keys() KeysView[str]¶
Returns the list of possible keys.
- get_actions() KeysView[str]¶
Returns the list of possible actions.
- set_bindings(bindings: dict[str, str]) None¶
Use
bindingsas the new keymap.- Parameters:
bindings – A dictionary mapping keys to actions.
Notes
This also calculates the mappings and calls
set_mappings().
- set_mappings(mappings: Any) None¶
Use
mappingsas the new keymap.- Parameters:
mappings – A dictionary mapping actions to either a single key or a list of keys that are bound to that action. This also calculates the bindings and calls
set_bindings().
Warning
Where
mappingscontains some consistency issues, such as keys bound multiple times or nonexistent keys or actions, this shows a warning and the keymap behavior is undefined.
- get_bindings() dict[str, str]¶
Returns the dictionary of bindings from keys to actions.
- get_mappings() OrderedDict[str, tuple[str, ...]]¶
Returns the dictionary of mappings from actions to keys.
- get_action(key: str, default: str | None = None) str | None¶
Given
key, returns the action, ordefaultif unbound.
- keys_to_actions(key_list: list[str] | tuple[str, ...]) list[str]¶
Returns the actions performed by pressing all of the keys in
key_list.Raises an error if any element of
key_listis not a valid machine key (i.e. not in the keys passed to__init__()).
- __getitem__(key)¶
Returns the list of keys that are bound to the action
key.(Confusing, I know.)
- __setitem__(action, key_list)¶
Maps
actionto all the keys inkey_list.Also unbinds each key in
key_listif already bound.