plover-python-dictionary-cmd
Execute arbitrary command from a Python dictionary.
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.
See also: plover-run-shell, plover-run-py, plover-open-url.
What problem does this plugin solve?
First, this assumes you know what a Python dictionary is.
Maybe you want to write a dictionary that looks like this:
LONGEST_KEY = 1
def lookup(key):
if key == ("SKWR-F",):
return "{PLOVER:OPEN_URL:https://www.openstenoproject.org/}"
The {PLOVER:OPEN_URL:…} obviously opens the said URL, using Plover Open URL plugin.
Problem: what if the task you want to do is not already covered by some command plugin?
While you can certainly write a new command plugin, that is rather time-consuming.
The following will not work:
import webbrowser
LONGEST_KEY = 1
def lookup(key):
if key == ("SKWR-F",):
webbrowser.open("https://www.openstenoproject.org/")
It's because the dictionary may be looked up multiple times.
The solution
Write the plugin like the following.
import webbrowser
import plover_python_dictionary_cmd
LONGEST_KEY = 1
@plover_python_dictionary_cmd.register
def f(engine):
webbrowser.open("https://www.openstenoproject.org/")
def lookup(key):
if key == ("SKWR-F",):
return str(f) # or: f.str_with_args()
As an extra bonus, you get access to the engine object inside the function f above.
Extra
f.str_with_args() works as follows:
f.str_with_args(1, 2) returns a string, which when interpreted as a Plover command
and executed, will call f(engine, 1, 2).
As such, you can also modify the code above as follows:
@plover_python_dictionary_cmd.register
def f(engine, url):
webbrowser.open(url)
def lookup(key):
if key == ("SKWR-F",):
return f.str_with_args("https://www.openstenoproject.org/")
Internal implementation detail
It uses a global lookup table to store the reference to the function f. Then str(f) as above
returns something like {plover:python_dictionary_cmd:123456} where 123456 is some unique ID.
Don't rely on this implementation detail.
Metadata
Release files for plover-python-dictionary-cmd 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| plover_python_dictionary_cmd-0.0.1.tar.gz | 15.4 kB | Without provenance | Details for plover_python_dictionary_cmd-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plover_python_dictionary_cmd-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for plover_python_dictionary_cmd-0.0.1-py3-none-any.whl |
Total release size: 31.7 kB
Release files / plover_python_dictionary_cmd-0.0.1.tar.gz
| Download URL | plover_python_dictionary_cmd-0.0.1.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0e70caeb44c0aa9a16dc361245117ccccf3c0e8c606ef4836395cbf66fc7f0b
|
|
BLAKE2b-256 checksum How to use checksums |
9fa152c8519466b9ecf5bccdd860c50e67195fceb9221a88f51358ef57765c37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / plover_python_dictionary_cmd-0.0.1-py3-none-any.whl
| Download URL | plover_python_dictionary_cmd-0.0.1-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5a6ad96785860bfc4edf90bcd4e109f12c971e2594b0435ec8ea0be0b6cb723
|
|
BLAKE2b-256 checksum How to use checksums |
129e2e80092a622f3d307e47f2d1ad91a50275b94e42736caca1b4ced94232df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for plover-python-dictionary-cmd 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.