This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
forked from dictation-toolbox/Caster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_caster.py
159 lines (131 loc) · 5.16 KB
/
_caster.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
#! python2.7
'''
main Caster module
Created on Jun 29, 2014
'''
import os, time, sys
import logging
logging.basicConfig()
import time, socket, os
from dragonfly import (get_engine, Function, Grammar, Playback, Dictation, Choice, Pause,
RunCommand)
from castervoice.lib.ctrl.dependencies import DependencyMan # requires nothing
DependencyMan().initialize()
_NEXUS = None
from castervoice.lib import settings # requires toml
if settings.SYSTEM_INFORMATION["platform"] != "win32":
raise SystemError("Your platform is not currently supported by Caster.")
settings.WSR = __name__ == "__main__"
from castervoice.lib import utilities # requires settings
from castervoice.lib.ccr.standard import SymbolSpecs
if settings.WSR:
SymbolSpecs.set_cancel_word("escape")
from castervoice.lib import control
_NEXUS = control.nexus()
from castervoice.lib.ctrl.dependencies import find_pip, update
from castervoice.lib import navigation
navigation.initialize_clipboard(_NEXUS)
from castervoice.apps import __init__
from castervoice.asynch import *
from castervoice.lib.ccr import *
from castervoice.lib.ccr.recording import bringme, again, alias, history
import castervoice.lib.dev.dev
from castervoice.asynch.sikuli import sikuli
from castervoice.lib.actions import Key
from castervoice.lib.terminal import TerminalCommand
from castervoice.lib.dfplus.state.short import R
from castervoice.lib.dfplus.additions import IntegerRefST
from castervoice.lib.dfplus.merge.mergepair import MergeInf
from castervoice.lib.dfplus.merge.mergerule import MergeRule
if not globals().has_key('profile_switch_occurred'):
# Load user rules
_NEXUS.process_user_content()
_NEXUS.merger.update_config()
_NEXUS.merger.merge(MergeInf.BOOT)
class DependencyUpdate(RunCommand):
synchronous = True
# pylint: disable=method-hidden
def process_command(self, proc):
# Process the output from the command.
RunCommand.process_command(self, proc)
# Only reboot dragon if the command was successful and online_mode is true
# 'pip install ...' may exit successfully even if there were connection errors.
if proc.wait() == 0 and update:
Playback([(["reboot", "dragon"], 0.0)]).execute()
def change_monitor():
if settings.SETTINGS["sikuli"]["enabled"]:
Playback([(["monitor", "select"], 0.0)]).execute()
else:
print("This command requires SikuliX to be enabled in the settings file")
pip = find_pip()
class MainRule(MergeRule):
@staticmethod
def generate_ccr_choices(nexus):
choices = {}
for ccr_choice in nexus.merger.global_rule_names():
choices[ccr_choice] = ccr_choice
return Choice("name", choices)
@staticmethod
def generate_sm_ccr_choices(nexus):
choices = {}
for ccr_choice in nexus.merger.selfmod_rule_names():
choices[ccr_choice] = ccr_choice
return Choice("name2", choices)
mapping = {
# update management
# "update caster":
# R(DependencyUpdate([pip, "install", "--upgrade", "castervoice"])),
# "update dragonfly":
# R(DependencyUpdate([pip, "install", "--upgrade", "dragonfly2"])),
# hardware management
"volume <volume_mode> [<n>]":
R(Function(navigation.volume_control, extra={'n', 'volume_mode'})),
"change monitor":
R(Key("w-p") + Pause("100") + Function(change_monitor)),
# passwords
# mouse alternatives
"legion [<monitor>]":
R(Function(navigation.mouse_alternates, mode="legion", nexus=_NEXUS)),
"rainbow [<monitor>]":
R(Function(navigation.mouse_alternates, mode="rainbow", nexus=_NEXUS)),
"douglas [<monitor>]":
R(Function(navigation.mouse_alternates, mode="douglas", nexus=_NEXUS)),
# ccr de/activation
"<enable> <name>":
R(Function(_NEXUS.merger.global_rule_changer(), save=True)),
"<enable> <name2>":
R(Function(_NEXUS.merger.selfmod_rule_changer(), save=True)),
"enable caster":
R(Function(_NEXUS.merger.merge, time=MergeInf.RUN, name="numbers")),
"disable caster":
R(Function(_NEXUS.merger.ccr_off)),
}
extras = [
IntegerRefST("n", 1, 50),
Dictation("text"),
Dictation("text2"),
Dictation("text3"),
Choice("enable", {
"enable": True,
"disable": False
}),
Choice("volume_mode", {
"mute": "mute",
"up": "up",
"down": "down"
}),
generate_ccr_choices.__func__(_NEXUS),
generate_sm_ccr_choices.__func__(_NEXUS),
IntegerRefST("monitor", 1, 10)
]
defaults = {"n": 1, "nnv": 1, "text": "", "volume_mode": "setsysvolume", "enable": -1}
control.non_ccr_app_rule(MainRule(), context=None, rdp=False)
if globals().has_key('profile_switch_occurred'):
reload(sikuli)
else:
profile_switch_occurred = None
print("\n*- Starting " + settings.SOFTWARE_NAME + " -*")
if settings.WSR:
print("Windows Speech Recognition is garbage; it is " \
+"recommended that you not run Caster this way. ")
get_engine().recognize_forever()