Ejemplo n.º 1
0
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": ""}
Ejemplo n.º 2
0
class MainRule(MappingRule):

    mapping = {
        # it is this section that you want to fiddle around with if you're new: mapping, extras, and defaults

        # in the next line, there are two things to observe:
        # the first is the use of parentheses and the pipe symbol (|)
        # --this lets me use either "lock dragon" or "deactivate" to trigger that command.
        # The next is the playback action, which lets me tell Dragon to simulate me speaking some words.
        '(lock Dragon | deactivate)':
        Playback([(["go", "to", "sleep"], 0.0)]),

        # Here I'm using BringApp-- this is the same as typing what goes in between the parentheses
        # into the Windows command prompt, without the quotes and commas, like:
        # explorer C:\NatLink\NatLink\MacroSystem
        # -- (which would open Windows Explorer at the specified location). Anything you can do with the command line can be done this way
        # IMPORTANT: If you don't have Dragonfly  6.6  or later, lines 40 and 46  will cause this file to crash and should be commented out
        "open natlink folder":
        BringApp("explorer", "C:\NatLink\NatLink\MacroSystem"),

        # here I'm using the Key action to press some keys -- see the documentation here: http://dragonfly.readthedocs.org/en/latest/actions.html?highlight=key#module-dragonfly.actions.action_key
        "remax":
        Key("a-space/10,r/10,a-space/10,x"),

        # here I'm chaining a bunch of different actions together to do a complex task
        "(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('http://dragonfly.readthedocs.org/en/latest') + Key('enter'),

        # here I'm just saying one word to trigger some other words
        "hotel":
        Text("hotels are not cheap"),

        # If you need to do more complicated tasks, or use external resources, a function might be what you need.
        # note that here, I'm using extras: "n" and "text"
        # The angle brackets <> meaning I'm using an extra, and the square brackets [] mean that I don't have to speak that word, it's optional.
        # Advice: if you use an optional extra, like I am with "text", you should set a default value  in the defaults section down below.
        # To trigger the following command, you would have to say the word "function" followed by a number between 1 and 1000.
        '[use] function <n> [<text>]':
        Function(my_function, extra={'n', 'text'}),
    }
    extras = [
        IntegerRef("n", 1, 1000),
        Dictation("text"),
        Choice("choice", {
            "alarm": "alarm",
            "custom grid": "CustomGrid",
            "element": "e"
        }),
    ]
    defaults = {
        "n": 1,
        "text": "",
    }
Ejemplo n.º 3
0
def launch(hmc_type, data=None):
    from dragonfly import (WaitWindow, FocusWindow, Key)
    instructions = _get_instructions(hmc_type)
    if data is not None:  # and callback!=None:
        instructions.append(data)
    Popen(instructions)

    hmc_title = _get_title(hmc_type)
    WaitWindow(title=hmc_title, timeout=5).execute()
    FocusWindow(title=hmc_title).execute()
    Key("tab").execute()
Ejemplo n.º 4
0
def launch(hmc_type, callback, data=None):
    from dragonfly import (WaitWindow, FocusWindow, Key)
    instructions = _get_instructions(hmc_type)
    if data != None:
        instructions.append(data)
    Popen(instructions)

    hmc_title = _get_title(hmc_type)
    WaitWindow(title=hmc_title, timeout=5).execute()
    FocusWindow(title=hmc_title).execute()
    Key("tab").execute()

    from caster.asynch.hmc import squeue
    squeue.add_query(callback)
Ejemplo n.º 5
0
def closeProgram(name):
    (FocusWindow(title=name) + WaitWindow(title=name) + Key('a-f4')).execute()
