Esempio n. 1
0
class Decker(MergeRule):
    pronunciation = "test rule"

    mapping = {
        "doon [<nnavi200>]": R(Key("pagedown")) * Repeat(extra="nnavi200"),
    }
    extras = [IntegerRefST("n", 1, 50), IntegerRefST("nnavi200", 1, 200)]
Esempio 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", r"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 = [
        IntegerRefST("n", 1, 1000),
        Dictation("text"),
        Choice("choice", {
            "alarm": "alarm",
            "custom grid": "CustomGrid",
            "element": "e"
        }),
    ]
    defaults = {
        "n": 1,
        "text": "",
    }
Esempio n. 3
0
class NPPRule(MergeRule):
    pronunciation = "notepad plus plus"

    mapping = {
        "(line | zeile) <n>": R(Key("c-g") + Text("%(n)d") + Key("enter")),
        "(save | speichern)": R(Key("c-s")),
        "(save as | speichern als)": R(Key("ca-s")),
    }
    extras = [IntegerRefST("n", 1, 1000)]
    defaults = {"n": 1}
Esempio n. 4
0
class FirefoxRule(MergeRule):
    pronunciation = "fire fox"

    mapping = {
        "(new tab|neuer Tab) [<n>]": R(Key("c-t")) * Repeat(extra="n"),
        "reopen tab [<n>]": R(Key("cs-t")) * Repeat(extra="n"),
        "show history": R(Key("c-h")),
        "show downloads": R(Key("c-j")),
        "show bookmarks": R(Key("c-b")),
        "[add] bookmark": R(Key("c-d")),
        "cancel bookmark":  # Call this after "[add] bookmark" if you want to cancel
        R(Key("a-b")),
        "delete bookmark":  # Call if you are on a page you have bookmarked before
        R(Key("c-d") + Pause("200") + Key("a-e")),
        "full screen": R(Key("f11")),
        "zoom in [<n>]": R(Key("c-plus/20")) * Repeat(extra="n"),
        "zoom out [<n>]": R(Key("c-minus/20")) * Repeat(extra="n"),
        "(leiste | address bar)": R(Key("c-l")),

        # the following commands requires the vim vixen extension
        "(scroll down | runter) [<n>]": R(Key("c-f")) * Repeat(extra="n"),
        "(scroll down | runter) half [<n>]": R(Key("c-d")) * Repeat(extra="n"),
        "(scroll up | hoeher) [<n>]": R(Key("c-b")) * Repeat(extra="n"),
        "(scroll up | hoeher) half [<n>]": R(Key("c-u")) * Repeat(extra="n"),
        "scroll top": R(Key("g") + Key("g")),
        "scroll bottom": R(Key("G")),
        "reload": R(Key("r")),
        "toggle pin": R(Key("z") + Key("p")),
        "(loesche pin | delete pin)": R(Key("!") + Key("d")),
        "(history back|zurueck) [<n>]": R(Key("H")) * Repeat(extra="n"),
        "(history forward|vorwaerts) [<n>]": R(Key("L")) * Repeat(extra="n"),
        "parent [<n>]": R(Key("g") + Key("u")) * Repeat(extra="n"),
        "root": R(Key("g") + Key("U")),
        "link":  # opens in new tab
        R(Key("F")),
        "link here": R(Key("f")),
        "mark <letter>": R(Key("m") + Text("%(letter)s")),
        "jump <letter>": R(Key("'") + Text("%(letter)s")),
        "focus input": R(Text("gi")),
        "copy url":  # copy URL in current tab
        R(Text("y")),
        "clipboard tab":  # open clipboard's URL in current tab
        R(Text("p")),
        "clipboard new tab":  # open clipboard's URL in new tab
        R(Text("P")),
        "toggle":  # enables / disables add on
        R(Key("s-escape")),

        # from nav: next / prior / close tab
    }
    extras = [
        IntegerRefST("n", 1, 100),
        alphanumeric.get_alphabet_choice("letter"),
    ]
    defaults = {"n": 1}
Esempio n. 5
0
class Zahlen(MergeRule):
    pronunciation = "zahlen"

    mapping = {
        "wort ziffer <wn>": R(Function(wort_zahl, extra="wn")),
    }

    extras = [
        IntegerRefST("wn", 0, 10),
    ]
    defaults = {}
