def test_other_special_in_sequence(self):
     output = check_parse_tree(
         " test <an_extra> [op] {test_special=4}",
         Sequence([Literal(u"test"), extras["an_extra"], Optional(Literal(u"op"))]),
     )
     assert output.test_special == 4
     assert all(getattr(child, 'test_special', None) == None for child in output.children)
Exemple #2
0
class MappingCountRule(MappingRule):
    exported = False
    extras = [
        NoCompile(Optional(Integer(min=0, max=99), default=1), name='nn'),
        IntegerRef(min=1, max=10, name='n'),
        IntegerRef(min=1, max=100, name='bign'),
        DictateWords('text')
    ]
    defaults = {'n': 1, 'nn': 1, 'text': '', 'bign': 1}
 def test_alternative_parens(self):
     check_parse_tree(
         "( test |[op] <an_extra>)",
         Alternative(
             [
                 Literal(u"test"),
                 Sequence([Optional(Literal(u"op")), extras["an_extra"]]),
             ]
         ),
     )
Exemple #4
0
class MoveRule(CompoundRule):
    spec = "<type> <direction> <n>"
    extras = [
        Choice("type", {
            'Break': 'Break',
            'Move': 'Move'
        }),
        Optional(
            Choice("direction", {
                'left': 'left',
                'up': 'up',
                'down': 'down',
                'right': 'right'
            }), "direction"),
        Optional(Repetition(Integer("n", 0, 10), 0, 10, "n"), "n")
    ]

    def _process_recognition(self, node, extras):
        numbers = extras["n"]
        direction = extras["direction"]
        if (direction == None):
            direction = 'down'

        total = "".join(str(x) for x in numbers)
        if (total == ""):
            total = "1"
        total = int(total)

        presses = []
        if (type == "Break"):
            presses.append('home')

        for i in range(total):
            presses.append(direction)

        press(presses)
class SharedChromeRepeatablesRule(MappingCountRule):
    mapping = aenea.configuration.make_grammar_commands(
        'chrome',
        {
            '<jl_direct> <letter>': Function(ActivateLink),
            '<jl_new_tab> <letter>': Function(ActivateLinkNewTab),
            '<jl_hover> <letter>': Function(ActivateLinkHover),
            '<jl_copy_url> <letter>': Function(ActivateLinkCopyUrl),
            '<jl_copy_text> <letter>': Function(ActivateLinkCopyText),
            '"new tab"': DragonKey('c-t'),
            'new window': DragonKey('c-n'),
            'new incognito': DragonKey('cs-n'),
            'teepee <nn>': DragonKey('c-%(nn)d'),
            'teepee back': DragonKey('caret'),
            'twink <nn>': DragonKey('cs-tab:%(nn)d'),
            'trip <nn>': DragonKey('c-tab:%(nn)d'),
            'steak': DragonKey('c-s'),
            'stop': DragonKey('w-dot'),
            'print': DragonKey('c-p'),
            'zoom in <nn>': DragonKey('c-plus:%(nn)d'),
            'zoom out <nn>': DragonKey('c-minus:%(nn)d'),
            'zoom reset': DragonKey('c-0'),
            'enable clicks': DragonKey('c-space/10,colon,plus,a,enter'),
            'disable clicks': DragonKey('c-space/10,colon,minus,enter'),
            # 'links':                    DragonKey('c-m'),
            # 'tinks':                    DragonKey('c-k'),
            # 'multi links':              DragonKey('a-f'),
            # 'copy link URL':            DragonKey('y,f'),
            'reload | refresh': DragonKey('c-r'),
            # 'duplicate tab | dope tab': DragonKey('y,t'),
            # '(pin | unpin) tab':        DragonKey('a-p'),
            # 'move tab left':            DragonKey('langle, langle'),
            # 'move tab right':           DragonKey('rangle, rangle'),
            # '"new tab"':                Key('w-t'),
            # 'new window':               Key('w-n'),
            # 'new incognito':            Key('ws-n'),
            # 'teepee <nn>':              Key('w-%(nn)d'),
            # 'teepee back':              Key('caret'),
            # 'twink <nn>':               Key('cs-tab:%(nn)d'),
            # 'trip <nn>':                Key('c-tab:%(nn)d'),
            # 'steak' :                   Key('w-s'),
            # 'stop' :                    Key('w-dot'),
            # 'print' :                   Key('w-p'),
            # 'zoom in <nn>':             Key('w-plus:%(nn)d'),
            # 'zoom out <nn>':            Key('w-minus:%(nn)d'),
            # 'links':                    Key('c-m'),
            # 'tinks':                    Key('c-k'),
            # 'multi links':              Key('a-f'),
            # 'copy link URL':            Key('y,f'),
            # 'reload | refresh':         Key('w-r'),
            # 'duplicate tab | dope tab': Key('y,t'),
            # '(pin | unpin) tab':        Key('a-p'),
            # 'move tab left':            Key('langle, langle'),
            # 'move tab right':           Key('rangle, rangle'),
        })

    extras = [
        NoCompile(Optional(Integer(min=0, max=100), default=1), name='nn'),
        Choice(name='jl_direct', choices=jump_letters_direct),
        Choice(name='jl_new_tab', choices=jump_letters_new_tab),
        Choice(name='jl_hover', choices=jump_letters_hover),
        Choice(name='jl_copy_url', choices=jump_letters_copy_url),
        Choice(name='jl_copy_text', choices=jump_letters_copy_text),
        Choice(choices=LETTERS, name='letter'),
    ]
