Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/user202729/plover-run-py

Command plugin for Plover to run an arbitrary Python command.
https://github.com/user202729/plover-run-py

Last synced: about 12 hours ago
JSON representation

Command plugin for Plover to run an arbitrary Python command.

Awesome Lists containing this project

README

        

# plover-run-py

[![PyPI](https://img.shields.io/pypi/v/plover-run-py?style=flat)](https://pypi.python.org/pypi/plover-run-py/)

Command plugin for Plover to run an arbitrary Python command.

**Note**: Mostly superseded by [`plover-python-dictionary-cmd` plugin](https://github.com/user202729/plover-python-dictionary-cmd).

**Warning**: While this plugin can do everything what a command plugin can, this should
only be used for personal usage. If the usage is sufficiently general, it's recommended to make
a Plover command plugin instead.

It's also possible to execute a command from the command-line, using
[the `plover_send_command` script](https://plover.readthedocs.io/en/latest/cli_reference.html#sending-commands).
Unfortunately, this method takes about 1.5s per call due to Plover's overhead.

If `python -m plover.scripts.send_command` is used, the time is reduced to 0.3s per call,
mostly because of `pkg_resources` import.

### See also

* [`plover-python-dictionary-cmd` plugin](https://github.com/user202729/plover-python-dictionary-cmd) for doing the same task, but within a **Python dictionary**.
* [`plover-run-shell` plugin](https://github.com/user202729/plover_run_shell) for running a shell command.
* [`plover-debugging-console` plugin](https://github.com/user202729/plover-debugging-console) for
running Python commands in Plover in a shell (more convenient for debugging and showing results).
* [`plover-retro-stringop` plugin](https://github.com/buffet/plover_retro_stringop) for
running Python commands to transform/modify the previous text using arbitrary Python expression.

## Usage

In order to use this plugin in [Plover](https://github.com/openstenoproject/plover) you need to
create a dictionary entry of the form:

``` json
{
"example_stroke": "{PLOVER:PY:command}"
}
```

Variables `engine` and `plover` are provided.

Remember to escape the characters in `\{}` according to Plover's dictionary format.

Alternatively, if the definition has the form `"{PLOVER:PY_F:path}"`, the content of the file
at the given path will be run as Python code.

**Note**: If the command takes a long time to finish, Plover might freeze.

## Example

Refer to the API reference ([1](https://plover.readthedocs.io/en/latest/api_reference.html),
[2](https://plover2.readthedocs.io/en/latest/api_reference.html)) (unofficial, community-maintained)
for more details.

* Sleep between key presses: `{#a}{plover:py:import time; time.sleep(1)}{#b}`

See also [plover-delay](https://github.com/user202729/plover-delay) for a dedicated plugin.

* Toggle a plugin and show a warning notification on the status:
(broken into multiple lines for readability)

```
{plover:py:
engine["enabled_extensions"]^=\{'ibus'\};
plover.log.warning('ibus enabled=' + str('ibus' in engine["enabled_extensions"]))
}
```