def __init__(self, spec=None, static=False, pause=0.02, autofmt=False): Text.__init__(self, spec, static, pause, autofmt) # Since we're not actually part of the Dragonfly Action hierarchy and dynamically dispatch to one of two # Action implementations, we can't simply subclass and rely on polymorphism to call the correct method. # That's because this class is a subclass of the container, not of the Action itself. So, in order to ensure # our overridden method is called on the correct Action, we must add an unbound copy of the method to each # of the Actions. setattr(self._dragonfly_action, "_parse_spec", self._parse_spec)
class CodeMappings(MappingRule): mapping = { 'dock stat': Text('docker ps -a') + Key('enter'), 'dock rem': Text('docker rm'), 'dock redis': Text('docker run --name devredis -p 6379:6379 -d redis') + Key('enter'), 'redis commander': Text('redis-commander') + Key('enter'), } extras=[ Integer('tab', 1, 10), Integer('number', 1, 9999), Dictation("text") ]
def __init__(self, spec=None, static=False, pause=_pause_default, autofmt=False, use_hardware=False): TextBase.__init__(self, spec=spec, static=static, pause=pause, autofmt=autofmt, use_hardware=use_hardware)
class GlobalChromeMappings(MappingRule): mapping = { "new (thing | tab)": Key("c-t"), "new window": Key("c-n"), "reopen tab": Key("cs-t"), "(next | nex) (tab | ab) [<n>]": Key("c-pgdown:%(n)d"), "(previous | preev) tab [<n>]": Key("c-pgup:%(n)d"), "show tab <tab>": Key("c-%(tab)d"), "(first | firs) tab": Key("c-1"), "(last | lass | las ) tab": Key("c-9"), "go back": Key("a-left"), "go forward": Key("a-right"), "address [bar]": Key("a-d"), "refresh page": Key("f5"), "find <text>": Key("c-g/25") + Text("%(text)s"), "find next": Key("enter"), "find (prev | previous)": Key("s-enter"), "bookmark page": Key("c-d"), "(full-screen | full screen)": Key("f11"), # Click By Voice "open <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumber) + Key("enter"), # click by voice "open focus <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumberFocus) + Key("enter"), # click by voice "open click <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumberClick) + Key("enter"), # click by voice go_command + " <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumberToTab) + Key("enter"), # click by voice go_command + " tab <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumberGoToTab) + Key("enter"), # click by voice go_command + " window <w> [<x>] [<y>] [<z>]": Key("cs-space/" + click_by_voice_delay) + Function(printNumberGoToWindow) + Key("enter"), # click by voice "hide hints": Key("cs-space/" + click_by_voice_delay) + Text(":-") + Key("enter"), # click by voice "show hints": Key("cs-space/" + click_by_voice_delay) + Text(":+") + Key("enter"), # click by voice "high contrast": Key("cs-space/" + click_by_voice_delay) + Text(":+c") + Key("enter"), # click by voice # Vimium "open": Key("f"), "tabs": Key("s-f"), "get Earl": Key("y,y"), # copy the current url to the clipboard "get link Earl": Key("y,f"), # copy a link url to the clipboard # "(go | goat | goke | launch | lunch) <number>": Text("%(number)d"), # vimium "(duplicate | dupe) tab": Key("y/25,t"), # vimium } extras=[ Integer("n", 1, 50), Integer("w", 0, 10), Integer("x", 0, 10), Integer("y", 0, 10), Integer("z", 0, 10), Integer("tab", 1, 8), Integer("number", 1, 9999), Dictation("text"), ] defaults = { "n": 1, }
class PHPUsefulMethods(MappingRule): mapping = { "print statement": Text("print_r();") + Key("left") + Key("left"), "echo statement": Text("echo \"\";") + Key("left") + Key("left"), "dump statement": Text("var_dump();") + Key("left") + Key("left"), "log statement": Text("error_log(print_r(,true));") + Key("left") + Key("left") + Key("left") + Key("left") + Key("left") + Key("left") + Key("left") + Key("left"), }
class NetrwRule(MappingRule): exported = True mapping = { "explore here": Text(":Explore") + Key("enter"), "explore fault": Text(":Vexplore") + Key("enter"), "explore split": Text(":Sexplore") + Key("enter"), "explore tab": Text(":Texplore") + Key("enter"), "explore back": Text(":Rexplore") + Key("enter"), "create net file": Key('%%'), "create net directory": Key('d') } extras = [] defaults = {}
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"), }
def letters(big, dict1, dict2, letter): '''used with alphabet.txt''' d1 = str(dict1) if d1 != "": Text(d1).execute() if str(big) != "": Key("shift:down").execute() letter.execute() if str(big) != "": Key("shift:up").execute() d2 = str(dict2) if d2 != "": Text(d2).execute()
class UsefulStuff(MappingRule): mapping = { "in quotes": Text("\"\"") + Key("left"), "in single quotes": Text("\'\'") + Key("left"), "dirty bird": Text("()") + Key("left"), "in brackets": Text("[]") + Key("left"), "in braces": Text("{}") + Key("left"), "in angle brackets": Text("<>") + Key("left"), "in parameters": Text("()"), "arrow": Text("->"), "double arrow": Text("=>"), "fat arrow": Text("=>"), }
class Movement(MappingRule): mapping = { "[<n>] (down | jay | J)": Text("%(n)dj"), "[<n>] (up | kay | K)": Text("%(n)dk"), "[<n>] (left | h)": Text("%(n)dh"), "[<n>] (right | el | l)": Text("%(n)dl"), "[<n>] (word | dub | W)": Text("%(n)dw"), "[<n>] big (word | dub | W)": Text("%(n)dW"), "[<n>] (bee | B | be)": Text("%(n)db"), "[<n>] big (bee | B | be)": Text("%(n)dB"), "dollar": Key("$"), "carrot": Key("^"), "page down": Key('c-d'), "page up": Key('c-u'), "go left window": Key('c-w, h'), "go right window": Key('c-w, l'), "go next window": Key('c-w, w'), "go previous window": Key('c-w, p'), "go next tab": Key('c-w, t'), "go previous tab": Key('c-w, T'), } extras = [ IntegerRef("n", 1, 900), ] defaults = { "n": 1, }
class TerminalCommandsRule(MappingRule): mapping = { "terminal directory": Text("dir") + Key("enter"), "terminal up": Key("up"), "terminal python": Text("python "), "terminal change": Text("cd "), # window navigation commands "window left": Key("c-w,h"), "window right": Key("c-w,l"), "window up": Key("c-w,k"), "window down": Key("c-w,j"), } extras = [] defaults = {}
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 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 = {}
def squash_count(n): """Formats n words to the left of the cursor with whitespace removed. Excepting spaces immediately after comma, colon and percent chars. Note: Word count differs between editors and programming languages. The examples are all from Eclipse/Python. Example: "'my new variable' *pause* 'squash 3'" => "mynewvariable". "'my<tab>new variable' *pause* 'squash 3'" => "mynewvariable". "( foo = bar, fee = fye )", 'squash 9'" => "(foo=bar, fee=fye)" """ saveText = _get_clipboard_text() cutText = _select_and_cut_text(n) if cutText: endSpace = cutText.endswith(' ') text = _cleanup_text(cutText) newText = ''.join(text.split(' ')) if endSpace: newText = newText + ' ' newText = _expand_after_special_chars(newText) newText = newText.replace("%", "%%") # Escape any format chars. Text(newText).execute() else: # Failed to get text from clipboard. Key('c-v').execute() # Restore cut out text. _set_clipboard_text(saveText)
class fluidOne(QuickFluidRules): name = "fluid_one" mapping = { "snarl": Key("space, s, n, a, r, space"), "burp": Text(" burpy "), "groan": Text(" g r o aaa n "), } extras = [ Integer("n", 1, 50), Integer("tab", 1, 8), Integer("number", 1, 9999), Dictation("text"), ] defaults = { "n": 1, }
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": ""}
def output_if(name, statement_type): execute_with_dictation( name, on_dictation=lambda v: Text("%s %s {" % (statement_type, format_variable_name(name))), on_other=lambda v: replace_in_text("%s $ {" % statement_type), )
class FirefoxRule(MergeRule): pronunciation = "fire fox" mapping = { "new tab [<n>]": R(Key("c-t"), rdescript="Browser: New Tab") * Repeat(extra="n"), "reopen tab [<n>]": R(Key("cs-t"), rdescript="Browser: Reopen Tab") * Repeat(extra="n"), "show history": R(Key("c-h"), rdescript="Browser: Show History"), "show downloads": R(Key("c-j"), rdescript="Browser: Show Downloads"), "zoom in <n>": R(Key("c-plus/20"), rdescript="Browser: Zoom In") * Repeat(extra="n"), "zoom out <n>": R(Key("c-minus/20"), rdescript="Browser: Zoom") * Repeat(extra="n"), "super refresh": R(Key("c-f5"), rdescript="Browser: Super Refresh"), "[add] bookmark": R(Key("c-d"), rdescript="Browser: Add Bookmark"), "developer tools": R(Key("f12"), rdescript="Browser: Developer Tools"), "resume": R(Key("f8"), rdescript="Browser: Resume"), "step over": R(Key("f10"), rdescript="Browser: Step Over"), "step into": R(Key("f11"), rdescript="Browser: Step Into"), "step out": R(Key("s-f11"), rdescript="Browser: Step Out"), "IRC identify": R(Text("/msg NickServ identify PASSWORD"), rdescript="IRC Chat Channel Identify"), } extras = [ Dictation("dict"), IntegerRefST("n",1, 100), ] defaults ={"n": 1, "dict":"nothing"}
class EclipseCCR(MergeRule): pronunciation = "eclipse jump" mwith = [Navigation().get_pronunciation()] mapping = { #Line Ops "configure": R(Paste(ec_con.analysis_chars)+Key("left:2/5, c-f/20, backslash, rbracket, enter") + \ Function(ec_con.analyze_for_configure), rdescript="Eclipse: Configure"), "jump in [<n>]": R(Key("c-f, a-o")+Paste(r"[\(\[\{\<]")+Function(ec_con.regex_on)+ \ Key("enter:%(n)d/5, escape, right") , rdescript="Eclipse: Jump In"), "jump out [<n>]": R(Key("c-f, a-o")+Paste(r"[\)\] \}\>]")+Function(ec_con.regex_on)+ \ Key("enter:%(n)d/5, escape, right") , rdescript="Eclipse: Jump Out"), "jump back [<n>]": R(Key("c-f/5, a-b")+Paste(r"[\)\]\}\>]")+Function(ec_con.regex_on)+ \ Key("enter:%(n)d/5, escape, left") , rdescript="Eclipse: Jump Back"), "[go to] line <n>": R(Key("c-l") + Pause("50") + Text("%(n)d") + Key("enter")+ Pause("50"), rdescript="Eclipse: Go To Line"), "shackle <n> [<back>]": R(Key("c-l")+Key("right, cs-left")+ \ Function(ec_con.lines_relative), rdescript="Eclipse: Select Relative Lines"), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), Boolean("back"), ] defaults = {"n": 1, "back": False}
class VimCommands(MappingRule): extras = [ Dictation('text'), IntegerRef("n", 1, 1000), IntegerRef("line", 1, 10000), ] defaults = { "n": 1, "z": 1, } mapping = { # Basic modes "insert mode": Key("i"), "command mode": Key("escape"), "save file": Key("colon, w, enter"), "quit": Key("colon, q"), # Navigation "up [<n>]": Key("k:%(n)d"), "down [<n>]": Key("j:%(n)d"), "left [<n>]": Key("h:%(n)d"), "right [<n>]": Key("l:%(n)d"), "go [<line>]": Key("colon") + Text("%(line)s\n"), # Basic commands "delete line": Key("d,d"), "undo": Key("u"), "word [<n>]": Key("w:%(n)d"), "back [<n>]": Key("b:%(n)d"), "change word": Key("c,w"), }
def output_switch(name): if name == "": command = replace_in_text("switch ($) {}") else: name = format_name(name) command = Text("switch (%s) {}" % name) command.execute()
def expand_count(n): """Formats n words to the left of the cursor by adding whitespace in certain positions. Note that word count differs between editors and programming languages. The examples are all from Eclipse/Python. Example, with to compact code: "result=(width1+width2)/2 'expand 9' " => "result = (width1 + width2) / 2" """ saveText = _get_clipboard_text() cutText = _select_and_cut_text(n) if cutText: endSpace = cutText.endswith(' ') cutText = _expand_after_special_chars(cutText) reg = re.compile( r'([a-zA-Z0-9_\"\'\)][=\+\-\*/\%]|[=\+\-\*/\%][a-zA-Z0-9_\"\'\(])') hit = reg.search(cutText) count = 0 while hit and count < 10: cutText = cutText[:hit.start() + 1] + ' ' + \ cutText[hit.end() - 1:] hit = reg.search(cutText) count += 1 newText = cutText if endSpace: newText = newText + ' ' newText = newText.replace("%", "%%") # Escape any format chars. Text(newText).execute() else: # Failed to get text from clipboard. Key('c-v').execute() # Restore cut out text. _set_clipboard_text(saveText)
def output_binding(value_name, is_pointer=False): pointer_suffix = ".*" if is_pointer else "" execute_with_dictation( value_name, lambda n: Text("%s%s = " % (format_value_name(n), pointer_suffix)), lambda n: replace_in_text("$%s = " % pointer_suffix))
def get_symbol(n, sticky): n = int(n) - 1 if n < 0 or n > len(control.nexus().sticky) - 1: return Text(control.nexus().sticky[n]).execute() if not utilities.window_exists(None, settings.S_LIST_VERSION): enable_sticky_list(sticky)
def output_directory_command(directory_name, format_type=None, directory_command=None): if directory_command is not None: Text("%s %s" % (directory_command, format_directory_name(directory_name, format_type))).execute()
class CodeMappings(MappingRule): mapping = {'test code': Text('cd D:GitProjects')} extras = [ Integer('tab', 1, 10), Integer('number', 1, 9999), Dictation("text") ]
class CommandRule(MappingRule): mapping = { #"[go to | show] project window": Key("a-1"), # Search. "replace": Key("c-h"), "show find": Key("c-f"), "find <text>": Key("c-f/25") + Text("%(text)s"), # "find next": Key("f3"), # "find (prev | previous)": Key("s-f3"), "find in files": Key("cs-f"), # Code. "[shoreline | show] line <w> [<x>] [<y>] [<z>]": Key("c-g/25") + Function(printNumber)+ Key("enter"), "show white space": Key("cs-w"), # Window handling. "new tab": Key("c-n"), "next tab [<t>]": Key("c-tab:%(t)d"), "(preev | previous) tab [<t>]": Key("cs-tab:%(t)d"), "close tab": Key("c-w"), "(full-screen | full screen)": Key("f11"), } extras = [ Integer("t", 1, 50), Dictation("text"), IntegerRef("n", 1, 50000), Integer("w", 0, 10), Integer("x", 0, 10), Integer("y", 0, 10), Integer("z", 0, 10) ] defaults = { "t": 1, }
class TerminalRule(MappingRule): exported = True mapping = { "open terminal": Text(":term") + Key("enter"), } extras = [] defaults = {}
def getFile(text=None): open_get_file_dialog = Key("cas-n") if text: open_get_file_dialog.execute() file_name = str(text).lower() Text(file_name).execute() else: open_get_file_dialog.execute()
class MultiMoreKeyMap(MappingRule): mapping = { "wave": Key("shift:up, right"), # "boss": Key("ctrl:down"), # "shun": Key("ctrl:up"), "switch": release + Key("ctrl:down, tab"), "show [all] apps | show [all] Windows": release + Key("alt:down, tab"), "mimic <text>": release + Mimic(extra="text"), "pop": Key("apps"), # right click "focus chrome too": Mimic("focus", "chrome") + Pause("25") + Mimic("focus", "chrome"), # Dragon NaturallySpeaking mimics "list Windows": Mimic("list", "all", "Windows"), "(web search | search web) <text>": Mimic("search", "the", "web", "for", extra="text"), ### programming "short object": Text("obj"), "short string": Text("str"), "jason": Text("json"), ### Dragonfly Commands "add text map": Text("\"\": Text(\"\"),") + Key("left:12"), "add key map": Text("\"\": Key(\"\"),") + Key("left:11"), } extras = [ Integer("n", 1, 50), Integer("tab", 1, 8), Integer("number", 1, 9999), Dictation("text"), ] defaults = { "n": 1, }
def next_line(semi): semi = str(semi) Key("escape").execute() time.sleep(0.25) Key("end").execute() time.sleep(0.25) Text(semi).execute() Key("enter").execute()
def __init__(self, spec=None, static=False, pause=0.02, autofmt=False): Text.__init__(self, spec, static, pause, autofmt)