File: commands.md

package info (click to toggle)
plover 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,356 kB
  • sloc: python: 21,589; sh: 682; ansic: 25; makefile: 11
file content (47 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Commands

To define a new command called `example_command`, add this name as an
entry point in `setup.cfg`:

```ini
[options.entry_points]
plover.command =
  example_command = plover_my_plugin.command:example
```

The command can be used in dictionary entries:

```json
{
  "S-": "{PLOVER:EXAMPLE_COMMAND:argument}",
  "T-": "{PLOVER:EXAMPLE_COMMAND}"
}
```

Command plugins are implemented as **functions** that take a
{class}`StenoEngine<plover.engine.StenoEngine>` and an optional string
argument. If an argument is not passed in the dictionary entry, it will be
`''`.

```python
# plover_my_plugin/command.py

def example(engine, argument):
  pass
```

Commands can access any of the properties and methods in the engine object
passed to it, such as in [`plover_system_switcher`](https://github.com/nsmarkop/plover_system_switcher/blob/master/plover_system_switcher.py):

```python
def switch_system(engine, system):
  engine.config = {"system_name": system}
```

They can also interact with the rest of the Python environment, and even other
programs, such as [`plover_vlc_commands`](https://github.com/benoit-pierre/plover_vlc_commands/blob/master/plover_vlc_commands.py) sending HTTP requests to VLC:

```python
def stop(_, _):
  _vlc_request("?command=pl_stop")
```