Ejemplo n.º 6
0
class DragonRule(MappingRule):
    mapping = {
        '(number|numbers) mode':
        R(Playback([(["numbers", "mode", "on"], 0.0)])),
        'spell mode':
        R(Playback([(["spell", "mode", "on"], 0.0)])),
        'dictation mode':
        R(Playback([(["dictation", "mode", "on"], 0.0)])),
        'normal mode':
        R(Playback([(["normal", "mode", "on"], 0.0)])),
        '(command mode | command on | com on)':
        R(Playback([(["command", "mode", "on"], 0.0)])),
        '(command off | com off)':
        R(Playback([(["command", "mode", "off"], 0.0)])),
        "fix dragon double":
        R(Function(fix_dragon_double)),
        "left point":
        R(
            Playback([(["MouseGrid"], 0.1), (["four", "four"], 0.1),
                      (["click"], 0.0)])),
        "right point":
        R(
            Playback([(["MouseGrid"], 0.1), (["six", "six"], 0.1),
                      (["click"], 0.0)])),
        "center point":
        R(Playback([(["MouseGrid"], 0.1), (["click"], 0.0)]),
          rdescript="Mouse: Center Point"),
        "show windows":
        R(Mimic("list", "all", "windows"),
          rdescript="Dragon: emulate Dragon command for listing windows"),
        "cory <text>":
        R(Mimic("correct", extra="text") +
          WaitWindow(title="spelling window") + Mimic("choose", "one"),
          rdescript=
          "Dragon: brings up the correction menu for the phrase spoken in the command and chooses the 1st choice"
          ),
        "cory that":
        R(Mimic("correct", "that") + WaitWindow(title="spelling window") +
          Mimic("choose", "one"),
          rdescript=
          "Dragon: brings up the correction menu for the previously spoken phrase and chooses the first choice"
          ),
        "make that <text>":
        R(Mimic("scratch", "that") + Mimic(extra="text"),
          rdescript=
          "Dragon: deletes the dictation generated by the previous utterance and replaces it with what you say next"
          ),
        "scratch [<n10>]":
        R(Playback([(["scratch", "that"], 0.03)]),
          rdescript="Dragon: delete dictation from previous n utterances") *
        Repeat(extra="n10"),

        # Users may want to adjust the wait time on the next few commands
        "train word":
        R(Mimic("train", "that") + Pause("75") + Key("a-r/250, s"),
          rdescript=
          "Dragon: quickly train word when you have it selected in a Dragon friendly text field"
          ),
        "word train":
        R(Key("c-c/20") + Mimic("edit", "vocabulary") +
          Key("c-v/5, tab, down, up, a-t/50, enter/50, a-r/250, s/50, escape"),
          rdescript=
          "train word quickly once you have it selected in non-full text control application"
          ),
        "(add train | train from add word)":
        R(Key("a-a/2, enter/300, a-s"),
          rdescript="Dragon: quickly train word from the add word dialogbox"),
        "(train from vocab | cab train)":
        R(Key("a-t/50, enter/50, a-r/250, s"),
          rdescript="Dragon: quickly train word from Vocabulary Editor"),
        "(train from vocab | cab train)":
        R(Key("a-t/50, enter/50, a-r/250, s"),
          rdescript="Dragon: quickly train word from Vocabulary Editor"),
        "remove from vocab":
        R(Key("c-c/5") + Mimic("edit", "vocabulary") + Pause("20") +
          Key("c-v/10, tab, down, up/5, a-d, y, escape/30, right"),
          rdescript="Dragon: remove selected word from vocabulary"),
        "(add to vocab | vocab that)":
        R(Key("c-c/5") + Mimic("add", "word") + Pause("20") +
          Key("c-v, a-a/2, enter/300, a-s/30, right"),
          rdescript="Dragon: add selected word to vocabulary and train it"),
        "recognition history":
        R(Playback([(["view", "recognition", "history"], 0.03)]),
          rdescript="Dragon: open Dragon recognition history"),
        "peak [recognition] history":
        R(Playback([(["view", "recognition", "history"], 0.03)]) +
          Pause("300") + Key("escape"),
          rdescript="Dragon: open Dragon recognition history then close it"),
        "[dictation] sources":
        R(Mimic("manage", "dictation", "sources"),
          rdescript="Dragon: manage dictation sources"),
    }
    # see above
    extras = extras_for_whole_file()
    defaults = defaults_for_whole_file()
 def _execute(self, data=None):
     StartApp(*self.args).execute()
     WaitWindow(None, os.path.basename(self.args[0]), 3).execute()
