Esempio n. 1
0
    def find(self, back, go, text=None, punctuation=None, a=None, b=None, c=None):
        '''set direction'''

        key = "b" if back else "o"
        Key("a-" + key).execute()
        '''figure out what to search for'''
        if text is not None:
            text = str(text)
            '''simple vowel-removal regex'''
            if self.regex:
                text = re.sub("[aeiouAEIOU]+", r".*", text)
                if text.endswith(r".*"):
                    text = text[:-2]
        elif punctuation is not None:
            text = str(punctuation)
            self.regex_off()
        elif a is not None:
            a = str(a)
            b = str(b) if b is not None else ""
            c = str(c) if c is not None else ""
            text = a + b + c
            self.regex_off()
        Text(text).execute()
        '''"go" indicates that we should keep looking'''
        if go:
            u = UntilCancelled(Key("enter"), 2)
            u.show = False
            u.execute()
        else:
            Key("enter, escape").execute()
Esempio n. 2
0
class Navigation(MergeRule):
    pronunciation = "navigation"

    mapping = {
        # "periodic" repeats whatever comes next at 1-second intervals until "terminate"
        # or "escape" (or your SymbolSpecs.CANCEL) is spoken or 100 tries occur
        "periodic":
        ContextSeeker(forward=[
            L(
                S(["cancel"], lambda: None),
                S(["*"],
                  lambda fnparams: UntilCancelled(
                      Mimic(*filter(lambda s: s != "periodic", fnparams)), 1).
                  execute(),
                  use_spoken=True))
        ]),
        # VoiceCoder-inspired -- these should be done at the IDE level
        "fill <target>":
        R(Key("escape, escape, end"), show=False) + AsynchronousAction(
            [L(S(["cancel"], Function(context.fill_within_line)))],
            time_in_seconds=0.2,
            repetitions=50),
        "jump in":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["right", "(~[~{~<"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump out":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["right", ")~]~}~>"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump back":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump back in":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))],
            finisher=Key("right"),
            time_in_seconds=0.1,
            repetitions=50),

        # keyboard shortcuts
        'save':
        R(Key("c-s"), rspec="save"),
        "shift click":
        R(Key("shift:down") + Mouse("left") + Key("shift:up")),
        "stoosh [<nnavi500>]":
        R(Function(navigation.stoosh_keep_clipboard), rspec="stoosh"),
        "cut [<nnavi500>]":
        R(Function(navigation.cut_keep_clipboard), rspec="cut"),
        "spark [<nnavi500>] [(<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)]]":
        R(Function(navigation.drop_keep_clipboard), rspec="spark"),
        "splat [<splatdir>] [<nnavi10>]":
        R(Key("c-%(splatdir)s"), rspec="splat") * Repeat(extra="nnavi10"),
        SymbolSpecs.CANCEL:
        R(Key("escape"), rspec="cancel"),
        "shackle":
        R(Key("home/5, s-end"), rspec="shackle"),
        "(tell | tau) <semi>":
        R(Function(navigation.next_line), rspec="tell dock"),
        "(hark | heart) <semi>":
        R(Function(navigation.previous_line), rspec="hark dock"),
        "duple [<nnavi50>]":
        R(Function(navigation.duple_keep_clipboard), rspec="duple"),
        "Kraken":
        R(Key("c-space"), rspec="Kraken"),
        "undo [<nnavi10>]":
        R(Key("c-z")) * Repeat(extra="nnavi10"),
        "redo [<nnavi10>]":
        R(
            ContextAction(
                default=Key("c-y") * Repeat(extra="nnavi10"),
                actions=[
                    (AppContext(executable=["rstudio", "foxitreader"]),
                     Key("cs-z") * Repeat(extra="nnavi10")),
                ])),

        # text formatting
        "set [<big>] format (<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)]":
        R(Function(textformat.set_text_format)),
        "clear castervoice [<big>] formatting":
        R(Function(textformat.clear_text_format)),
        "peek [<big>] format":
        R(Function(textformat.peek_text_format)),
        "(<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)] <textnv> [brunt]":
        R(Function(textformat.master_format_text)),
        "[<big>] format <textnv>":
        R(Function(textformat.prior_text_format)),
        "<word_limit> [<big>] format <textnv>":
        R(Function(textformat.partial_format_text)),
        "hug <enclosure>":
        R(Function(text_utils.enclose_selected)),
        "dredge [<nnavi10>]":
        R(Key("alt:down, tab/20:%(nnavi10)d, alt:up"),
          rdescript="Core: switch to most recent Windows"),

        # Ccr Mouse Commands
        "kick [<nnavi3>]":
        R(Function(navigation.left_click)) * Repeat(extra="nnavi3"),
        "psychic":
        R(Function(navigation.right_click)),
        "(kick double|double kick)":
        R(Function(navigation.left_click) * Repeat(2)),
        "squat":
        R(Function(navigation.left_down)),
        "bench":
        R(Function(navigation.left_up)),

        # special keystroke commands
        "(lease wally | latch) [<nnavi10>]":
        R(Key("home:%(nnavi10)s")),
        "(ross wally | ratch) [<nnavi10>]":
        R(Key("end:%(nnavi10)s")),
        "sauce wally [<nnavi10>]":
        R(Key("c-home:%(nnavi10)s")),
        "dunce wally [<nnavi10>]":
        R(Key("c-end:%(nnavi10)s")),
        "bird [<nnavi500>]":
        R(Key("c-left:%(nnavi500)s")),
        "firch [<nnavi500>]":
        R(Key("c-right:%(nnavi500)s")),
        "brick [<nnavi500>]":
        R(Key("s-left:%(nnavi500)s")),
        "frick [<nnavi500>]":
        R(Key("s-right:%(nnavi500)s")),
        "blitch [<nnavi500>]":
        R(Key("cs-left:%(nnavi500)s")),
        "flitch [<nnavi500>]":
        R(Key("cs-right:%(nnavi500)s")),
        "<button_dictionary_500_no_prefix_no_modifier> [<nnavi500>]":
        R(Key("%(button_dictionary_500_no_prefix_no_modifier)s") *
          Repeat(extra='nnavi500'),
          rdescript=
          "press buttons from button_dictionary_500_no_prefix_no_modifier"),
        "<modifier> <button_dictionary_500_modifier> [<nnavi500>]":
        R(Key("%(modifier)s-%(button_dictionary_500_modifier)s") *
          Repeat(extra='nnavi500'),
          rdescript=
          "press modifiers plus buttons from button_dictionary_500_modifier"),
        "<modifier> <button_dictionary_1_modifier>":
        R(Key("%(modifier)s-%(button_dictionary_1_modifier)s"),
          rdescript=
          "press modifiers plus buttons from button_dictionary_1_modifier"),
    }

    tell_commands_dict = {
        "dock": ";",
        "doc": ";",
        "sink": "",
        "com": ",",
        "deck": ":"
    }
    tell_commands_dict.update(_tpd)
    button_dictionary_500_no_prefix_no_modifier = {
        "tabby": "tab",
        "clear": "backspace",
        "deli": "del",
        "shock": "enter",
        "lease": "left",
        "ross": "right",
        "sauce": "up",
        "dunce": "down",
        "page (down | dunce)": "pgdown",
        "page (up | sauce)": "pgup",
    }
    button_dictionary_500_modifier = {
        key: value
        for key, value in keyboard_support.button_dictionary_1.items()
        if value in [
            "backspace", "del", "enter", "left", "right", "up", "down",
            "pgdown", "pgup"
        ]
    }
    button_dictionary_1_modifier = {
        key: value
        for key, value in keyboard_support.button_dictionary_1.items()
        if value in ["home", "end"]
    }
    extras = [
        ShortIntegerRef("nnavi10", 1, 11),
        ShortIntegerRef("nnavi3", 1, 4),
        ShortIntegerRef("nnavi50", 1, 50),
        ShortIntegerRef("nnavi500", 1, 500),
        Dictation("textnv"),
        Choice("enclosure", _dtpd),
        Choice(
            "capitalization", {
                "yell": 1,
                "tie": 2,
                "gerrish": 3,
                "sing": 4,
                "laws": 5,
                "say": 6,
                "cop": 7,
                "slip": 8,
            }),
        Choice(
            "spacing", {
                "gum": 1,
                "gun": 1,
                "spine": 2,
                "snake": 3,
                "pebble": 4,
                "incline": 5,
                "dissent": 6,
                "descent": 6,
            }),
        Choice("semi", tell_commands_dict),
        Choice("word_limit", {
            "single": 1,
            "double": 2,
            "triple": 3,
            "Quadra": 4
        }), navigation_support.TARGET_CHOICE,
        Choice("extreme", {
            "Wally": "way",
        }),
        Choice("big", {
            "big": True,
        }),
        Choice("splatdir", {
            "lease": "backspace",
            "ross": "delete",
        }), keyboard_support.modifier_choice_object,
        Choice("button_dictionary_500_no_prefix_no_modifier",
               button_dictionary_500_no_prefix_no_modifier),
        Choice("button_dictionary_500_modifier",
               button_dictionary_500_modifier),
        Choice("button_dictionary_1_modifier", button_dictionary_1_modifier)
    ]

    defaults = {
        "nnavi500": 1,
        "nnavi50": 1,
        "nnavi10": 1,
        "nnavi3": 1,
        "textnv": "",
        "capitalization": 0,
        "spacing": 0,
        "extreme": None,
        "big": False,
        "splatdir": "backspace",
    }
