-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_main.py
122 lines (108 loc) · 3.95 KB
/
_main.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- coding: utf-8 -*-
print "importing " + __file__
from dragonfly import *
import Base
import inspect
grammar = Base.ContinuousGrammar("_main grammar")
# decorator
def GrammarRule(rule):
if inspect.isclass(rule):
if issubclass(rule, Base.BaseQuickRules):
rule(grammar)
else:
grammar.add_rule(rule())
else:
grammar.add_rule(rule)
@GrammarRule
class CatchAll(Base.ContinuingRule):
spec = "<RunOn>"
extras = (Dictation("RunOn"), )
def _process_recognition(self, node, extras):
Text(extras["RunOn"].format()).execute()
@GrammarRule
class SomeQuickRules(Base.QuickContinuousRules):
name = "GlobalQuickRules"
extrasDict = {
"keyCount": IntegerRef("keyCount", 1, 1000),
"n": IntegerRef("n", 1, 10000),
"clickCount": IntegerRef("clickCount", 1, 1000),
"lineCount": IntegerRef("lineCount", 1, 1000),
"text": Dictation("text"),
"chain": Dictation("chain"),
}
defaultsDict = {
"n": 1,
"keyCount": 1,
"clickCount": 1,
"lineCount": 1,
}
mapping = {
"(click|mouse) [<clickCount> [times]]": Mouse("left:1") * Repeat(extra="clickCount"),
"control click [<clickCount> [times]]": (Key("ctrl:down") + Mouse("left:1") + Key("ctrl:up")) * Repeat(extra="clickCount"),
"right click [<clickCount> [times]]": Mouse("right:1") * Repeat(extra="clickCount"),
"middle click [<clickCount> [times]]": Mouse("middle:1") * Repeat(extra="clickCount"),
"double click": Mouse("left:2"),
"shift down": Key("shift:down"),
"shift up": Key("shift:up"),
"shift click": Key("shift:down") + Mouse("left:1") + Key("shift:up"),
"shift right click": Key("shift:down") + Mouse("right:1") + Key("shift:up"),
"down click": Mouse("left:down"),
"up click": Mouse("left:up"),
"down right click": Mouse("right:down"),
"up right click": Mouse("right:up"),
"toggle flux": Key("a-end"),
}
@GrammarRule
class QuickCRules(Base.QuickContinuousRules):
mapping = {
"(in quotes|string it)": Text("\"\"") + Key("left"),
"in brackets": Text("[]") + Key("left"),
"in apostrophes": Text("''") + Key("left"),
"brackets": Text("[]"),
"angle brackets": Text("<>"),
"parentheses": Text("()"),
"in curly brackets": Text("{}") + Key("left"),
"in angle brackets": Text("<>") + Key("left"),
"spinster": Text("()") + Key("enter"),
"item": Text(", "),
"assignment": Text(" = "),
}
@GrammarRule
class system_shortcuts_rule(Base.QuickContinuousRules):
name = "system_shortcuts"
mapping = {
"save": Key("c-s"),
"copy": Key("c-c"),
"(paste|from clip|from clipboard)": Key("c-v"),
"cut": Key("c-x"),
"top": Key("c-home"),
"bottom": Key("c-end"),
"tab windows": Key("alt:down, tab:down"),
"go to tab <n>": (Key("right") * Repeat(extra="n")) + Key("alt:up, tab:up"),
"last window": Key("alt:down, tab/5, alt:up"),
"undo": Key("c-z"),
"find": Key("c-f"),
"desktop": Key("w-d"),
"dock left": Key("w-left"),
"dock left twice": Key("w-left") * Repeat(2),
"dock right": Key("w-right"),
"dock right twice": Key("w-right") * Repeat(2),
"hide [(others | other windows)]": Key("w-home"),
"minimize": Key("w-down") * Repeat(2),
"maximize": Key("w-up"),
"close window": Key("a-f4"),
}
extrasDict = {
"keyCount": IntegerRef("keyCount", 1, 1000),
"n": IntegerRef("n", 0, 1000),
}
defaultsDict = {
"keyCount": 1,
"n": 1,
}
grammar.load()
# Unload function which will be called by natlink at unload time.
def unload():
global grammar
if grammar: grammar.unload()
grammar = None