class PythonNon(MappingRule): mapping = { "with": R(Text("with "), rdescript="Python: With"), "open file": R(Text("open('filename','r') as f:"), rdescript="Python: Open File"), "read lines": R(Text("content = f.readlines()"), rdescript="Python: Read Lines"), "try catch": R(Text("try:") + Key("enter:2/10, backspace") + Text("except Exception:") + Key("enter"), rdescript="Python: Try Catch"), }
class LyxRule(MergeRule): pronunciation = "lyx" mapping = { "new file": R(Key("c-n"), rdescript="LyX: new file"), "open file": R(Key("c-o"), rdescript="LyX: open file"), "save as": R(Key("cs-s"), rdescript="LyX: save as"), "math mode": R(Key("c-m"), rdescript="LyX: math mode"), "display mode": R(Key("cs-m"), rdescript="LyX: display mode"), "view PDF": R(Key("c-r"), rdescript="LyX: view PDF"), "update PDF": R(Key("cs-r"), rdescript="LyX: update PDF"), "move line up [<n>]": R(Key("a-up"), rdescript="LyX: move line up") * Repeat(extra="n"), "move line down [<n>]": R(Key("a-down"), rdescript="LyX: move line down") * Repeat(extra="n"), "insert <environment>": R(Key("a-i, h, %(environment)s"), rdescript="LyX: insert environment"), } extras = [ IntegerRefST("n", 1, 10), Choice( "environment", { "(in line formula | in line)": "i", "(display formula | display)": "d", "(equation array environment | equation array)": "e", "(AMS align environment | AMS align)": "a", "AMS align at [environment]": "t", "AMS flalign [environment]": "f", "(AMS gathered environment | AMS gather)": "g", "(AMS multline [environment]| multiline)": "m", "array [environment]": "y", "(cases [environment] | piecewise)": "c", "(aligned [environment] | align)": "l", "aligned at [environment]": "v", "gathered [environment]": "h", "split [environment]": "s", "delimiters": "r", "matrix": "x", "macro": "o", }), ] defaults = { "n": 1, }
class FoxitRule(MergeRule): pronunciation = "fox it reader" mapping = { "next tab [<n>]": R(Key("c-tab"), rdescript="Foxit Reader: Next Tab") * Repeat(extra="n"), "prior tab [<n>]": R(Key("cs-tab"), rdescript="Foxit Reader: Previous Tab") * Repeat(extra="n"), "close tab [<n>]": R(Key("c-f4/20"), rdescript="Foxit Reader: Close Tab") * Repeat(extra="n"), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim":""}
class CustomVocabulary(MergeRule): pronunciation = "custom vocabulary" mapping = { "doctor": R(Text("docker "), rdescript="CustomVocabulary: Shultz"), "Lower Schultz": R(Text("shultz"), rdescript="CustomVocabulary: Shultz"), "Ashley Gmail": R(Text("*****@*****.**"), rdescript="CustomVocabulary: Shultz"), "e-mail": R(Text(" email "), rdescript="CustomVocabulary: Email") } extras = [] defaults = {}
class SQLDeveloperRule(MergeRule): pronunciation = "sequel developer" mapping = { "run this query": R(Key("f9"), rdescript="SQL Dev: Run Query"), "format code": R(Key("c-f7"), rdescript="SQL Dev: Format Code"), "comment line": R(Key("c-slash"), rdescript="SQL Dev: Comment Line"), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1}
class CustomVocabulary(MergeRule): pronunciation = "Green key" mapping = { "(Ashley at Green key | Ashley Greinke)": R(Text("*****@*****.**"), rdescript="CustomVocabulary: Shultz"), "(Greinke Tech | Green key to)": R(Text("greenkeytech"), rdescript="CustomVocabulary: Shultz"), "(API Greinke Tech | API Green key to)": R(Text("api.greenkeytech.com"), rdescript="CustomVocabulary: Shultz"), "(Greinke | Green key)": R(Text("GreenKey"), rdescript="CustomVocabulary: Shultz"), } extras = [] defaults = {}
class HMCDirectoryRule(MergeRule): mapping = { # specific to directory browser "browse": R(Function(hmc_directory_browse, nexus=_NEXUS), rdescript="Browse Computer") }
class DevelopmentHelp(MappingRule): mapping = { # caster development tools "(show | open) documentation": BringApp(settings.SETTINGS["paths"]["DEFAULT_BROWSER_PATH"]) + WaitWindow(executable=settings.get_default_browser_executable()) + Key('c-t') + WaitWindow(title="New Tab") + Text('http://dragonfly.readthedocs.org/en/latest') + Key('enter'), "open natlink folder": R(BringApp("C:/Windows/explorer.exe", settings.SETTINGS["paths"]["BASE_PATH"].replace("/", "\\")), rdescript="Open Natlink Folder"), "refresh debug file": Function(devgen.refresh), "Agrippa <filetype> <path>": Function(grep_this), "run rule complexity test": Function(lambda: run_tests()), "run unit tests": Function(testrunner.run_tests), "run remote debugger": Function(run_remote_debugger), } extras = [ Dictation("text"), Choice("path", { "natlink": "c:/natlink/natlink", "sea": "C:/", }), Choice("filetype", { "java": "*.java", "python": "*.py", }) ] defaults = {"text": ""}
class PythonNon(MappingRule): mapping = { "try catch": R(Text("try:") + Key("enter:2/10, backspace") + Text("except Exception:") + Key("enter"), rdescript="Python: Try Catch"), }
def __init__(self, num_choice_500s, num_specs): mapping = {} extras = [] defaults = {} w500 = get_500_words() spec_base = "" text_base = "" for k in range(0, num_choice_500s): extra_name = "giant_" + str(k) spec_base += " <" + extra_name + ">" text_base += " %(" + extra_name + ")s" extras.append(get_giant_choice(extra_name)) for i in range(0, num_specs): word = w500[i] mapping[word + spec_base] = R(Text(word + text_base), show=False) MergeRule.__init__(self, name="complexity test", mapping=mapping, extras=extras, defaults=defaults)
def ACP(command, label=None): """Utilize the Palette UI to execute commands.""" if not label: label = "Atom: Unlabeled Palette Command: " + command return R(Key("cs-p") + Pause(str(atom_palette_wait)) + Text(command) + Key("enter"), rdescript=label)
def refresh(self, *args): '''args: spec, list of lists of strings''' # get mapping recorded_macros = utilities.load_json_file(settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) if len(args)>0: recorded_macros[args[0]] = args[1] utilities.save_json_file(recorded_macros, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) mapping = {} for spec in recorded_macros: sequences = recorded_macros[spec] mapping[spec] = R(Playback([(sequence, 0.0) for sequence in sequences])*Repeat(extra="n"), rdescript="Recorded Macro: "+spec) mapping["record from history"] = R(Function(self.record_from_history), rdescript="Record From History") mapping["delete recorded macros"] = R(Function(self.delete_recorded_macros), rdescript="Delete Recorded Macros") # reload with new mapping self.reset(mapping)
def test_cancel(self): mutable_integer = {"value": 0} def increment(): mutable_integer["value"] += 1 '''make fake AsynchronousAction''' context_set = S(["test", "words"], increment) unused_context_set = S(["other"], Text, "words") context_level = L(context_set, unused_context_set) aa1 = AsynchronousAction([context_level], time_in_seconds=0.2, repetitions=20, blocking=False) aa1.set_nexus(self.nexus) '''make fake StackItemAsynchronous''' alt = MockAlternative(u"gray", u"fox") sia1 = StackItemAsynchronous( aa1, {"_node": alt}) # the dictionary is fake Dragonfly data '''add it''' self.nexus.state.add(sia1) '''make fake canceling RegisteredAction''' cancel = R(NullAction(), rspec="test") cancel.set_nexus(self.nexus) '''make fake StackItemRegisteredAction''' alt2 = MockAlternative(u"my", u"spoken", u"words") sira1 = StackItemRegisteredAction(cancel, {"_node": alt2}) '''add it''' self.nexus.state.add(sira1) '''AsynchronousAction should have executed exactly once, when it was added, then immediately gotten canceled''' self.assertEqual(mutable_integer["value"], 1)
class Numbers(MergeRule): pronunciation = CCRMerger.CORE[2] mapping = { "word number <wn>": R(Function(alphanumeric.word_number, extra="wn"), rdescript="Number As Word"), "numb <wnKK>": R(Function(alphanumeric.numbers2, extra="wnKK"), rspec="number", rdescript="Number"), } extras = [ IntegerRefST("wn", 0, 10), IntegerRefST("wnKK", 0, 1000000), ] defaults = {}
def add_modkeys(rule): release = R(Key("shift:up, ctrl:up, alt:up"), rdescript = "Mod Keys Up") if not hasattr(rule, "marked") and\ rule.get_pronunciation()[0:6] != "Merged": # don't augment merged rules-- they'd get it twice for spec in rule.mapping_actual().keys(): rule.mapping_actual()[spec] = release + rule.mapping_actual()[spec] + release rule.marked = True
class CommandRule(MappingRule): mapping = { "next tab [<n>]": R(Key("c-pgdown") * Repeat(extra="n"), rdescript="Notepad++: Next Tab"), "prior tab [<n>]": R(Key("c-pgup") * Repeat(extra="n"), rdescript="Notepad++: Prior Tab"), "close tab [<n>]": R(Key("c-w") * Repeat(extra="n"), rdescript="Notepad++: Close Tab"), "stylize <n2>": R(Mouse("right") + Key("down:6/5, right") + (Key("down") * Repeat(extra="n2")) + Key("enter"), rdescript="Notepad++: Stylize"), "remove style": R(Mouse("right") + Key("down:6/5, right/5, down:5/5, enter"), rdescript="Notepad++: Remove Style"), "preview in browser": R(Key("cas-r"), rdescript="Notepad++: Preview In Browser"), # requires function list plug-in: "function list": R(Key("cas-l"), rdescript="Notepad++: Function List"), } extras = [ Dictation("text"), IntegerRef("n", 1, 100), IntegerRef("n2", 1, 10), ] defaults = {"n": 1}
class WindowsSpeechRecognitionRule(MergeRule): mapping = { "reboot windows speech recognition": R(Function(utilities.reboot, wsr=True), rdescript="Reboot Windows Speech Recognition"), } extras = [] defaults = {}
class IERule(MergeRule): pronunciation = "explorer" mapping = { "address bar": R(Key("a-d"), rdescript="Explorer: Address Bar"), "new folder": R(Key("cs-n"), rdescript="Explorer: New Folder"), "new file": R(Key("a-f, w, t"), rdescript="Explorer: New File"), "(show | file | folder) properties": R(Key("a-enter"), rdescript="Explorer: Properties Dialog"), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1}
def refresh(self, *args): aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) if not ChainAlias.json_path in aliases: aliases[ChainAlias.json_path] = {} if len(args) > 0 and args[0] != "": aliases[ChainAlias.json_path][args[0]] = args[1] utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) mapping = {} for spec in aliases[ChainAlias.json_path]: mapping[spec] = R( Text(str(aliases[ChainAlias.json_path][spec])), rdescript="Chain Alias: " + spec) mapping["chain alias"] = R( Function(self.chain_alias), rdescript="Create Chainable Alias") mapping["delete chain aliases"] = R( Function(lambda: delete_all(self, ChainAlias.json_path)), rdescript="Delete Aliases") self.reset(mapping)
def test_blocking(self): '''tests: 1 - successful termination (queued actions execute immediately) 2 - unsuccessful termination (queued actions are dropped) 3 - cancellation (queued actions are dropped) ''' for i in range(0, 3): '''make fake AsynchronousAction''' context_set = S(["cancel", "words"], NullAction()) context_level = L(context_set) aa1 = AsynchronousAction([context_level], blocking=True) # turn blocking on aa1.set_nexus(self.nexus) '''make fake StackItemAsynchronous''' alt = MockAlternative(u"run", u"blocker") sia1 = StackItemAsynchronous( aa1, {"_node": alt}) # the dictionary is fake Dragonfly data '''add it''' self.nexus.state.add(sia1) '''blocked function''' mutable_integer = {"value": 0} def increment(): mutable_integer["value"] += 1 '''make fake incrementing RegisteredAction''' inc = R(Function(increment), rspec="inc") inc.set_nexus(self.nexus) '''make fake StackItemRegisteredAction''' alt2 = MockAlternative(u"my", u"spoken", u"words") sira1 = StackItemRegisteredAction(inc, {"_node": alt2}) '''add it''' self.nexus.state.add(sira1) '''incrementing should be blocked at this point''' self.assertEqual(mutable_integer["value"], 0) if i == 0: '''incrementing should happen that moment of unblocking''' self.nexus.state.terminate_asynchronous(True) self.assertEqual(mutable_integer["value"], 1) elif i == 1: '''incrementing gets dropped''' self.nexus.state.terminate_asynchronous(False) self.assertEqual(mutable_integer["value"], 0) elif i == 2: '''make fake canceling RegisteredAction''' cancel = NullAction(rspec="cancel") cancel.set_nexus(self.nexus) '''make fake StackItemRegisteredAction''' alt3 = MockAlternative(u"my", u"cancel", u"words") sira2 = StackItemRegisteredAction(cancel, {"_node": alt3}) '''add it''' self.nexus.state.add(sira2) '''incrementing gets dropped''' self.assertEqual(mutable_integer["value"], 0)
def refresh(self, *args): '''args: spec, text''' aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) if not Alias.json_path in aliases: aliases[Alias.json_path] = {} if len(args) > 0: aliases[Alias.json_path][args[0]] = args[1] utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) mapping = {} for spec in aliases[Alias.json_path]: mapping[spec] = R( Text(str(aliases[Alias.json_path][spec])), rdescript="Alias: " + spec) mapping["alias <s>"] = R( Function(lambda s: self.alias(s)), rdescript="Create Alias") mapping["delete aliases"] = R( Function(lambda: delete_all(self, Alias.json_path)), rdescript="Delete Aliases") self.reset(mapping)
class GridControlRule(MappingRule): mapping = { "<n> [by] <n2> [<action>]": R(Function(send_input), rdescript="Douglas Grid: Action"), "exit": R(Function(kill), rdescript="Exit Douglas Grid"), } extras = [ IntegerRef("n", 0, 300), IntegerRef("n2", 0, 300), Choice("action", { "kick": 0, "psychic": 1, }), ] defaults = { "action": -1, }
class GridControlRule(MergeRule): mapping = { "<n> [by] <n2> [<action>]": R(Function(send_input, nexus=_NEXUS), rdescript="Douglas Grid: Action"), "exit | escape | cancel": R(Function(kill, nexus=_NEXUS), rdescript="Exit Douglas Grid"), } extras = [ IntegerRefST("n", 0, 300), IntegerRefST("n2", 0, 300), Choice("action", { "kick": 0, "psychic": 1, }), ] defaults = { "action": -1, }
class MineNon(MappingRule): mapping = { # "switch <exec_path>": # R(Function(window_switcher.switch_window)), # "switch notepad": # R(Playback([(["switch", "to", "notepad"], 0.0)])), # "switch kindle": # R(Playback([(["switch", "to", "kindle"], 0.0)])), # "switch spot if I": # R(Playback([(["switch", "to", "spotify"], 0.0)])), # "switch file man": # R(Playback([(["switch", "to", "fman"], 0.0)])), # "open spot if I": # R(Playback([(["open", "spotify"], 0.0)])), # "open file man": # R(Playback([(["open", "fman"], 0.0)])), "show work [spaces]": R(Key("w-tab")), "(create | new) work [space]": R(Key("wc-d")), "close work [space]": R(Key("wc-f4")), "next work [space] [<n>]": R(Key("wc-right")) * Repeat(extra="n"), "(previous | prior) work [space] [<n>]": R(Key("wc-left")) * Repeat(extra="n"), # "normal mode": # R(Playback([(["switch", "to", "normal", "mode"], 0.0)])), # "command mode": # R(Playback([(["switch", "to", "command", "mode"], 0.0)])), # "dictation mode": # R(Playback([(["switch", "to", "dictation", "mode"], 0.0)])), } extras = [ window_switcher.get_choice(), IntegerRefST("n", 1, 5), ] defaults = { "n": 1, }
class SListUsageRule(MappingRule): mapping = { "L add [<sticky>]": R(Function(add_symbol), rdescript="Add Selected To Sticky List"), "L get <n> [<sticky>]": R(Function(get_symbol), rdescript="Retrieve From Sticky List"), "L remove <n> [<sticky>]": R(Function(remove_word), rdescript="Remove From Sticky List"), "L clear": Function(clear), "L run": R(Function(do_enable), rdescript="Run Sticky List"), "L kill": R(Function(kill), rdescript="Shutdown Sticky List"), } extras = [ IntegerRef("n", 1, 200), Dictation("text"), Choice("sticky", {"run": 1}), ] defaults = {"n": 1, "text": "", "sticky": 0 }
class CommandRule(MappingRule): mapping = { "insert image": R(Key("alt, n, p"), rdescript="Word: Insert Image"), } extras = [ Dictation("dict"), IntegerRef("n", 1, 100), ] defaults = {"n": 1, "dict": "nothing"}
class HMCHistoryRule(MergeRule): mapping = { # specific to macro recorder "check <n>": R(Function(hmc_checkbox, nexus=_NEXUS), rdescript="Check Checkbox"), "check from <n> to <n2>": R(Function(hmc_recording_check_range, nexus=_NEXUS), rdescript="Check Range"), "exclude <n>": R(Function(hmc_recording_exclude, nexus=_NEXUS), rdescript="Uncheck Checkbox"), "[make] repeatable": R(Function(hmc_recording_repeatable, nexus=_NEXUS), rdescript="Make Macro Repeatable") } extras = [ IntegerRefST("n", 1, 25), IntegerRefST("n2", 1, 25), ]
class Numbers(MergeRule): pronunciation = "numbers" mapping = { "word number <wn>": R(Function(alphanumeric.word_number, extra="wn"), rdescript="Number As Word"), "numb <wnKK> [<wnKK2>] [<wnKK3>] [<wnKK4>] [<wnKK5>]": R(Text("%(wnKK)s" + "%(wnKK2)s" + "%(wnKK3)s" + "%(wnKK4)s" + "%(wnKK5)s"), rspec="number", rdescript="Number"), # "<numberalias>": # R(Key("%(numberalias)s")), } extras = [ IntegerRefST("wn", 0, 10), IntegerRefST("wnKK", 0, 10), IntegerRefST("wnKK2", 0, 10), IntegerRefST("wnKK3", 0, 10), IntegerRefST("wnKK4", 0, 10), IntegerRefST("wnKK5", 0, 10), Choice( "numberalias", { "zero": "0", "ein": "1", "twit": "2", "tray": "3", "fear": "4", "firth": "5", "sex": "6", "seventh": "7", "eigen": "8", "net": "9", }), ] defaults = { "wnKK2": "", "wnKK3": "", "wnKK4": "", "wnKK5": "", }
class JavaNon(MappingRule): mapping = { "try catch": R(Text("try{}catch(Exception e){}"), rdescript="Java: Try Catch"), "deco override": R(Text("@Override"), rdescript="Java: Override Decorator"), "iterate and remove": R(Paste( "for (Iterator<TOKEN> iterator = TOKEN.iterator(); iterator.hasNext();) {\n\tString string = iterator.next();\nif (CONDITION) {\niterator.remove();\n}\n}" ), rdescript="Java: Iterate And Remove"), "string builder": R(Paste( "StringBuilder builder = new StringBuilder(); builder.append(orgStr); builder.deleteCharAt(orgStr.length()-1);" ), rdescript="Java: String Builder"), } ncextras = [] ncdefaults = {}
class MSWordRule(MergeRule): pronunciation = "Microsoft Word" mapping = { "insert image": R(Key("alt, n, p"), rdescript="Word: Insert Image"), } extras = [ Dictation("dict"), IntegerRefST("n", 1, 100), ] defaults = {"n": 1, "dict": "nothing"}