Ejemplo n.º 8
0
class MyRule(MappingRule):

    # It is this section that you want to edit if you're new. The mapping, extras, and defaults
    mapping = {

        # Here I'm just saying two words to trigger some other words
        "hotel info":
        Text("These types of hospitality services are not cheap."),

        # In the next line, there are two things to observe:
        # the first is the use of parentheses and the pipe symbol (|)
        # --this lets me use either "motel" or "lodging" to trigger that command.
        # The next is the playback action, which lets me tell the speech recognition engine to simulate me speaking some words.
        "(motel | lodging)":
        Playback([(["hotel", "info"], 0.0)]),

        # Here I'm using BringApp -- this is the same as typing what goes in between the parentheses
        # into the command prompt/terminal, without the quotes and commas, like:
        # Windows OS: explorer C:\NatLink\NatLink\MacroSystem
        # Could be changed changed for Linux/Mac
        # -- (which would open Windows Explorer at the specified location). Anything you can do with the command line can be done this way
        "open natlink folder":
        BringApp("explorer", r"C:\NatLink\NatLink\MacroSystem"),

        # Here I'm using the Key action to press some keys -- see the documentation here: https://dragonfly2.readthedocs.io/en/latest/actions.html?#module-dragonfly.actions.action_key
        # "a-" Everything before "-" is a keyboard modifier, "a" is for the "alt" Key.
        # "-space" reprresents the SpaceBar Key.
        # "/10" After "a-space" Slows down the keypresses by 10 ms" with a seriess of keypresses as demonstrated this may be necessary.
        # The comma "," after "a-space/10" separates keypresses in a series.
        "remax":
        Key("a-space/10,r/10,a-space/10,x"),

        # Here I'm chaining a bunch of different actions together to do a complex task
        # This is Windows OS speciffic but the path in BringApp could be changed for Linux/Mac
        "(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'),

        # If you need to do more complicated tasks, or use external resources, a function might be what you need.
        # Note that here, I'm using extras: "n" and "text"
        # The angle brackets <> meaning I'm using an extra, and the square brackets [] mean that I don't have to speak that word, it's optional.
        # Advice: if you use an optional extra, like I am with "text", you should set a default value  in the defaults section down below.
        # To trigger the following command, you would have to say the word "function" followed by a number between 1 and 1000.
        '[use] function <n> [<text>]':
        Function(my_function, extra={'n', 'text'}),

        # Sometimes it's easier to have things as a list in a command as a choice that do different things.
        # That's what `<choice>` Is defined in `extras` allows you define that list. If you dictate `i choose custom grid` Then `CustomGrid` will be printed as text.
        # Items in the list are pairs. e.g `{"custom grid": "CustomGrid"}` The first item of a pair is the command "custom grid" and the second "CustomGrid" output text action.
        "i choose <choice>":
        Text("%(choice)s"),
    }

    extras = [
        IntegerRef("n", 1, 1000),
        Dictation("text"),
        Choice("choice", {
            "alarm": "alarm",
            "custom grid": "CustomGrid",
            "element": "e"
        }),
    ]
    defaults = {
        "n": 1,
        "text": "",
    }
Ejemplo n.º 9
0
class DevRule(MappingRule):

    mapping = {
        # 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":
        Function(bring_test) + FocusWindow("explorer"),
        "reserved word <text>":
        Key("dquote,dquote,left") + Text("%(text)s") +
        Key("right, colon, tab/5:5") + Text("Text(\"%(text)s\"),"),
        "refresh ccr directory":
        Function(ccr.refresh_from_files
                 ),  # will need to disable and reenable language
        "Agrippa <filetype> <path>":
        Function(grep_this),

        # experimental/incomplete commands
        "zone test":
        R(Text("a") + Text("b")),
        "experiment <text>":
        Function(experiment),
        #
        #     "dredge [<id> <text>]":         Function(dredge),
        "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] ")))
        ]),
        "never-ending":
        AsynchronousAction([
            L(S(["ashes", "charcoal"], print_time, None),
              S(["bravery"], Text, "bravery1"))
        ],
                           time_in_seconds=0.2,
                           repetitions=20,
                           finisher=Text("finisher successful")),
        "ashes":
        RegisteredAction(Text("ashes fall "), rspec="ashes"),
        "bravery":
        RegisteredAction(Text("bravery is weak "), rspec="bravery"),
        "charcoal boy <text> [<n>]":
        R(Text("charcoal is dirty %(text)s"), rspec="charcoal"),
        "test confirm action":
        ConfirmAction(Key("a"), rdescript="Confirm Action Test"),
        "convert node <n>":
        R(Key("cs-right, cs-right/5:%(n)d, cs-right, c-x, c-v, comma") +
          Text("Text()") + Key("left, c-v"),
          rdescript="Convert Node"),
        "text action":
        R(Text("Text()") + Key("left"), rdescript="Node 2"),
        "long conversion <text>":
        R(Key("c-x") + Text("\"%(text)s\", Text(") + Key("c-v, rparen"),
          rdescript="Node 3"),
    }
    extras = [
        Dictation("text"),
        Dictation("textnv"),
        IntegerRef("n", 1, 5),
        Choice("id", {
            "R": 1,
            "M": 2,
        }),
        Choice("path", {
            "natlink": "c:/natlink/natlink",
            "sea": "C:/",
        }),
        Choice("filetype", {
            "java": "*.java",
            "python": "*.py",
        }),
    ]
    defaults = {"text": "", "id": None}