Esempio n. 6
0
class Experimental(MappingRule):

    mapping = {
        # experimental/incomplete commands
        "experiment": Function(experiment),
        "short talk number <n2>": Text("%(n2)d"),
        #     "dredge [<id> <text>]":         Function(dredge),
        "test dragonfly paste": Paste("some text"),
    }
    extras = [Dictation("text"), Dictation("text2"), IntegerRefST("n2", 1, 100)]
    defaults = {"text": "", "text2": ""}
Esempio n. 7
0
class Punctuation(MergeRule):
    pronunciation = CCRMerger.CORE[3]

    mapping = {
        "[<long>] <text_punc> [<npunc>]":
        R(Text("%(long)s" + "%(text_punc)s" + "%(long)s")) *
        Repeat(extra="npunc"),
        # For some reason, this one doesn't work through the other function
        "[<long>] backslash [<npunc>]":
        R(Text("%(long)s" + "\\" + "%(long)s")) * Repeat(extra="npunc"),
        "<double_text_punc> [<npunc>]":
        R(Text("%(double_text_punc)s") + Key("left")) * Repeat(extra="npunc"),
        "tabby [<npunc>]":
        R(Key("tab")) * Repeat(extra="npunc"),
        "(back | shin) tabby [<npunc>]":
        R(Key("s-tab")) * Repeat(extra="npunc"),
        "boom [<npunc>]":
        R(Text(", ")) * Repeat(extra="npunc"),
        "bam [<npunc>]":
        R(Text(". ")) * Repeat(extra="npunc"),
        "ace [<npunc100>]":
        R(Text(" ")) * Repeat(extra="npunc100"),
    }

    extras = [
        IntegerRefST("npunc", 0, 10),
        IntegerRefST("npunc100", 0, 100),
        Choice("long", {
            "long": " ",
        }),
        Choice("text_punc", text_punc_dict),
        Choice("double_text_punc", double_text_punc_dict)
    ]
    defaults = {
        "npunc": 1,
        "npunc100": 1,
        "long": "",
    }
Esempio n. 8
0
class IERule(MergeRule):
    pronunciation = "explorer"

    mapping = {
        "get up [<n>]": R(Key("a-up")) * Repeat(extra="n"),
        "get back [<n>]": R(Key("a-left")) * Repeat(extra="n"),
        "get forward [<n>]": R(Key("a-right")) * Repeat(extra="n"),
        "new folder": R(Key("cs-n")),
        "address bar": R(Key("c-l")),
        "search": R(Key("c-l, tab")),
        "left pane": R(Key("c-l, tab:2")),
        "center pane": R(Key("c-l, tab:3")),
        "sort": R(Key("c-l, tab:4")),
    }
    extras = [IntegerRefST("n", 1, 10)]
    defaults = {
        "n": 1,
    }
Esempio n. 9
0
class DragonRule(MergeRule):
    pronunciation = "dragon"

    mapping = {
        "reboot (dragon|caster) (german|deutsch)":
        R(Function(utilities.reboot_Deutsch),
          rdescript="Reboot Dragon Naturallyspeaking"),
        "reboot (dragon|caster) (english|englisch)":
        R(Function(utilities.reboot_Englisch),
          rdescript="Reboot Dragon Naturallyspeaking"),
    }

    extras = [
        Dictation("text"),
        Dictation("mim"),
        IntegerRefST("n", 1, 1000),
    ]
    defaults = {"n": 1, "mim": ""}
Esempio n. 10
0
    def reset(self, mapping):
        grammar = self._grammar  # save reference because Grammar.remove_rule nullifies it
        ccr = self._merger is not None

        if grammar is not None and not ccr:
            grammar.unload()
            grammar.remove_rule(self)

        extras = self.extras if self.extras else [
            IntegerRefST("n", 1, 50), Dictation("s")
        ]
        defaults = self.defaults if self.defaults else {"n": 1, "s": ""}
        MergeRule.__init__(self, self.name, mapping, extras, defaults,
                           self.exported, self.context)

        if ccr: self._merger.merge(MergeInf.SELFMOD)

        if grammar is not None and not ccr:
            grammar.add_rule(self)
            grammar.load()
