-
Notifications
You must be signed in to change notification settings - Fork 1
/
plover_agnostic_toggle.py
43 lines (35 loc) · 1.18 KB
/
plover_agnostic_toggle.py
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
#!/usr/bin/env python
from plover.translation import Translation
from plover.steno import Stroke
from plover import system
def toggle_key(translator, stroke, cmdline):
# Toggle keys of previous stroke
toggles = [key.strip().replace(" ","") for key in cmdline.split(',')]
translations = translator.get_state().translations
if not translations:
return
t = translations[-1]
translator.untranslate_translation(t)
keys = set(t.strokes[-1].steno_keys)
allKeys = set(system.KEYS)
for key in toggles:
if key in keys:
keys.remove(key)
elif key in allKeys:
keys.add(key)
translator.translate_stroke(Stroke(keys))
def stroke_negative(translator, stroke, cmdline):
# Toggle ALL keys of previous stroke
translations = translator.get_state().translations
if not translations:
return
t = translations[-1]
translator.untranslate_translation(t)
keys = set(t.strokes[-1].steno_keys)
allKeys = set(system.KEYS)
for key in allKeys:
if key in keys:
keys.remove(key)
else:
keys.add(key)
translator.translate_stroke(Stroke(keys))