class SudokuGridRule(MappingRule): pronunciation = "sudoku grid" mapping = { "<n> [grid <s>] [<action>]": R(Function(move_mouse)), "[<n0>] [grid <s0>] (grab | select | drag) <n> [grid <s>] [<action>]": R(Function(drag_mouse)), "squat {weight=2}": R(Function(store_first_point)), "bench {weight=2}": R(Function(select_text)), SymbolSpecs.CANCEL + "{weight=2}": R(Function(Grid.kill)), } extras = [ ShortIntegerRef("n", -1, 1500), ShortIntegerRef("n0", -1, 1500), ShortIntegerRef("s", 0, 10), ShortIntegerRef("s0", 0, 10), Choice("action", { "kick": 0, "kick (double | 2)": 1, "psychic": 2, "move": 3, }), ] defaults = { "n": 0, "n0": 0, "s": 0, "s0": 0, "action": -1, }
class CppSnippetExampleExperimental(MappingRule): pronunciation = "sublime snippet" mapping = { "<snippet>": R(Function(insert_snippet)), "<snippet_variants> [<n>]": R(Function(insert_snippet_with_variants)), "variant <n>": R(Key("c-z") + Function(insert_variant)), "display variants": R(Key("c-z") + Function(display_variants)), "apply <transformation>": R(Key("c-z") + Function(transform_last_snippet)), "small test": R(Function(send_sublime,c = "insert_snippet",data = {"contents":"${1:${PARAK:y}}=2 + ${PARAK:z}","PARAK":"x"})), "small jerry": R(Function(send_sublime,c = "prev_field",data = {})), "jerry": R(Function(store_and_next)), "<snippet> over": R(Function(insert_snippet_with_defaults)), "<snippet_variants> [<n>] over": R(Function(insert_snippet_with_variants_and_defaults)), } extras = [ IntegerRefST("n",1,10), Choice("snippet",{k:v for k,v in snippets.items() if isinstance(v,str)}), Choice("snippet_variants",{k:v for k,v in snippets.items() if not isinstance(v,str)}), Choice("transformation",transformations), ] defaults = {}
class SudokuGridRule(MappingRule): pronunciation = "sudoku grid" mapping = { "<n> [grid <s>] [<action>]": R(Function(move_mouse)), "[<n0>] [grid <s0>] drag <n> [grid <s>] [<action>]": R(Function(drag_mouse)), "escape": R(Function(kill)), SymbolSpecs.CANCEL: R(Function(kill)), } extras = [ IntegerRefST("n", -1, 1500), IntegerRefST("n0", -1, 1500), IntegerRefST("s", 0, 10), IntegerRefST("s0", 0, 10), Choice("action", { "move": 0, "kick": 1, "kick (double | 2)": 2, "psychic": 3, }), ] defaults = { "n": 0, "n0": 0, "s": 0, "s0": 0, "action": 0, }
class LegionGridRule(MappingRule): mapping = { "<n> [<action>]": R(Function(send_input)), "refresh": R(Function(Grid.mouse_alternates, mode="legion")), SymbolSpecs.CANCEL + " {weight=2}": R(Function(Grid.kill)), "<n1> (select | light) <n2>": R(Function(drag_highlight)), } extras = [ Choice("action", { "kick": 0, "psychic": 1, "select | light": 2, }), ShortIntegerRef("n", 0, 1000), ShortIntegerRef("n1", 0, 1000), ShortIntegerRef("n2", 0, 1000), ] defaults = { "action": -1, }
class MouseAlternativesRule(MappingRule): mapping = { "legion [<monitor>] [<rough>]": R( Function(navigation.mouse_alternates, mode="legion") + Function(utilities.focus_mousegrid, gridtitle="legiongrid")), "rainbow [<monitor>]": R( Function(navigation.mouse_alternates, mode="rainbow") + Function(utilities.focus_mousegrid, gridtitle="rainbowgrid")), "douglas [<monitor>]": R( Function(navigation.mouse_alternates, mode="douglas") + Function(utilities.focus_mousegrid, gridtitle="douglasgrid")), "sudoku [<monitor>]": R( Function(navigation.mouse_alternates, mode="sudoku") + Function(utilities.focus_mousegrid, gridtitle="sudokugrid")), } extras = [ IntegerRefST("monitor", 1, 10), Choice("rough", { "rough": True, "detailed": False }) ] defaults = {"rough": True}
class SikuliManagementRule(MappingRule): mapping = { "launch sick IDE": R(Function(_sc.launch_IDE)), "launch sick server": R(Function(_sc.bootstrap_start_server_proxy)), "terminate sick server": R(Function(_sc.terminate_server_proxy)), }
class HardwareRule(MappingRule): mapping = { # Windows 10 changes volume by increments 2 "volume <volume_mode> [<n_volume>]": R(Key("%(volume_mode)s") * Repeat(extra="n_volume")), "media <multimedia_control> [<n_media>]": R(Key("%(multimedia_control)s") * Repeat(extra="n_media")), "change monitor": R(Key("w-p") + Pause("100") + Function(change_monitor)) } extras = [ IntegerRefST("n_media", 1, 15), IntegerRefST("n_volume", 1, 50), Choice("multimedia_control", { "next": "tracknext", "back": "trackprev", "play|pause": "playpause", }), Choice("volume_mode", { "mute|unmute": "volumemute", "up": "volumeup", "down": "volumedown", }) ] defaults = { "n_volume": 1, "n_media": 1, "volume_mode": "setsysvolume", }
class PrologNon(MappingRule): mapping = { "Rule": R(Text("() :-.") + Key("left/6")), SymbolSpecs.IF: R(Text("( ") + Key("enter") + Text(";") + Key("enter") + Text(")")), }
class TmuxRule(MappingRule): mapping = { "pane close": R(Key("c-b, x")), "pane split vertical": R(Key("c-b, percent")), "pane split horizontal": R(Key("c-b, quote")), "window move": R(Key("c-b, p")), "window rename": R(Key("c-b, comma")), }
class WindowManagementRule(MappingRule): mapping = { 'minimize': R(Playback([(["minimize", "window"], 0.0)])), 'maximize': R(Playback([(["maximize", "window"], 0.0)])), "remax": R(Key("a-space/10,r/10,a-space/10,x")), }
class StackTest(MappingRule): '''test battery for the ContextStack''' mapping = { "close last tag": ContextSeeker([ L(S(["cancel"], None), S(["html spoken"], close_last_spoken, use_spoken=True), S(["span", "div"], close_last_rspec, use_rspec=True)) ]), "html": R(Text("<html>"), rspec="html spoken"), "divider": R(Text("<div>"), rspec="div"), "span": R(Text("<span>"), rspec="span"), "backward seeker [<text>]": ContextSeeker([ L(S(["ashes"], Text("ashes1 [%(text)s] ")), S(["bravery"], Text("bravery1 [%(text)s] "))), L(S(["ashes"], Text("ashes2 [%(text)s] ")), S(["bravery"], Text("bravery2 [%(text)s] "))) ]), "forward seeker [<text>]": ContextSeeker(forward=[ L(S(["ashes"], Text("ashes1 [%(text)s] ")), S(["bravery"], Text("bravery1 [%(text)s] "))), L(S(["ashes"], Text("ashes2 [%(text)s] ")), S(["bravery"], Text("bravery2 [%(text)s] "))) ]), "asynchronous test": AsynchronousAction([ L(S(["ashes", "charcoal"], print_time, None), S(["bravery"], Text, "bravery1")) ], time_in_seconds=0.2, repetitions=20, finisher=Text(FINISHER_TEXT), blocking=False), "ashes": RegisteredAction(Text("ashes _ "), rspec="ashes"), "bravery": RegisteredAction(Text("bravery _ "), rspec="bravery"), "charcoal <text> [<n>]": R(Text("charcoal _ %(text)s"), rspec="charcoal"), "test confirm action": ConfirmAction(Key("a"), rdescript="Confirm Action Test", instructions="some words here"), "test box action": BoxAction(lambda data: _abc(data), rdescript="Test Box Action", box_type=settings.QTYPE_DEFAULT, log_failure=True), } extras = [Dictation("text"), Dictation("text2"), IntegerRefST("n", 1, 5)] defaults = {"text": "", "text2": ""}
def _deserialize(self): """ This _deserialize creates mapping which uses the user-made extras. """ self._initialize() self._smr_mapping = { "bring me <program>": R(Function(self._bring_program)), "bring me <website>": R(Function(self._bring_website)), "bring me <folder> [in <app>]": R(Function(self._bring_folder)), "bring me <file>": R(Function(self._bring_file)), "refresh bring me": R(Function(self._load_and_refresh)), "<launch_type> to bring me as <key>": R(Function(self._bring_add)), "to bring me as <key>": R(Function(self._bring_add_auto)), "remove <key> from bring me": R(Function(self._bring_remove)), "restore bring me defaults": R(Function(self._bring_reset_defaults)), } self._smr_extras = [ Choice( "launch_type", { "[current] program": "program", "website": "website", "folder": "folder", "file": "file", }), Choice("app", { "terminal": "terminal", "explorer": "explorer", }), Dictation("key"), ] self._smr_extras.extend(self._rebuild_items()) self._smr_defaults = {"app": None}
class MouseAlternativesRule(MappingRule): mapping = { "legion [<monitor>]": R(Function(navigation.mouse_alternates, mode="legion")), "rainbow [<monitor>]": R(Function(navigation.mouse_alternates, mode="rainbow")), "douglas [<monitor>]": R(Function(navigation.mouse_alternates, mode="douglas")), } extras = [IntegerRefST("monitor", 1, 10)] defaults = {}
class CustomVSCode(MergeRule): pronunciation = "custom visual studio code" mapping = { "save file as": R(Key("cs-s"), rdescript="VS Code: Save As"), "uppercase": R(Key("csa-u"), rdescript="VS Code: uppercase"), "lowercase": R(Key("csa-l"), rdescript="VS Code: lowercase"), "execute": R(Key("s-enter"), rdescript="VS Code: Ctrl + b"), "[go to] group [<n2>]": R(Key("c-%(n2)s"), rdescript="VS Code: Go to Group #"), "spring <n>": R(Key("c-g") + Pause("10") + Text("%(n)s") + Key("enter"), rdescript="VS Code: Go to Line #"), "crew [<text>]": R(Key("c-f") + Pause("10") + Text("%(text)s") + Pause("10") + Key("escape"), rdescript="VS Code: Get Next"), "trail [<text>]": R(Key("c-f") + Pause("10") + Text("%(text)s") + Pause("10") + Key("s-enter") + Key("escape"), rdescript="VS Code: Get Next"), "expand|fill quotes": R(Key("cs-space"), rdescript="VS Code: Expand Selection to Quotes"), "(cellaring | sell rang) <n> <n3>": R( Key("c-g") + Pause("5") + Text("%(n)s") + Key("enter") + Pause("5") + Key("c-k") + Key("c-b") + Pause("5") + Key("c-g") + Pause("10") + Text("%(n3)s") + Key("enter") + Key("end") + Key("c-k") + Key("c-k")), # The following commands of been enabled via words.txt # If Caster gets rid of transformers, reenable these words # "grab it": # R(Key("c-d"), rdescript="VS Code: Ctrl + d"), # "skip it": # R(Key("c-k,c-d"), rdescript="VS Code: Ctrl + d, k"), # "cue jeep": # R(Key("a-up"), rdescript="VS Code: uppercase"), # "cue doom": # R(Key("a-down"), rdescript="VS Code: uppercase"), } extras = [ Dictation("text"), Dictation("mim"), ShortIntegerRef("n", 1, 1000), ShortIntegerRef("n2", 1, 9), ShortIntegerRef("n3", 1, 999), ] defaults = {"n": 1, "mim": "", "text": ""}
class RapidCode(MergeRule): pronunciation = "rapid code" mapping = { "to end of line": R( Function(execute_command, command_name="cursorLineEndSelect") ), "comment": R(Function(execute_command, command_name="editor.action.commentLine")), } extras = [ Dictation("dictation"), ]
class Numbers(MergeRule): pronunciation = "numbers" mapping = { "word number <wn>": R(Function(word_number, extra="wn")), "numb <wnKK>": R(Function(numbers2, extra="wnKK"), rspec="Number"), } extras = [ IntegerRefST("wn", 0, 10), IntegerRefST("wnKK", 0, 1000000), ] defaults = {}
class HMCHistoryRule(MappingRule): mapping = { # specific to macro recorder "check <n>": R(Function(hmc_checkbox)), "check from <n> to <n2>": R(Function(hmc_recording_check_range)), "exclude <n>": R(Function(hmc_recording_exclude)), "[make] repeatable": R(Function(hmc_recording_repeatable)) } extras = [ IntegerRefST("n", 1, 25), IntegerRefST("n2", 1, 25), ]
class FoxitRule(MappingRule): mapping = { "next tab [<n>]": R(Key("c-tab")) * Repeat(extra="n"), "prior tab [<n>]": R(Key("cs-tab")) * Repeat(extra="n"), "close tab [<n>]": R(Key("c-f4/20")) * Repeat(extra="n"), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim": ""}
class SQLDeveloperRule(MappingRule): mapping = { "run this query": R(Key("f9")), "format code": R(Key("c-f7")), "comment line": R(Key("c-slash")), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1}
class PythonNon(MappingRule): mapping = { "with": R(Text("with ")), "open file": R(Text("open('filename','r') as f:")), "read lines": R(Text("content = f.readlines()")), "try catch": R( Text("try:") + Key("enter:2/10, backspace") + Text("except Exception:") + Key("enter")), }
class CasterRule(MappingRule): mapping = { "clear caster log": R(Function(utilities.clear_log)), "reboot caster": R(Function(utilities.reboot)), # ccr de/activation "enable (c c r|ccr)": R(Function(lambda: control.nexus().set_ccr_active(True))), "disable (c c r|ccr)": R(Function(lambda: control.nexus().set_ccr_active(False))), }
class MiscellaneousRule(MappingRule): mapping = { "grid overlay close": R(Function(stop_grid)), "grid overlay open": R(Function(start_grid)), #"hotel info": Text("These types of hospitality industry are not cheap."), #'(motel | lodging)': Playback([(["hotel", "info"], 0.0)]), #"open natlink folder": BringApp("explorer", r"C:\NatLink\NatLink\MacroSystem"), #"remax": Key("a-space/10,r/10,a-space/10,x"), #"remax": Key("a-space/10,r/10,a-space/10,x"), #"(show | open) documentation": BringApp('C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe') + WaitWindow(executable="chrome.exe") + Key('c-t') + WaitWindow(title="New Tab") + Text('https://dragonfly2.readthedocs.io/en/latest') + Key('enter'), #'reload taskbar': Function(reload), "(take note|techno) <textnv>": Function(take_note), "bring me notes": Function(jump_to_notes), "daily note <textnv>": Function(take_note_daily), "bring me daily notes": Function(jump_to_notes_daily), } extras = [ #IntegerRefST("nnavi500", 1, 500), Dictation("textnv"), #Choice("capitalization", { # "capitalize": 1, # THISISATEST # "camelcaps": 2, # ThisIsATest # "camelcase": 3, # thisIsATest # # "caps": 4, # "laws": 5, # thisisatest # "dragon say": 6, # this is a test # "single caps": 7, # This is a test # "(dragon slip|lowercase)": 8, # this is a test # "spongebob": 9, # this is a test #}), ] defaults = { "textnv": "", }
class CasterRule(MappingRule): mapping = { # update management ToDo: Fully implement castervoice PIP install #"update caster": # R(_DependencyUpdate([_PIP, "install", "--upgrade", "castervoice"])), "update dragonfly": R(_DependencyUpdate([_PIP, "install", "--upgrade", "dragonfly2"])), # ccr de/activation "enable c c r": R(Function(lambda: control.nexus().set_ccr_active(True))), "disable c c r": R(Function(lambda: control.nexus().set_ccr_active(False))), }
def _deserialize(self): mapping = {} pronunciation = self.get_pronunciation() # recreate all saved aliases commands = self._config.get_copy() for spec in commands: text = commands[spec] mapping[spec] = R(Text(text), rdescript="{}: {}".format(pronunciation, spec)) # add command for creating new aliases mapping["{} [<s>]".format(pronunciation)] = R( Function(lambda s: self._alias(s)), rdescript="Create {}".format(pronunciation)) # add command for deleting all aliases mapping["delete {}es".format(pronunciation)] = R( Function(lambda: self._delete_all()), rdescript="Delete {}".format(pronunciation)) self._smr_mapping = mapping
class JavaNon(MappingRule): mapping = { "try catch": R(Text("try{}catch(Exception e){}")), "deco override": R(Text("@Override")), "iterate and remove": R(Paste( "for (Iterator<TOKEN> iterator = TOKEN.iterator(); iterator.hasNext();) {\n\tString string = iterator.next();\nif (CONDITION) {\niterator.remove();\n}\n}" )), "string builder": R(Paste( "StringBuilder builder = new StringBuilder(); builder.append(orgStr); builder.deleteCharAt(orgStr.length()-1);" )), }
def _deserialize(self): mapping = {} recorded_macros = self._config.get_copy() for spec in recorded_macros: sequences = recorded_macros[spec] delay = settings.settings(["miscellaneous", "history_playback_delay_secs"]) # The associative string (ascii_str) must be ascii, but the sequences within Playback must be Unicode. mapping[spec] = R( Playback([(sequence, delay) for sequence in sequences]), rdescript="Recorded Macro: " + spec) * Repeat(extra="n") mapping["record from history"] = R( Function(lambda: self._record_from_history()), rdescript="Record From History") mapping["delete recorded macros"] = R( Function(lambda: self._delete_recorded_macros()), rdescript="Delete Recorded Macros") self._smr_mapping = mapping
class SudokuGridRule(MergeRule): ''' Rules for sudoku grid. We can either move the mouse or drag it. The number n is one of the numbered squares. The grid portion is a number from 1-9 referencing an inner unnumbered square. ''' pronunciation = "sudoku grid" mapping = { "curse <xn> by <yn> [grid <hexdigit>]": R(Function(move_mouse)), "drag <xn> by <yn> [grid <hexdigit>]": R(Function(drag_mouse)), } extras = [ IntegerRef("yn", -1, 100), IntegerRef("xn", -1, 100), IntegerRef("sn", 0, 10), Choice( "hexdigit", { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, "arch": 10, "brov": 11, "char": 12, "delta": 13, "echo": 14, "foxy": 15, }), Choice("action", { "move": 0, "kick": 1, "kick (double | 2)": 2, "psychic": 3, }), ] defaults = { "xn": 0, "yn": 0, "hexdigit": None, "action": 0, }
class VHDLnon(MappingRule): mapping = { "entity": R(entity_string), "Architecture": R(architecture_string), "component": R(component_string), "component declaration": R(component_declaration_string), SymbolSpecs.SWITCH: R(case_string), SymbolSpecs.CASE: R(Text("case TOKEN is")), "process": R(process_string), "generate components": R(for_generate_string), "conditional component": R(if_generate_string), }
class Markdown(MergeRule): pronunciation = "mark down" mapping = { "heading [<num>] [<dict>]": R(Store() + Function(lambda num, dict: Text( ("#" * num) + " " + str(dict).capitalize()).execute()) + Retrieve() + Key("enter")), "table row <n>": R(Function(lambda n: Text("|" * (n - 1)).execute()) + Key("home")), "table (break | split) <n>": R( Function(lambda n: Text("---|" * (n - 1) + "---").execute()) + Key("enter")), "insert <element>": R(Store() + Key("%(element)s") + Retrieve(action_if_text="c-right")), "insert header": R(Text("---\nauthor: \ntitle: \n---\n")), } extras = [ Dictation("dict"), ShortIntegerRef("n", 1, 12), ShortIntegerRef("num", 1, 7), Choice( "element", { "list": "asterisk, space", "numbered list": "one, dot, space", "[block] quote": "rangle, space", "link": "lbracket, rbracket, lparen, rparen, left:3", "image": "exclamation, lbracket, rbracket, lparen, rparen, left:3", "reference": "lbracket, rbracket, left, at", "equation": "dollar, dollar, enter:2, dollar, dollar, up", "math": "dollar, dollar, left", "(italics | italic text)": "underscore:2, left", "bold [text]": "asterisk:4, left:2", "strike through [text]": "tilde:4, left:2", "horizontal rule": "asterisk, asterisk, asterisk, enter", "R code": "backtick:3, lbrace, r, rbrace, enter:2, backtick:3, up", "in line code": "backtick:2, left", "code [block]": "backtick:6, left:3, enter:2, up", }), ] defaults = { "num": 1, "dict": "", }
class Again(MappingRule): mapping = { "again (<n> [(times|time)] | do)": R(Function(lambda n: Again._create_asynchronous(n)), show=False), # pylint: disable=E0602 } extras = [IntegerRefST("n", 1, 50)] defaults = {"n": 1} @staticmethod def _repeat(utterance): Playback([(utterance, 0.0)]).execute() return False @staticmethod def _create_asynchronous(n): if len(_history) == 0: return last_utterance_index = 1 if settings.WSR: # ContextStack adds the word to history before executing it if len(_history) == 1: return last_utterance_index = 2 utterance = [ str(x) for x in " ".join(_history[len(_history) - last_utterance_index]).split() ] if utterance[0] == "again": return forward = [L(S(["cancel"], lambda: Again._repeat(utterance)))] AsynchronousAction(forward, rdescript="Repeat Last Action", time_in_seconds=0.2, repetitions=int(n), blocking=False).execute()