Esempio n. 3
0
class Navigation(MergeRule):
    pronunciation = "navigation"

    mapping = {
        # "periodic" repeats whatever comes next at 1-second intervals until "terminate"
        # or "escape" (or your SymbolSpecs.CANCEL) is spoken or 100 tries occur
        "periodic":
        ContextSeeker(forward=[
            L(
                S(["cancel"], lambda: None),
                S(["*"],
                  lambda fnparams: UntilCancelled(
                      Mimic(*filter(lambda s: s != "periodic", fnparams)), 1).
                  execute(),
                  use_spoken=True))
        ]),
        # VoiceCoder-inspired -- these should be done at the IDE level
        "fill <target>":
        R(Key("escape, escape, end"), show=False) + AsynchronousAction(
            [L(S(["cancel"], Function(context.fill_within_line)))],
            time_in_seconds=0.2,
            repetitions=50),
        "jump in":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["right", "(~[~{~<"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump out":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["right", ")~]~}~>"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump back":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))],
            time_in_seconds=0.1,
            repetitions=50),
        "jump back in":
        AsynchronousAction(
            [L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))],
            finisher=Key("right"),
            time_in_seconds=0.1,
            repetitions=50),

        # keyboard shortcuts
        'save':
        R(Key("c-s"), rspec="save"),
        'shock [<nnavi50>]':
        R(Key("enter"), rspec="shock") * Repeat(extra="nnavi50"),
        # "(<mtn_dir> | <mtn_mode> [<mtn_dir>]) [(<nnavi500> | <extreme>)]":
        #     R(Function(text_utils.master_text_nav)), # this is now implemented below
        "shift click":
        R(Key("shift:down") + Mouse("left") + Key("shift:up")),
        "stoosh [<nnavi500>]":
        R(Function(navigation.stoosh_keep_clipboard), rspec="stoosh"),
        "cut [<nnavi500>]":
        R(Function(navigation.cut_keep_clipboard), rspec="cut"),
        "spark [<nnavi500>] [(<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)]]":
        R(Function(navigation.drop_keep_clipboard), rspec="spark"),
        "splat [<splatdir>] [<nnavi10>]":
        R(Key("c-%(splatdir)s"), rspec="splat") * Repeat(extra="nnavi10"),
        "deli [<nnavi50>]":
        R(Key("del/5"), rspec="deli") * Repeat(extra="nnavi50"),
        "clear [<nnavi50>]":
        R(Key("backspace/5:%(nnavi50)d"), rspec="clear"),
        SymbolSpecs.CANCEL:
        R(Key("escape"), rspec="cancel"),
        "shackle":
        R(Key("home/5, s-end"), rspec="shackle"),
        "(tell | tau) <semi>":
        R(Function(navigation.next_line), rspec="tell dock"),
        "duple [<nnavi50>]":
        R(Function(navigation.duple_keep_clipboard), rspec="duple"),
        "Kraken":
        R(Key("c-space"), rspec="Kraken"),
        "undo [<nnavi10>]":
        R(Key("c-z")) * Repeat(extra="nnavi10"),
        "redo [<nnavi10>]":
        R(
            ContextAction(
                default=Key("c-y") * Repeat(extra="nnavi10"),
                actions=[
                    (AppContext(executable=["rstudio", "foxitreader"]),
                     Key("cs-z") * Repeat(extra="nnavi10")),
                ])),

        # text formatting
        "set [<big>] format (<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)]":
        R(Function(textformat.set_text_format)),
        "clear castervoice [<big>] formatting":
        R(Function(textformat.clear_text_format)),
        "peek [<big>] format":
        R(Function(textformat.peek_text_format)),
        "(<capitalization> <spacing> | <capitalization> | <spacing>) [(bow|bowel)] <textnv> [brunt]":
        R(Function(textformat.master_format_text)),
        "[<big>] format <textnv>":
        R(Function(textformat.prior_text_format)),
        "<word_limit> [<big>] format <textnv>":
        R(Function(textformat.partial_format_text)),
        "hug <enclosure>":
        R(Function(text_utils.enclose_selected)),
        "dredge [<nnavi10>]":
        R(Key("alt:down, tab/20:%(nnavi10)d, alt:up"),
          rdescript="Core: switch to most recent Windows"),

        # Ccr Mouse Commands
        "kick [<nnavi3>]":
        R(Function(navigation.left_click)) * Repeat(extra="nnavi3"),
        "psychic":
        R(Function(navigation.right_click)),
        "(kick double|double kick)":
        R(Function(navigation.left_click) * Repeat(2)),
        "squat":
        R(Function(navigation.left_down)),
        "bench":
        R(Function(navigation.left_up)),

        # keystroke commands
        "<direction> [<nnavi500>]":
        R(Key("%(direction)s") * Repeat(extra='nnavi500'),
          rdescript="arrow keys"),
        "(lease wally | latch) [<nnavi10>]":
        R(Key("home:%(nnavi10)s")),
        "(ross wally | ratch) [<nnavi10>]":
        R(Key("end:%(nnavi10)s")),
        "sauce wally [<nnavi10>]":
        R(Key("c-home:%(nnavi10)s")),
        "dunce wally [<nnavi10>]":
        R(Key("c-end:%(nnavi10)s")),
        "bird [<nnavi500>]":
        R(Key("c-left:%(nnavi500)s")),
        "firch [<nnavi500>]":
        R(Key("c-right:%(nnavi500)s")),
        "brick [<nnavi500>]":
        R(Key("s-left:%(nnavi500)s")),
        "frick [<nnavi500>]":
        R(Key("s-right:%(nnavi500)s")),
        "blitch [<nnavi500>]":
        R(Key("cs-left:%(nnavi500)s")),
        "flitch [<nnavi500>]":
        R(Key("cs-right:%(nnavi500)s")),
        "<modifier> <button_dictionary_500> [<nnavi500>]":
        R(Key("%(modifier)s%(button_dictionary_500)s") *
          Repeat(extra='nnavi500'),
          rdescript=
          "press modifier keys plus buttons from button_dictionary_500"),
        "<modifier> <button_dictionary_10> [<nnavi10>]":
        R(Key("%(modifier)s%(button_dictionary_10)s") *
          Repeat(extra='nnavi10'),
          rdescript="press modifier keys plus buttons from button_dictionary_10"
          ),
        "<modifier> <button_dictionary_1>":
        R(Key("%(modifier)s%(button_dictionary_1)s"),
          rdescript=
          "press modifiers plus buttons from button_dictionary_1, non-repeatable"
          ),

        # "key stroke [<modifier>] <combined_button_dictionary>":
        #     R(Text('Key("%(modifier)s%(combined_button_dictionary)s")')),

        # "key stroke [<modifier>] <combined_button_dictionary>":
        #     R(Text('Key("%(modifier)s%(combined_button_dictionary)s")')),
    }
    tell_commands_dict = {
        "dock": ";",
        "doc": ";",
        "sink": "",
        "com": ",",
        "deck": ":"
    }
    tell_commands_dict.update(_tpd)

    # I tried to limit which things get repeated how many times in hopes that it will help prevent the bad grammar error
    # this could definitely be changed. perhaps some of these should be made non-CCR
    button_dictionary_500 = {
        "(tab | tabby)": "tab",
        "(backspace | clear)": "backspace",
        "(delete|deli)": "del",
        "(escape | cancel)": "escape",
        "(enter | shock)": "enter",
        "(left | lease)": "left",
        "(right | ross)": "right",
        "(up | sauce)": "up",
        "(down | dunce)": "down",
        "page (down | dunce)": "pgdown",
        "page (up | sauce)": "pgup",
        "space": "space"
    }
    button_dictionary_10 = {
        "(F{}".format(i) + " | function {})".format(i): "f{}".format(i)
        for i in range(1, 13)
    }
    button_dictionary_10.update(caster_alphabet())
    button_dictionary_10.update(_tpd)
    longhand_punctuation_names = {
        "minus": "hyphen",
        "hyphen": "hyphen",
        "comma": "comma",
        "deckle": "colon",
        "colon": "colon",
        "slash": "slash",
        "backslash": "backslash"
    }
    button_dictionary_10.update(longhand_punctuation_names)
    button_dictionary_1 = {
        "(home | lease wally | latch)": "home",
        "(end | ross wally | ratch)": "end",
        "insert": "insert",
        "zero": "0",
        "one": "1",
        "two": "2",
        "three": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9"
    }
    combined_button_dictionary = {}
    for dictionary in [
            button_dictionary_1, button_dictionary_10, button_dictionary_500
    ]:
        combined_button_dictionary.update(dictionary)

    modifier_choice_object = Choice(
        "modifier",
        {
            "(control | fly)": "c-",  #TODO: make DRY
            "(shift | shin)": "s-",
            "alt": "a-",
            "(control shift | que)": "cs-",
            "control alt": "ca-",
            "(shift alt | alt shift)": "sa-",
            "(control alt shift | control shift alt)":
            "csa-",  # control must go first
            "windows": "w-",  # windows should go before alt/shift
            "control windows": "cw-",
            "control windows alt": "cwa-",
            "control windows shift": "cws-",
            "windows shift alt": "wsa-",
            "windows alt shift": "was-",
            "windows shift": "ws-",
            "windows alt": "wa-",
            "control windows alt shift": "cwas-",
            "hit": "",
        })
    extras = [
        IntegerRefST("nnavi10", 1, 11),
        IntegerRefST("nnavi3", 1, 4),
        IntegerRefST("nnavi50", 1, 50),
        IntegerRefST("nnavi500", 1, 500),
        Dictation("textnv"),
        Choice("enclosure", _dtpd),
        Choice("direction", {
            "dunce": "down",
            "sauce": "up",
            "lease": "left",
            "ross": "right",
        }),
        modifier_choice_object,
        Choice("button_dictionary_1", button_dictionary_1),
        Choice("button_dictionary_10", button_dictionary_10),
        Choice("button_dictionary_500", button_dictionary_500),
        Choice("combined_button_dictionary", combined_button_dictionary),
        Choice(
            "capitalization", {
                "yell": 1,
                "tie": 2,
                "gerrish": 3,
                "sing": 4,
                "laws": 5,
                "say": 6,
                "cop": 7,
                "slip": 8,
            }),
        Choice(
            "spacing", {
                "gum": 1,
                "gun": 1,
                "spine": 2,
                "snake": 3,
                "pebble": 4,
                "incline": 5,
                "dissent": 6,
                "descent": 6,
            }),
        Choice("semi", tell_commands_dict),
        Choice("word_limit", {
            "single": 1,
            "double": 2,
            "triple": 3,
            "Quadra": 4
        }),
        navigation_support.TARGET_CHOICE,
        navigation_support.get_direction_choice("mtn_dir"),
        Choice("mtn_mode", {
            "shin": "s",
            "queue": "cs",
            "fly": "c",
        }),
        Choice("extreme", {
            "Wally": "way",
        }),
        Choice("big", {
            "big": True,
        }),
        Choice("splatdir", {
            "lease": "backspace",
            "ross": "delete",
        }),
    ]

    defaults = {
        "nnavi500": 1,
        "nnavi50": 1,
        "nnavi10": 1,
        "nnavi3": 1,
        "textnv": "",
        "capitalization": 0,
        "spacing": 0,
        "mtn_mode": None,
        "mtn_dir": "right",
        "extreme": None,
        "big": False,
        "splatdir": "backspace",
        "modifier": "",
    }