WARNING: there may be outdated information.
This is just an overview.
For more information, read:
- https://github.com/openstenoproject/plover/wiki/Plugins
- https://plover.readthedocs.io/
- https://plover2.readthedocs.io/
- Docstrings in Plover source code
Component roles:
- Emulate keyboard: oslayer
- Get input from keyboard: machine+oslayer
- Get input from serial port machines: machine+serial
- Lookup dictionary: translator
- Merge strokes together: translator
- Run macro: translator
- Interpret glue, stitch: formatter
- Run meta: formatter
- Combine components, connect hooks: engine
The unit tests helps a lot, too.
Details:
Stroke(KAT)
Stroke(HROG)
Stroke(AFRLG)
Stroke(*)
|
|
+------------+
| Translator | ------ (lookup dictionary) ------ StenoDictionary
+------------+
|
+--------------------------> macro.undo.undo()
|
v
Translation(KAT, "cat")
Translation(KAT/HROG, "cat", replaced=[Translation(KAT, "cat")])
Translation(AFRLG, "{#a}{}{^}")
|
|
+------------------------------------------------|
| Formatter.format: |
| | |
| | |
| +-------------------------+ |
| | _translation_to_actions | |
| +-------------------------+ |
| | |
| | |
| v |
| |
| [Action("catalog")] |
| [_Action(combo="a"), |
| _Action(prev_attach=True, next_attach=True)] |
| |
| | |
| | |
| +---------------+ |
| | TextFormatter | |
| +---------------+ |
| | |
+------------------------------------------------|
|
|
v
send_string(catalog)
send_string(a)
[User type]
KAT/HROG/AFRLG/*
[Machine plugin pass to StenoEngine object]
## Module: plover.engine
-> (StenoEngine) self._machine.add_stroke_callback(self._machine_stroke_callback)
-> self._same_thread_hook(self._on_stroked, steno_keys)
-> self._translator.translate(stroke)
## Module: plover.translation
[ Translator have .translate(Stroke(KAT)) called ]
-> translator.translate_stroke(Stroke(KAT))
Case 1. a macro (undo)
-> Call plover.macro.undo:undo(translator, Stroke(KAT), cmdline="")
-> translator.get_state().translations to get last translation
-> undo with translator.untranslate_translation(t)
-> redo t.replaced (if available)
-> **Which means that if there's any key combo in t.replaced, it will be done again!**
Be very careful with key combo, it must not be inside any multistroke word.
Case 2. not a macro
-> Find translation object `t`:
* Translation(KAT -> "cat")
* Translation(KAT/HROG -> "catalog", replaced=[Translation(KAT -> cat)])
* Translation(AFRLG -> "{#a}{}{^}") # <-- .has_undo() = False
-> .translate_translation(t)
-> ._undo(*t.replaced)
-> ._do(t)
-> add t to .get_state().translations
-> (internal details) add counter translator._to_do
-> flush()
-> call engine._formatter.format(old: List[Translation], new: List[Translation])
## Module: plover.formatting
Formatter.format(undo, do)
Example:
* undo=[Translation(KAT -> cat)]
* do=[Translation(KAT/HROG -> "catalog", replaced=[Translation(KAT -> cat)])]
_translation_to_actions("catalog", ctx) -> [_Action("catalog")]
_translation_to_actions("{#a}{^}", ctx) -> [_Action(combo="a"), _Action(prev_attach=True, next_attach=True)]
-> OutputHelper.render()
-> self.output.send_key_combination(action.combo) / self.output.send_engine_command(action.command)
/ self.output.send_backspaces(erased) / self.output.send_string(appended)
## Module: plover.engine (again)
.send_backspaces(b)
-> ._keyboard_emulation.send_backspaces(b)
-> trigger_hook