Esempio n. 11
0
class FileDialogueRule(MergeRule):
    pronunciation = "file dialogue"

    mapping = {
        "get up [<n>]": R(Key("a-up")) * Repeat(extra="n"),
        "get back [<n>]": R(Key("a-left")) * Repeat(extra="n"),
        "get forward [<n>]": R(Key("a-right")) * Repeat(extra="n"),
        "new folder": R(Key("cs-n")),
        "address bar": R(Key("c-l")),
        "search": R(Key("c-l, tab")),
        "left pane": R(Key("c-l, tab:3")),
        "center pane": R(Key("c-l, tab:4")),
        "sort": R(Key("c-l, tab:5")),
        "organize": R(Key("c-l, tab:2")),
        "(dateiname | filename)": R(Key("c-l, tab:6")),
        "(dateityp | file type)": R(Key("c-l, tab:7")),
    }
    extras = [IntegerRefST("n", 1, 10)]
    defaults = {
        "n": 1,
    }
Esempio n. 12
0
class Punctuation(MergeRule):
    pronunciation = CCRMerger.CORE[3]

    mapping = {
        "[<long>] <text_punc> [<npunc>]":
        R(Text("%(long)s" + "%(text_punc)s" + "%(long)s")) *
        Repeat(extra="npunc"),
        # For some reason, this one doesn't work through the other function
        "[<long>] backslash [<npunc>]":
        R(Text("%(long)s" + "\\" + "%(long)s")) * Repeat(extra="npunc"),
    }

    extras = [
        IntegerRefST("npunc", 0, 10),
        Choice("long", {
            "long": " ",
        }),
        Choice("text_punc", text_punc_dict)
    ]
    defaults = {
        "npunc": 1,
        "long": "",
    }
Esempio n. 13
0
class GridControlRule(MergeRule):

    mapping = {
        "<x> [by] <y> [<action>]":
        R(Function(send_input, nexus=_NEXUS),
          rdescript="Douglas Grid: Action"),
        "<x1> [by] <y1> select <x2> [by] <y2>":
        R(Function(send_input_select, nexus=_NEXUS),
          rdescript="Douglas Grid: Select (long version)"),
        "<x1> [by] <y1> select <x2>":
        R(Function(send_input_select_short, nexus=_NEXUS),
          rdescript="Douglas Grid: Select (short version)"),
        "point <point>":
        R(Function(store_point), rdescript="Douglas Grid: Stor point"),
        "select":
        R(Function(select_text, nexus=_NEXUS),
          rdescript="Douglas Grid: Select (point version)"),
        "exit | escape | cancel":
        R(Function(kill, nexus=_NEXUS), rdescript="Douglas Grid: Exit"),
    }
    extras = [
        IntegerRefST("x", 0, 300),
        IntegerRefST("y", 0, 300),
        IntegerRefST("x1", 0, 300),
        IntegerRefST("y1", 0, 300),
        IntegerRefST("x2", 0, 300),
        IntegerRefST("y2", 0, 300),
        Choice("action", {
            "kick": 0,
            "psychic": 1,
            "move": 2,
        }),
        Choice("point", {
            "one": 1,
            "two": 2,
        }),
    ]
    defaults = {
        "action": 0,
    }
Esempio n. 14
0
class GridControlRule(MergeRule):

    mapping = {
        "[<pre>] <color> <n> [<action>]":
        R(Function(send_input, nexus=_NEXUS),
          rdescript="Rainbow Grid: Action"),
        "[<pre1>] <color1> <n1> select [<pre2>] <color2> <n2>":
        R(Function(send_input_select, nexus=_NEXUS),
          rdescript="Rainbow Grid: Select (long version)"),
        "[<pre1>] <color1> <n1> select <n2>":
        R(Function(send_input_select_short, nexus=_NEXUS),
          rdescript="Rainbow Grid: Select (short version)"),
        "point <point>":
        R(Function(store_point), rdescript="Rainbow Grid: Store point"),
        "select":
        R(Function(select_text, nexus=_NEXUS),
          rdescript="Rainbow Grid: Select (point version)"),
        "exit | escape | cancel":
        R(Function(kill, nexus=_NEXUS), rdescript="Rainbow Grid: Exit"),
    }
    extras = [
        IntegerRefST("pre", 0, 9),
        IntegerRefST("pre1", 0, 9),
        IntegerRefST("pre2", 0, 9),
        Choice(
            "color", {
                "(red | rot)": 0,
                "(orange | tan | brown | braun)": 1,
                "(yellow | gelb)": 2,
                "(green | gruen)": 3,
                "(blue | blau)": 4,
                "(purple | lila)": 5
            }),
        Choice(
            "color1", {
                "(red | rot)": 0,
                "(orange | tan | brown | braun)": 1,
                "(yellow | gelb)": 2,
                "(green | gruen)": 3,
                "(blue | blau)": 4,
                "(purple | lila)": 5
            }),
        Choice(
            "color2", {
                "(red | rot)": 0,
                "(orange | tan | brown | braun)": 1,
                "(yellow | gelb)": 2,
                "(green | gruen)": 3,
                "(blue | blau)": 4,
                "(purple | lila)": 5
            }),
        IntegerRefST("n", 0, 100),
        IntegerRefST("n1", 0, 100),
        IntegerRefST("n2", 0, 100),
        Choice("action", {
            "kick": 0,
            "psychic": 1,
            "move": 2,
        }),
        Choice("point", {
            "one": 1,
            "two": 2,
        }),
    ]
    defaults = {
        "pre": 0,
        "pre1": 0,
        "pre2": 0,
        "action": 0,
    }
