forked from tgrosinger/aenea-grammars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimium.py
85 lines (71 loc) · 1.92 KB
/
_vimium.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
# Created for aenea using libraries from the Dictation Toolbox
# https://github.com/dictation-toolbox/dragonfly-scripts
#
# Commands for interatcting with Chrome. Requires the Vimium extension.
# http://vimium.github.io/
#
# Author: Tony Grosinger
#
# Licensed under LGPL
import aenea
import aenea.configuration
from aenea.lax import Key, Text, Dictation
from aenea import (
IntegerRef
)
import dragonfly
chrome_context = aenea.ProxyCustomAppContext(executable="/opt/google/chrome/chrome")
grammar = dragonfly.Grammar('chrome', context=chrome_context)
window_mapping = {
# Tab navigation
'page (previous|left)': Key("cs-tab"),
'page (next|right)': Key("c-tab"),
'page <n>': Key("c-%(n)d"),
'page new': Key("c-t"),
'page reopen': Key("cs-t"),
'page close': Key("c-w"),
'page back': Key("s-h"),
'page forward': Key("s-l"),
'refresh': Key("r"),
'link': Key("f"),
'link new': Key("s-f"),
# Moving around
'more': Key("j:10"),
'less': Key("k:10"),
'top': Key("g, g"),
'bottom': Key("s-g"),
'back': Key("s-h"),
'forward': Key("s-l"),
# Searching
'find <text>': Key("escape, slash") + Text("%(text)s") + Key("enter"),
'next': Key("n"),
'prev|previous': Key("N"),
}
gmail_mapping = {
'open': Key("o"),
'inbox': Key("g, i"),
'[go to] label <text>': Key("g, l") + Text("%(text)s") + Key("enter"),
'trash': Key("hash"),
'archive': Key("e"),
'(earl|early|earlier)': Key("j"),
'(late|later)': Key("k"),
}
class Mapping(dragonfly.MappingRule):
mapping = window_mapping
extras = [
IntegerRef('n', 1, 99),
Dictation('text'),
]
class MappingMail(dragonfly.MappingRule):
mapping = gmail_mapping
extras = [
Dictation('text')
]
grammar.add_rule(Mapping())
grammar.add_rule(MappingMail())
grammar.load()
def unload():
global grammar
if grammar:
grammar.unload()
grammar = None