-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchrome.py
119 lines (106 loc) · 3.76 KB
/
chrome.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
print "importing " + __file__
from dragonfly import *
import BaseGrammars
from BaseRules import *
grammar_context = AppContext(executable="chrome")
grammar = BaseGrammars.ContinuousGrammar("chrome", context=grammar_context)
#decorator
def GrammarRule(rule):
if inspect.isclass(rule):
if issubclass(rule, BaseQuickRules):
rule(grammar)
else:
grammar.add_rule(rule())
else:
grammar.add_rule(rule)
@GrammarRule
class GoToTabRule(ContinuousRule):
spec = "go to tab <goToTabNum>"
extras = IntegerRef("goToTabNum", 1, 8),
def _process_recognition(self, node, extras):
Key("c-" + str(extras["goToTabNum"])).execute()
@GrammarRule
class ChromeRules(QuickContinuousRules):
name="chrome_rule"
mapping = {
"next tab [<n> [times]]": Key("c-tab") * Repeat(extra="n"),
"previous tab [<n> [times]]": Key("cs-tab") * Repeat(extra="n"),
"close (tab | pop up)": Key("c-w"),
"new tab": Key("c-t"),
"new window": Key("c-n"),
"incognito window": Key("cs-n"),
"reopen [last] [tab]": Key("cs-t"),
"[go to] last tab": Key("c-9"),
"[go to] last tab but <n>": Key("c-9") + Key("cs-tab") * Repeat(extra="n"),
"browse back": Key("backspace"),
"browse forward": Key("s-backspace"),
"toggle bookmarks": Key("cs-b"),
"toggle full-screen": Key("f11"),
"[open] history": Key("c-h"),
"[open] downloads": Key("c-j"),
"(go to|select) address": Key("a-d"),
"refresh": Key("c-f5"),
"stop (load | loading)": Key("escape"),
"(open | show) source": Key("c-u"),
"(save | do | make) bookmark": Key("c-d"),
"zoom in": Key("c-plus"),
"zoom out": Key("c-minus"),
"zoom (default | normal)": Key("c-0"),
"go to gmail": Key("c-t") + Pause("20") + Text("gmail.com") + Key("delete, enter"),
"go to PEGym": Key("c-t") + Pause("20") + Text("PEGym.com/forums/") + Key("delete, enter"),
}
extrasDict = {
"n": IntegerRef("n", 1, 30),
}
defaultsDict = {
"n":1,
}
def go_to_label(label_string):
formatted_label = "-".join(label_string.split())
action = Key("escape:2, g/20, l/20") + Text(formatted_label) + Key("escape, enter")
action.execute()
@GrammarRule
class GmailCalls(QuickContinuousCalls):
mapping = [
["go to label", go_to_label, "label_string"],
]
@GrammarRule
class GmailRules(QuickContinuousRules):
name="gmail_rule"
context = AppContext(title="Gmail")
mapping = {
"[show] shortcut help": Key("s-slash"),
"mark all read": Key("asterisk/20, a/20, s-i/20, asterisk/20, n"),
"mark read": Key("s-i"),
"mark unread": Key("s-u"),
"read it": Key("x/20, s-i") + Pause("20") + Key("x"),
"read hover": Mouse("left") + Pause("20") + Key("s-i") + Pause("20") + Mouse("left"),
"main window": Key("s-escape"),
"inbox": Key("escape:2, g/20, i"),
"sent box": Key("escape:2, g/20, t"),
"(mark|select) all": Key("asterisk/20, a"),
"select read": Key("asterisk/20, r"),
"select un read": Key("asterisk/20, u"),
"(select none|unselect all)": Key("asterisk/20, n"),
"select read": Key("asterisk/20, r"),
"select unread": Key("asterisk/20, u"),
"(toggle [selection|mark]|mark|unmark)": Key("x"),
"search [box]": Text("/"),
"(compose|new) message": Text("c"),
"trash it": Key("s-3"),
"show labels": Key("escape:2, l"),
"move to": Key("escape:2, v"),
"show [more] actions": Text("."),
"remove [current] label": Text("y"),
}
extrasDict = {
"text": Dictation("text"),
}
#---------------------------------------------------------------------------
# Load the grammar instance and define how to unload it.
grammar.load()
# Unload function which will be called by natlink at unload time.
def unload():
global grammar
if grammar: grammar.unload()
grammar = None