Esempio n. 15
0
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)),

        # window management
        '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")),

        # 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
    }
Esempio n. 16
0
class GitBashRule(MergeRule):
    pronunciation = "git bash"
    mwith = CCRMerger.CORE
    mapping = {

        # Compare to https://github.com/seekM/docs/blob/master/git.md

        # Basics
        # ======
        "get (initialize|initialisieren)":
        R(Text("git init") + Key("enter")),
        "get (status|zustand)":
        R(Text("git status") + Key("enter")),
        "get (status briefly|zustand kurz)":
        R(Text("git status --short") + Key("enter")),
        "get (append file|datei hinzufuegen)":
        Text("git add "),
        "get (append directory|ordner hinzufuegen)":
        R(Text("git add .") + Key("enter")),
        "get (append all|alle hinzufuegen)":
        R(Text("git add -A") + Key("enter")),
        "get difference file":
        Text("git diff "),
        "get difference":
        R(Text("git diff") + Key("enter")),
        "get difference staged":
        R(Text("git diff --staged") + Key("enter")),
        "get commit":
        R(Text("git commit") + Key("enter")),
        "get commit message":
        R(Text("git commit --message \"\"") + Key("left")),  # message
        "get (remove|entfernen)":
        R(Text("git rm ")),  # file
        "get remove force":
        R(Text("git rm --force ")),  # file
        "get (rename|umbenennen)":
        R(Text("git mv ")),  # file1 file2
        "get unmodify file":
        R(Text("git checkout -- ")),  # file           
        "get (unstage file|datei rueckgaengig)":
        R(Text("git reset HEAD ")),  # file   
        "get reset repository":
        R(Text("git reset --hard") + Key("enter")),
        "get (redo commit|commit wiederholen)":
        R(Text("git commit --amend --message \"\"") +
          Key("left")),  # message         

        # Branches
        # ========
        "get branch":
        R(Text("git branch ")),  # branch
        "get (switch|checkout)":
        R(Text("git checkout ")),  # branch
        "get branch (delete|entfernen)":
        R(Text("git branch --delete ")),  # branch
        "get branch (delete|entfernen) force":
        R(Text("git branch --delete -- force ")),  # branch
        "get branch (combine|kombiniert)":
        R(Text("git checkout -b ")),  # branch
        "get (reset branch|branch zuruecksetzen)":
        R(Text("git reset --hard ")),  # branch

        # Merging
        # =======
        "get (merge|vereinen)":
        R(Text("git merge ")),  # branch
        "get (show merged|zeige vereinigt)":
        R(Text("git branch --merged") + Key("enter")),
        "get (show not merged|zeige nicht vereinigt)":
        R(Text("git branch --no--merged") + Key("enter")),
        "get (logging|aufzeichnung) graph":
        R(Text("git loggraph")),
        "get (logging|aufzeichnung) patch <n>":
        R(Text("git log --patch -%(n)s") + Key("enter")),  # number
        "get (logging|aufzeichnung) statistic":
        R(Text("git log --stat") + Key("enter")),

        # Remotes
        # =======
        "get (clone|kopieren)":
        R(Text("git clone ")),  # url
        "get append remote":
        R(Text("git remote add ")),  # remote_repository(e.g. upstream) url
        "get (show|zeige) remotes":
        R(Text("git remote --verbose") + Key("enter")),
        "get (show|zeige) remote branches":
        R(Text("git branch --remote") + Key("enter")),
        "get fetch remote":
        R(Text("git fetch ")),  # remote_repository
        "get push new branch":
        R(Text("git push --set-upstream ")),  # remote_repository branch
        "get push branch":
        R(Text("git push ")),  # remote_repository branch
        "get (tracking|verfolgungs) branch":
        R(Text("git checkout --branch ")),  # branch remote_repository/branch
        "get (show tracking|zeige verfolgungs) branches":
        R(Text("git branch --verbose --verbose") + Key("enter")),
        "get (delete|entferne) remote branch":
        R(Text("git push  --delete ") +
          Key("left:10")),  # remote_repository branch

        # Rebasing
        # ========
        "get base":
        R(Text("git rebase ")),  # branch              

        # Miscellaneous
        # =============
        "get (stash|versteck)":
        R(Text("git stash save --message \"\"") + Key("left")),
        "get (stash|versteck) include untracked":
        R(
            Text("git stash save --include-untracked --message \"\"") +
            Key("left")),
        "get (stash|versteck) list show":
        R(Text("git stash list") + Key("enter")),

        #"get (stash apply|versteck anwenden) [<n>]":
        #    R(Text("git stash apply stash@{%(n)s}")), # @,{,} don't work at the moment
        #"get (stash apply|versteck anwenden) [<n>] file":
        #    R(Text("git checkout stash@{%(n)s} -- ")), # file # @,{,} don't work at the moment
        #"get (stash|versteck) drop [<n>]":
        #    R(Text("git stash drop stash@{%(n)s}")), # @,{,} don't work at the moment
        "get (stash apply|versteck anwenden)":
        R(Text("git stash apply")),
        "get (dropping stash|versteck verwerfen)":
        R(Text("git stash drop")),
        "get (search|suche)":
        R(Text("git grep --line-number ")),  # searchterm       

        # Other
        # =====
        "CD up":
        R(Text("cd ..") + Key("enter")),
        "CD":
        R(Text("cd ") + Key("enter")),
        "list":
        R(Text("ls") + Key("enter")),
        "make directory":
        R(Text("mkdir ")),
    }
    extras = [
        IntegerRefST("n", 1, 10000),
    ]
    defaults = {"n": 0}
