Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci/workflow_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GithubActionsYamlLoader(yaml.SafeLoader):
@staticmethod
def _unsupported(kind, token):
return SyntaxError(
"Github Actions does not support %s:\n%s" % (kind, token.start_mark)
f"Github Actions does not support {kind}:\n{token.start_mark}"
)

def fetch_alias(self):
Expand Down Expand Up @@ -41,13 +41,13 @@ def fetch_anchor(self):

for j in context["jobs"]:
base_type = j["type"].split("_")[0]
j["id"] = "%s_%s" % (
j["id"] = "{}_{}".format(
base_type,
j["variant"].lower().replace(" ", "_").replace(".", ""),
)
j["name"] = "%s (%s)" % (base_type.capitalize(), j["variant"])
j["name"] = "{} ({})".format(base_type.capitalize(), j["variant"])
j["needs"] = j.get("needs", [])
j["reqs"] = ["reqs/%s.txt" % r for r in j["reqs"]]
j["reqs"] = [f"reqs/{r}.txt" for r in j["reqs"]]
j["cache_extra_deps"] = j.get("cache_extra_deps", [])
if "python" not in j:
j["python"] = context["default_python"]
Expand All @@ -65,7 +65,7 @@ def fetch_anchor(self):
v = "(" + " ".join(map(shlex.quote, v)) + ")"
else:
v = shlex.quote(v)
shell_definition.append("job_%s=%s" % (k, v))
shell_definition.append(f"job_{k}={v}")
j["shell_definition"] = "; ".join(shell_definition)

# Render template.
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.8 # also update constraints.txt
rev: v0.16.0 # also update constraints.txt
hooks:
# Run the linter.
- id: ruff-check
Expand Down
6 changes: 4 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Configuration file for the Sphinx documentation builder.
from pygments.lexer import RegexLexer, bygroups
from typing import ClassVar

from pygments import token as t
from pygments.lexer import RegexLexer, bygroups
from sphinx.highlighting import lexers

# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -78,7 +80,7 @@
class RTFLexer(RegexLexer):
name = "rtf"

tokens = {
tokens: ClassVar[dict] = {
"root": [
(r"(\\[a-z*\\_~\{\}]+)(-?\d+)?", bygroups(t.Keyword, t.Number.Integer)),
(r"{\\\*\\cxcomment\s+", t.Comment.Multiline, "comment"),
Expand Down
15 changes: 8 additions & 7 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,16 @@ and providing a callback function:

```python
class MyExtension:
def __init__(self, engine: plover.engine.StenoEngine):
self.engine = engine
def __init__(self, engine: plover.engine.StenoEngine):
self.engine = engine

def start(self):
# Connect to the "stroked" hook
self.engine.hook_connect("stroked", self._on_stroked)
def start(self):
# Connect to the "stroked" hook
self.engine.hook_connect("stroked", self._on_stroked)

def _on_stroked(self, stroke: plover.steno.Stroke):
... # Gets called after each stroke
def _on_stroked(
self, stroke: plover.steno.Stroke
): ... # Gets called after each stroke
```

Events that occur within the Plover engine, such as machine disconnections,
Expand Down
20 changes: 10 additions & 10 deletions doc/dict_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ LONGEST_KEY = 1


def lookup(outline):
assert len(outline) == 1
assert len(outline) == 1

stroke = outline[0]
if stroke == "KP-PL":
return "example"
else:
raise KeyError
stroke = outline[0]
if stroke == "KP-PL":
return "example"
else:
raise KeyError


def reverse_lookup(translation):
if translation == "example":
return [("KP-PL",)]
else:
return []
if translation == "example":
return [("KP-PL",)]
else:
return []
```
38 changes: 17 additions & 21 deletions doc/hardware_communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ should translate platform-specific events into calls to

```python
class MyKeyboardCapture(Capture):
def start(self):
self._thread = threading.Thread(target=self._run)
self._thread.start()

def _run(self):
while True:
key, pressed = ... # wait for key event

if pressed:
self.key_down(key)
else:
self.key_up(key)
def start(self):
self._thread = threading.Thread(target=self._run)
self._thread.start()

def _run(self):
while True:
key, pressed = ... # wait for key event

if pressed:
self.key_down(key)
else:
self.key_up(key)
```

Plover's engine handles translating these calls into steno strokes, as well as
Expand All @@ -57,14 +57,11 @@ specified, by translating them to platform-specific input calls.

```python
class MyKeyboardEmulation(Output):
def send_backspaces(self, num):
...
def send_backspaces(self, num): ...

def send_string(self, s):
...
def send_string(self, s): ...

def send_key_combination(self, combo):
...
def send_key_combination(self, combo): ...
```

## Serial Protocols
Expand All @@ -81,12 +78,11 @@ and implement a way to parse each packet.

```python
class MySerialMachine(SerialStenotypeBase):
KEYS_LAYOUT = """
KEYS_LAYOUT = """
...
"""

def run(self):
...
def run(self): ...
```

## USB-based Protocols
Expand Down
2 changes: 1 addition & 1 deletion doc/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ available for sub-modules:
```python
from plover.i18n import Translator

_ = Translator(__package__, resource_dir='messages')
_ = Translator(__package__, resource_dir="messages")
```

Note: don't forget to add `Babel` to your build dependencies (in `pyproject.toml`).
Expand Down
7 changes: 4 additions & 3 deletions doc/plugin-dev/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ 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
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}
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")
_vlc_request("?command=pl_stop")
```
35 changes: 17 additions & 18 deletions doc/plugin-dev/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ write your desired dictionary format.

from plover.steno_dictionary import StenoDictionary

class ExampleDictionary(StenoDictionary):

readonly = False
class ExampleDictionary(StenoDictionary):
readonly = False

def _load(self, filename):
# If you are not maintaining your own state format, self.update is usually
# called here to add strokes / definitions to the dictionary state.
pass
def _load(self, filename):
# If you are not maintaining your own state format, self.update is usually
# called here to add strokes / definitions to the dictionary state.
pass

def _save(self, filename):
pass
def _save(self, filename):
pass
```

Note that setting `readonly` to `True` on your dictionary class will make
Expand All @@ -39,18 +39,17 @@ For example, a simplified version of the JSON dictionary implementation:

```python
class JsonDictionary(StenoDictionary):
def _load(self, filename):
with open(filename) as fp:
d = dict(json.load(fp))

def _load(self, filename):
with open(filename) as fp:
d = dict(json.load(fp))

# Inserts the entries into the dictionary
self.update((normalize_steno(k), v) for k, v in d.items())
# Inserts the entries into the dictionary
self.update((normalize_steno(k), v) for k, v in d.items())

def _save(self, filename):
with open(filename, "w") as fp:
entries = [("/".join(k), v) for k, v in self.items()]
json.dump(entries, fp)
def _save(self, filename):
with open(filename, "w") as fp:
entries = [("/".join(k), v) for k, v in self.items()]
json.dump(entries, fp)
```

Some dictionary formats, such as Python dictionaries, may require implementing
Expand Down
49 changes: 25 additions & 24 deletions doc/plugin-dev/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ plover.extension =
```python
# plover_my_plugin/extension.py


class Extension:
def __init__(self, engine):
# Called once to initialize an instance which lives until Plover exits.
self.engine = engine

def start(self):
# Called to start the extension or when the user enables the extension.
# It can be used to start a new thread for example.
pass

def stop(self):
# Called when Plover exits or the user disables the extension.
pass
def __init__(self, engine):
# Called once to initialize an instance which lives until Plover exits.
self.engine = engine

def start(self):
# Called to start the extension or when the user enables the extension.
# It can be used to start a new thread for example.
pass

def stop(self):
# Called when Plover exits or the user disables the extension.
pass
```

Extensions can interact with the engine through the
Expand All @@ -36,20 +37,20 @@ using the {js:func}`stroked<stroked>` hook:

```python
class StrokeLogger:
def __init__(self, engine):
self.engine = engine
self.output_file = None
def __init__(self, engine):
self.engine = engine
self.output_file = None

def start(self):
self.output_file = open("strokes.txt")
def start(self):
self.output_file = open("strokes.txt")

# self.on_stroked gets called on every stroke
self.engine.hook_connect("stroked", self.on_stroked)
# self.on_stroked gets called on every stroke
self.engine.hook_connect("stroked", self.on_stroked)

def stop(self):
self.engine.hook_connect("stroked", self.on_stroked)
self.output_file.close()
def stop(self):
self.engine.hook_connect("stroked", self.on_stroked)
self.output_file.close()

def on_stroked(self, stroke):
print(stroke, file=self.output_file)
def on_stroked(self, stroke):
print(stroke, file=self.output_file)
```
35 changes: 18 additions & 17 deletions doc/plugin-dev/gui_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ from plover_build_utils.setup import BuildPy, BuildUi

BuildPy.build_dependencies.append("build_ui")
CMDCLASS = {
"build_py": BuildPy,
"build_ui": BuildUi,
"build_py": BuildPy,
"build_ui": BuildUi,
}

setup(cmdclass=CMDCLASS)
Expand Down Expand Up @@ -44,18 +44,19 @@ GUI tools are implemented as Qt widget **classes** inheriting from

from plover.gui_qt.tool import Tool


# You will also want to import / inherit for your Python class generated by
# your .ui file if you are using Qt Designer for creating your UI rather
# than only from code
class Main(Tool):
TITLE = 'Example Tool'
ICON = ''
ROLE = 'example_tool'

def __init__(self, engine):
super().__init__(engine)
# If you are inheriting from your .ui generated class, also call
# self.setupUi(self) before any additional setup code
TITLE = "Example Tool"
ICON = ""
ROLE = "example_tool"

def __init__(self, engine):
super().__init__(engine)
# If you are inheriting from your .ui generated class, also call
# self.setupUi(self) before any additional setup code
```

Keep in mind that when you need to make changes to the UI, you will need to
Expand All @@ -72,13 +73,13 @@ provides Qt signals to be used as hooks.

```python
class StrokeLogger(Tool, Ui_StrokeLogger):
def __init__(self, engine):
super().__init__(engine)
self.setupUi(self)
def __init__(self, engine):
super().__init__(engine)
self.setupUi(self)

# Instead of engine.hook_connect
engine.signal_connect("stroked", self.on_stroked)
# Instead of engine.hook_connect
engine.signal_connect("stroked", self.on_stroked)

def on_stroked(self, stroke):
pass
def on_stroked(self, stroke):
pass
```
Loading
Loading