Exemple #6
0
def build_rule(custom_symbol=Impossible()):

    symbol = Alternative([RuleRef(rule=SymbolRule()), custom_symbol],
                         name='symbol')

    letter = RuleRef(rule=LetterRule(), name='letter')

    symbol_sequence = Optional(Repetition(Alternative([letter, symbol]),
                                          min=1,
                                          max=32),
                               name='symbol_sequence')
    """
	symbol_sequence = Sequence([
		Optional(Repetition(
			Alternative([letter, symbol]),
			min=1, max=32
		)),
		Optional(fluid_insert)
	], name='symbol_sequence')
	"""

    spell_rule = MappingRule(
        name="letter mapping",
        mapping={
            "press <symbol_sequence>":
            Function(execute_symbol_sequence),
            "spell <symbol_sequence> <fluid_insert>":
            Function(start_insert) + Function(execute_symbol_sequence) +
            Function(lambda fluid_insert: execute(fluid_insert)) +
            Function(end_insert),
            "trailing <symbol_sequence> <fluid_insert>":
            Function(start_insert) +
            Function(execute_symbol_sequence, spaced=True) +
            Function(lambda fluid_insert: execute(fluid_insert)) +
            Function(end_insert),
            "separate <symbol_sequence> <fluid_insert>":
            Function(start_insert) +
            Function(execute_symbol_sequence, spaced=True) + Key("backspace") +
            Function(lambda fluid_insert: execute(fluid_insert)) +
            Function(end_insert),

            #		# TODO Figure out how to bundle this into the rule below via defaults
            #		#"<symbol>":
            #		#	Function(start_insert)
            #		#	  #+ Function(execute_symbol)
            #		#	  + Function(lambda symbol: symbol.execute())
            #		#	  + Function(end_insert),
            #
            "<symbol> <symbol_sequence> <fluid_insert>":
            Function(start_insert) + Function(lambda symbol: execute(symbol)) +
            Function(execute_symbol_sequence) +
            Function(lambda fluid_insert: execute(fluid_insert)) +
            Function(end_insert),
            "<fluid_insert>":
            Function(start_insert) +
            Function(lambda fluid_insert: execute(fluid_insert)) +
            Function(end_insert),
        },
        extras=[
            symbol_sequence,
            symbol,
            fluid_insert,
        ],
    )

    return spell_rule
Exemple #7
0
        "pascal <pascal_text>": Text("%(pascal_text)s"),
        "lower <lower_text>": Text("%(lower_text)s"),
        "upper <upper_text>": Text("%(upper_text)s"),
    },
    extras=[
        Dictation("text"),
        Dictation("snake_text").lower().replace(" ", "_"),
        Dictation("const_text").upper().replace(" ", "_"),
        Dictation("camel_text").camel().apply(lower_first),
        Dictation("pascal_text").camel().apply(upper_first),
        Dictation("const_text").upper().replace(" ", "_"),
        Dictation("lower_text").lower(),
        Dictation("upper_text").upper(),
    ],
)
fluid_insert = Optional(RuleRef(rule=fluid_insert_rule), name='fluid_insert')


def execute(obj):
    if not obj is None:
        obj.execute()


def execute_symbol_sequence(symbol_sequence, spaced=False):
    if not symbol_sequence is None:
        for symbol in symbol_sequence:
            symbol.execute()
            if (spaced):
                Key("space").execute()
        #if(spaced):
        #	Key("backspace").execute()
 def test_optional_alternative(self):
     check_parse_tree("[test|test's]", Optional(Alternative([Literal(u"test"), Literal(u"test's")])))
 def test_sequence(self):
     check_parse_tree(
         " test <an_extra> [op]",
         Sequence([Literal(u"test"), extras["an_extra"], Optional(Literal(u"op"))]),
     )