class SublimeRulePlugin(MergeRule):
    pronunciation = "python voice coding plugin"
    mapping = {
        # alternative rule
        "[smart] alternative <alternative_index>":
            lazy_value("alternative",1),
        "smart <color> [alternative]":
            lazy_value("alternative",2),

        # paste back rule
        "[smart] paste back [<paste_back_index>]":
            lazy_value("paste_back",1),
        "[smart] paste <color> back":
            lazy_value("paste_back",2),

        # argument rule
        "[smart] [<adjective>] argument <argument_index>":
            lazy_value("argument",1),
        "[smart] <vertical_direction> [<ndir>] [<adjective>] argument <argument_index>":
            lazy_value("argument",2),
        "[smart] [<adjective>] <level> [<level_index>]  argument <argument_index>": 
            lazy_value("argument",3),
        "[smart] <level> [<level_index>] <adjective> argument <argument_index>": 
            lazy_value("argument",4),

        # big roi rule
        "smart <big_roi> [<big_roi_sub_index>]":
            lazy_value("big_roi",1),
        "[smart] <adjective> <big_roi> [<big_roi_sub_index>]":
            lazy_value("big_roi",2),
        "[smart] <vertical_abstract_only_direction> [<ndir>] <big_roi> [<big_roi_sub_index>]":
            lazy_value("big_roi",3),
        "[smart] <vertical_abstract_only_direction> [<ndir>] <block> [<adjective>] <big_roi> [<big_roi_sub_index>]":
            lazy_value("big_roi",4),

           
        # insert rule
        "(smart insert|insert item) <item_index>":
            lazy_value("insert_item",1),

        # collect rule
        "[smart] collect <collectable>":
            lazy_value("collect_indexable",1),
        "[smart] variable <collect_index>":
            lazy_value("collect_variable",2),
        "[smart] parameter <collect_index>":
            lazy_value("collect_parameter",2),
        "[smart] module <collect_index>":
            lazy_value("collect_module",2),
        "[smart] imported (value|object) <collect_index>":
            lazy_value("collect_imported_value",2),


 
        # banana example
        # "banana [<adjective>] <big_roi> [<big_roi_sub_index>]":
            # lazy_value("big_roi",4,vertical_abstract_only_direction = "above",
                # ndir = 1,block = "function"),
 
    }
    extras = [  
        IntegerRefST("argument_index", 1, 10),  
        IntegerRefST("alternative_index", 1, 10), 
        IntegerRefST("ndir",1,20),
        IntegerRefST("level_index",1,10),                                                                                                                                                       
        IntegerRefST("big_roi_sub_index",0,10), 
        IntegerRefST("paste_back_index",0,10),
        IntegerRefST("collect_index",1,30),
        IntegerRefST("item_index",1,30) ,                                                                                                                                                     
        Choice("adjective",{
                "first" : "first",
                "second": "second",
                "third": "third",
                "fourth": "fourth",
                "fifth": "fifth",
                "sixth": "sixth",
                "seventh": "seventh",
                "eighth": "eighth",
                "ninth":"ninth",
                "last":"last",
                "second last": "second last",
                "third last": "third last",
                "fourth last": "fourth last",
            }
        ) , 
        Choice("vertical_direction",{
                "up":"up",
                "down":"down",
                "above":"above",
                "below":"below",
            }
        ),
        Choice("vertical_abstract_only_direction",{
                "above":"above",
                "below":"below",
            }
        ),
        Choice("color",{
                "red":1,
                "blue":2, 
                "green":3,
                "yellow":4,
                "orange":5,
            }
        ),
        Choice("level",{
                "inside":"inside",
            }
        ),
        Choice("big_roi",{
                "if condition" : "if condition",
                "else if condition" : "else if condition",
                "while condition" : "while condition",
                "if expression condition" : "if expression condition",
                "if expression body" : "if expression body",
                "if expression":"if expression",
                "comprehension condition" : "comprehension condition",
                "return value" : "return value",
                "pass":"******",
                "break" : "break",
                "continue" : "continue",
                "assertion message" : "assertion message",
                "assertion condition" : "assertion condition",
                "(assignment right| right)" : "assignment right",
                "(assignment left| left)" : "assignment left",
                "assignment full" : "assignment full",
                "import statement":"import statement",
                #"(import|imported) (value|item|object|element)":"import value",
                #"module" : "module", 
                "(expression statement|expression)" : "expression statement",
                "iterator" : "iterator",
                "iterable" : "iterable",

            }
        ),
        Choice("block",{
                "(function|functions)" :"function",
            }
        ),
        Choice("collectable",{
                "(variable|variables)":"variable",
                "( parameter | parameters)":"parameter",
                "(module|modules)":"module",
                "(import|imported) (value|item|object|element)":"import value",
                "function ( name |names)":"function name",
            }
        ),

   
    ]
    defaults = {
        "adjective":"None",
        "ndir":1,
        "level_index":1,
        "big_roi_sub_index":0,
        "paste_back_index":0,

    }
