-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopypaste.py
105 lines (91 loc) · 2.2 KB
/
copypaste.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from dragonfly import (
Choice,
Function,
Playback,
)
import aenea
import aenea.misc
import aenea.vocabulary
import aenea.configuration
import aenea.format
from aenea import (
AeneaContext,
AppContext,
Alternative,
CompoundRule,
Dictation,
DictList,
DictListRef,
Grammar,
IntegerRef,
Key,
Literal,
ProxyAppContext,
MappingRule,
NeverContext,
Repetition,
Repeat,
RuleRef,
Sequence,
Text
)
from magneto.nexus import nexus
from magneto.mergerule import MergeRule
from magneto import settings
from magneto.settings import ModuleDictionary
print('loading copypaste rules')
try:
import aenea.communications
except ImportError:
print 'Unable to import Aenea client-side modules.'
raise
CLIPBOARD = ModuleDictionary("core\\copypaste")
def paste(t,n):
if n != 0:
t=n
if t=="default":
Key("c-v").execute()
else:
global CLIPBOARD
key = str(t)
if key in CLIPBOARD.dictionary:
previous = aenea.communications.server.paste(CLIPBOARD.dictionary[key])
Key("c-v").execute()
# restore previous clipboard value
aenea.communications.server.paste(previous)
else:
print("No key '%s' in clipboard dictionary" % key)
def copy(t,n):
if n != 0:
t=n
global CLIPBOARD
key = str(t)
selected_text = aenea.communications.server.copy()
if key=="default":
propagate_copy()
Key("c-c").execute()
CLIPBOARD[key] = selected_text
def propagate_copy():
"""move previous copy to index 2, 2 to 3, etc. drop 9.
TODO Function not working"""
print("propagating")
for i in range(8,1):
previous = str(i)
next_key = str(i+1)
if previous in CLIPBOARD:
CLIPBOARD[next_key] = CLIPBOARD[previous]
CLIPBOARD["1"] = CLIPBOARD["default"]
class CopyPaste(MergeRule):
mapping = {
"copy [<t> | <n>]": Function(copy),
"paste [<t> | <n>]": Function(paste),
}
extras = [
Dictation("t"),
IntegerRef("n",0,9)
]
defaults = {
"t": 'default',
"n": 0
}
nexus().merger.add_global_rule(CopyPaste())