Execute arbitrary command from a Python dictionary
Project description
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)
As an extra bonus, you get access to the engine
object inside the function f
above.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file plover_python_dictionary_cmd-0.0.0.tar.gz
.
File metadata
- Download URL: plover_python_dictionary_cmd-0.0.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95c90992c90d5804678637e939f48293e8748b82b518d1d65cfb624b16ed1c26 |
|
MD5 | 4c2e13a987c1ab9ab6a5e2d8202c96e7 |
|
BLAKE2b-256 | ca75cf96bc3f59ed1cc15bde1765138e30d55a5f41fd6491b6bc815ad30b1bf1 |
File details
Details for the file plover_python_dictionary_cmd-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: plover_python_dictionary_cmd-0.0.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0482106e880531c3dfc88d399a052afec3da92e09ae329424326637383083c3e |
|
MD5 | b4e6f88aaeb96ce2f57e10d681a54c47 |
|
BLAKE2b-256 | f193cbc327aaf78bb2cbc761bf4fc4cda3272c8f174db521d45d2e1c569997e7 |