Esempio n. 18
0
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>")),
        "divider":
            R(Text("<div>")),
        "span":
            R(Text("<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 _ ")),
        "bravery":
            RegisteredAction(Text("bravery _ ")),
        "charcoal <text> [<n>]":
            R(Text("charcoal _ %(text)s")),
        "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": ""}
class PythonVoiceCodingPluginRule(MergeRule):
    mapping = {
        "[smart] paste [<color>] back [with <surrounding_punctuation>]":
            lazy_value("paste_back",1),
        "[smart] paste <color> on <color2> [<color3> [ [and] <color4>]]":
            lazy_value("paste_back",2), 

        # alternative rule
        "smart alternative <alternative_index>":
            lazy_value("alternative",1),
        "smart <color>":
            lazy_value("alternative",2),
        "smart <color> [<color2> [<color3> [[and] <color4>]]]":
            lazy_value("alternative",3),

        "edit <color> [<color2> [<color3> [[and] <color4>]]]":
            lazy_value("alternative",3,operation = "edit"),

        # delete
        "[smart] delete <color> [<color2> [<color3> [[and] <color4>]]]":
            lazy_value("delete_alternatives",1),
        
        # swap
        "[smart] swap [<color>] back":
            lazy_value("swap_back",1),
        "[smart] swap <color> with <color2>":
            lazy_value("swap_back",2),

        # utilities
        "[smart] back initial":
            lazy_value("select_back",1),
        "smart back":
            lazy_value("select_back",2),
        "smart here":
            lazy_value("remember_here",1),


        # sub indexing rule
        "[(smart|<operation>)] [<nth>] part <sub_index>":
        # "[(smart|<operation>)] [<nth>] inner [<nth2>] part <sub_index>":
            lazy_value("select_part",1),
        "[(smart|<operation>)] [<nth>] part <sub_index> until (<sub_index2>|the end)":
        # "[(smart|<operation>)] [<nth>] inner [<nth2>] part <sub_index> until (<sub_index2>|the end)":
            lazy_value("select_part",2),
        "[(smart|<operation>)] ([<nth>] any|any <nth2>) part [<sub_index>]":
        # "[(smart|<operation>)] [<nth>] any [<nth2>] part [<sub_index>]":
            lazy_value("select_part",3),
        "[(smart|<operation>)] ([<nth>] every|every <nth2>) part [<sub_index>]":
        # "[(smart|<operation>)] [<nth>] every [<nth2>] part [<sub_index>]":
            lazy_value("select_part",4),


        # argument rule
        "[(smart|<operation>)] [<nth>] " + ARGUMENT_LIKE_INFORMATION:
            lazy_value("argument",1),
        "[(smart|<operation>)] <vertical_direction> [<ndir>] [<nth>] " + ARGUMENT_LIKE_INFORMATION:
            lazy_value("argument",2),
        "[(smart|<operation>)] [<nth>] inside [<level_index>] " + ARGUMENT_LIKE_INFORMATION: 
            lazy_value("argument",3),
        "[(smart|<operation>)] inside [<level_index>] <nth> " + ARGUMENT_LIKE_INFORMATION: 
            lazy_value("argument",4),
        "[(smart|<operation>)] outer [<level_index>] [<nth>] " + ARGUMENT_LIKE_INFORMATION: 
            lazy_value("argument",5),

        # big roi rule
        "(smart|<operation>) <big_roi> [<sub_index>]":
            lazy_value("big_roi",1),
        "[(smart|<operation>)] <nth> <big_roi> [<sub_index>]":
            lazy_value("big_roi",2),
        "[(smart|<operation>)] <vertical_direction> [<ndir>] <big_roi> [<sub_index>]":
            lazy_value("big_roi",3),
        "[smart] <vertical_direction> [<ndir>] <block> [<nth>] <big_roi> [<sub_index>]":
            lazy_value("big_roi",4),

           
        # item rule
        "[smart] item <item_index>":
            lazy_value("insert_item",1),
        "[smart] (item|items)  (all| <item_index> until (<item_index2>| the end))":
            lazy_value("insert_item",2),
        "[smart] (item|items) <item_index>   <item_index2> [  and  <item_index3>]":
            lazy_value("insert_item",3),


        # collect rule
        "[smart] collect <collectable>":
            lazy_value("collect_indexable",1),

        # variable rule
        "[smart] variable <item_index>  [[and] <item_index2> [and <item_index3>]]":
            lazy_value("collect_variable",2),
        "[smart] (variables all|variable <item_index> until (<item_index2>| the end))": 
            lazy_value("collect_variable",3),

        # parameter rule
        "[smart] [<vertical_direction> [<ndir>]] parameter <item_index>  [and <item_index2> [and <item_index3>]]":
            lazy_value("collect_parameter",2),
        "[smart] [<vertical_direction> [<ndir>]] (parameters all| parameter <item_index> until (<item_index2>| the end))":
            lazy_value("collect_parameter",3),
        
        # "[smart] [<vertical_direction> [<ndir>]] key parameter <item_index>  [ and <item_index2> [and <item_index3>]]":
            # lazy_value("collect_parameter",2,experimental = "True"),

        # "[smart] [<vertical_direction> [<ndir>]] key (parameters all| parameter <item_index> until (<item_index2>| the end))":
            # lazy_value("collect_parameter",3,experimental = "True"),
        
    }
    extras = [  
        IntegerRefST("argument_index", 0, 10),  
        IntegerRefST("keyword_index", 1, 10),  
        IntegerRefST("entire_keyword_index", 1, 10), 
        IntegerRefST("keyword_value_index", 1, 10), 
        IntegerRefST("alternative_index", 1, 10), 
        IntegerRefST("ndir",1,20),
        IntegerRefST("level_index",1,10),                                                                                                                                                       
        IntegerRefST("paste_back_index",0,10),
        IntegerRefST("collect_index",1,30),
        IntegerRefST("item_index",1,30),  
        IntegerRefST("item_index2",1,30),                                                                                                                                                     
        IntegerRefST("item_index3",1,30),                                                                                                                                                     
        IntegerRefST("item_index4",1,30),
        IntegerRefST("sub_index",1,10),
        IntegerRefST("sub_index2",1,10),                                                                        
        Choice("nth",names["nth_ordinal_adjective"]),
        Choice("nth2",names["nth_ordinal_adjective"]), 
        Choice("vertical_direction",names["vertical_direction"]),
        Choice("color", names["colors"]),
        Choice("color2", names["colors"]),
        Choice("color3", names["colors"]),
        Choice("color4", names["colors"]),
        Choice("big_roi",{

                "if condition" : "if condition",
                "else if condition" : "else if condition",
                "while condition" : "while condition",
                "with item" : "with clause",

                "exception":"exception",
                "exception name":"exception name",
                "handler":"handler",

                "if expression condition" : "if expression condition",
                "if expression value" : "if expression body",
                "if expression":"if expression",
                "if expression else" : "if expression else",

                "comprehension condition" : "comprehension condition",
                "comprehension value" : "comprehension value",

                "return value" : "return value",
                "pass":"******",
                "break" : "break",
                "continue" : "continue",

                "assertion message" : "assertion message",
                "assertion condition" : "assertion condition",
                "exception raised" : "exception raised",
                "raised cause": "raised cause",

                "(assignment right| right)" : "assignment right",
                "(assignment left| left)" : "assignment left",
                "assignment [full]" : "assignment full",
                "(expression statement|expression)" : "expression statement",


                "import statement":"import statement",
                "import value" : "import value",
                "module" : "import module",
                
                

                "iterator" : "iterator",
                "iterable" : "iterable",

                "function name": "definition name",
                "function parameter": "definition parameter",
                "parameter list": "definition parameter list",
                "default value": "default value",
                

                "lambda":"lambda",
                "lambda body":"lambda body",

                
                "class name": "class name",
                "decorator":"decorator",
                "base class":"base class",

#                 "same" : "same",


#                 "string" : "string",
#                 "integer literal" : "integer literal",
#                 "dictionary" : "dictionary",
#                 "list" : "list",
#                 "tuple" : "tuple",
#                 "set" : "set",
                

#                 "subscript" : "subscript",
#                 "subscript body" : "subscript body",
#                 "key" : "key",
#                 "lower" : "lower",
#                 "upper" : "upper",
#                 "step" : "step",
                
#                 "attribute" : "attribute",

#                 "comparison" : "comparison",
#                 "arithmetic" : "arithmetic",
#                 "boolean" : "boolean",

#                 "member": "member",
#                 "container": "container",
#                 "membership" : "membership",

#                 "left side" : "left side",
#                 "right side" : "right side",
#                 "middle" : "middle",

#                 "arithmetic left"  : "arithmetic left" ,
#                 "arithmetic right" : "arithmetic right",
#                 "arithmetic middle" : "arithmetic middle",

#                 "boolean left" : "boolean left",
#                 "boolean right" : "boolean right",
#                 "boolean middle" : "boolean middle",

#                 "boolean and"  : "boolean and" ,
#                 "boolean or" : "boolean or",


            }
        ),
        Choice("block",{
                "(function|functions)" :"function",
            }
        ),
        Choice("collectable",{
                "(variable|variables)":"variable",
                "( parameter | parameters)":"parameter",                
                "imported value":"import value",
                "module" : "module",
                "function (name|names)":"function name",
                "class name" : "class name",
                "decorator" : "decorator",
            }
        ),
        Choice("surrounding_punctuation",{
                "quotes":    ("quotes","quotes"),
                "thin quotes": ("'","'"),
                "tickris":   ("`","`"),
                "prekris":     ("(",")"),
                "brax":        ("[","]"),
                "curly":       ("{","}"),
                "angle":     ("<",">"),
                "dot":(".","."),
                "underscore": ("_","_"),
                "(comma|,)": (",",","),
                "ace":(" "," "),
                # "truth comprehension":"$$ = [x  for x in $$ if x]",
                # "force list": "$$ if isinstance($$,list) else [$$] ",
                # "truth": "$$ = $$ if $$ else ",
                # "key value":"quotes$$quotes:$$",
            }
        ),
        Choice("operation",{
                "paste": "paste",
                "delete":"delete",
                "swap": "swap",
                "edit": "edit",
            }
        ),
        Choice("caller",{
            "caller": "caller",
            }
        ),
   
    ]
    defaults = {
        "ndir":1,
        "level_index":0,

    }