forked from dictation-toolbox/dragonfly-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mouse_grid.py
219 lines (179 loc) · 5.96 KB
/
_mouse_grid.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""A command module for Dragonfly, for controlling the mouse using a grid.
This is still an experimental functionality. It may contain several bugs,
and it may be heavily modified.
Apart from the normal mouse grid, this grid is made to support multiple
monitors, ctrl-click and shift-click.
So far this is only tested on a dual screen setup.
-----------------------------------------------------------------------------
Licensed under the LGPL, see http://www.gnu.org/licenses/
"""
from dragonfly import (
MappingRule,
Function,
IntegerRef,
Choice,
Dictation,
Grammar,
# AppContext,
)
from lib.dynamic_aenea import (
GlobalDynamicContext,
should_send_to_aenea,
)
import lib.config
config = lib.config.get_config()
if config.get("aenea.enabled", False) == True:
import lib.grid_base_x
import lib.grid_base_win
def mouse_pos(pos1, pos2=None, pos3=None, pos4=None, pos5=None, pos6=None,
pos7=None, pos8=None, pos9=None, action=None):
if should_send_to_aenea():
lib.grid_base_x.mouse_pos(pos1, pos2, pos3, pos4, pos5, pos6, pos7,
pos8, pos9, action)
else:
lib.grid_base_win.mouse_pos(pos1, pos2, pos3, pos4, pos5, pos6, pos7,
pos8, pos9, action)
def left_click():
if should_send_to_aenea():
lib.grid_base_x.left_click()
else:
lib.grid_base_win.left_click()
def right_click():
if should_send_to_aenea():
lib.grid_base_x.right_click()
else:
lib.grid_base_win.right_click()
def double_click():
if should_send_to_aenea():
lib.grid_base_x.double_click()
else:
lib.grid_base_win.double_click()
def control_click():
if should_send_to_aenea():
lib.grid_base_x.control_click()
else:
lib.grid_base_win.control_click()
def shift_click():
if should_send_to_aenea():
lib.grid_base_x.shift_click()
else:
lib.grid_base_win.shift_click()
def mouse_mark():
if should_send_to_aenea():
lib.grid_base_x.mouse_mark()
else:
lib.grid_base_win.mouse_mark()
def mouse_drag():
if should_send_to_aenea():
lib.grid_base_x.mouse_drag()
else:
lib.grid_base_win.mouse_drag()
def hide_grids():
if should_send_to_aenea():
lib.grid_base_x.hide_grids()
else:
lib.grid_base_win.hide_grids()
def go():
if should_send_to_aenea():
lib.grid_base_x.go()
else:
lib.grid_base_win.go()
def unload_grids():
if should_send_to_aenea():
pass # The grid Windows are on the server side, no need to unload.
else:
lib.grid_base_win.unload_grids()
actions = {
"[left] click": left_click,
"right click": right_click,
"double click": double_click,
"control click": control_click,
"shift click": shift_click,
"mark": mouse_mark,
"drag": mouse_drag,
"go": go,
}
navigate_rule = MappingRule(
mapping={
"<pos1> [<pos2>] [<pos3>] [<pos4>] [<pos5>] [<pos6>] [<pos7>] [<pos8>] [<pos9>] [<action>]": Function(mouse_pos), # @IgnorePep8
"[left] click": Function(left_click),
"right click": Function(right_click),
"double click": Function(double_click),
"control click": Function(control_click),
"shift click": Function(shift_click),
"mark": Function(mouse_mark),
"drag": Function(mouse_drag),
"(close|cancel|stop|abort) [[mouse] grid]": Function(hide_grids), # @IgnorePep8
"go": Function(go),
},
extras=[ # Interval 1-9.
IntegerRef("pos1", 1, 10),
IntegerRef("pos2", 1, 10),
IntegerRef("pos3", 1, 10),
IntegerRef("pos4", 1, 10),
IntegerRef("pos5", 1, 10),
IntegerRef("pos6", 1, 10),
IntegerRef("pos7", 1, 10),
IntegerRef("pos8", 1, 10),
IntegerRef("pos9", 1, 10),
Dictation("text"),
Choice("action", actions),
],
defaults={
"pos1": 1
}
)
# Use global context, and activate/deactivate grammar dynamically.
grammarNavigation = Grammar("Grid navigation", context=GlobalDynamicContext())
grammarNavigation.add_rule(navigate_rule) # Add the top-level rule.
grammarNavigation.load() # Load the grammar.
grammarNavigation.disable()
def mouse_grid_start(pos1=None, pos2=None, pos3=None, pos4=None, pos5=None,
pos6=None, pos7=None, pos8=None, pos9=None, action=None):
if should_send_to_aenea():
lib.grid_base_x.set_grammar_reference(grammarNavigation)
grammarNavigation.enable()
lib.grid_base_x.mouse_grid(pos1, pos2, pos3, pos4, pos5, pos6, pos7,
pos8, pos9, action)
else:
lib.grid_base_win.set_grammar_reference(grammarNavigation)
grammarNavigation.enable()
lib.grid_base_win.mouse_grid(pos1, pos2, pos3, pos4, pos5, pos6, pos7,
pos8, pos9, action)
init_rule = MappingRule(
mapping={
"[mouse] grid [<pos1>] [<pos2>] [<pos3>] [<pos4>] [<pos5>] [<pos6>] [<pos7>] [<pos8>] [<pos9>] [<action>]": Function(mouse_grid_start), # @IgnorePep8
# In case focus on the grid/grids has been lost.
# "(close|cancel|stop|abort) [mouse] grid": Function(hide_grids), # @IgnorePep8
},
extras=[
IntegerRef("pos1", 1, 10),
IntegerRef("pos2", 1, 10),
IntegerRef("pos3", 1, 10),
IntegerRef("pos4", 1, 10),
IntegerRef("pos5", 1, 10),
IntegerRef("pos6", 1, 10),
IntegerRef("pos7", 1, 10),
IntegerRef("pos8", 1, 10),
IntegerRef("pos9", 1, 10),
Dictation("text"),
Choice("action", actions),
],
defaults={
"pos1": None
}
)
grammarInit = Grammar("Grid init", context=GlobalDynamicContext())
grammarInit.add_rule(init_rule)
grammarInit.load()
def unload():
"""Unload function which will be called at unload time."""
global grammarInit
if grammarInit:
grammarInit.unload()
grammarInit = None
global grammarNavigation
if grammarNavigation:
grammarNavigation.unload()
grammarNavigation = None
unload_grids()