Exemple #1
0
    def test_seeker_defaulting_and_chaining(self):
        '''this action makes the first seeker default'''
        action = NullAction(rspec="clean")
        action.set_nexus(self.nexus)
        alt = MockAlternative(u"my", u"spoken", u"words")
        sira = StackItemRegisteredAction(action, {"_node": alt})
        self.nexus.state.add(sira)

        #

        mutable_integer = {"value": 0}

        def increment():
            mutable_integer["value"] += 1

        '''make backward seekers'''
        back_seeker = ContextSeeker(back=[
            L(S(["def"], Function(lambda: None)),
              S(["abc"], Function(increment)))
        ],
                                    rspec="abc")
        back_seeker.set_nexus(self.nexus)
        '''create backward seeker stack items'''
        stack_seeker1 = StackItemSeeker(back_seeker, {"_node": alt})
        stack_seeker2 = StackItemSeeker(back_seeker, {"_node": alt})
        '''add one'''
        self.nexus.state.add(stack_seeker1)
        '''at this point, the first seeker should have defaulted and done nothing'''
        self.assertEqual(mutable_integer["value"], 0)

        self.nexus.state.add(stack_seeker2)
        '''the second context seeker should have been triggered by the first, incrementing the value'''
        self.assertEqual(mutable_integer["value"], 1)
Exemple #2
0
 def test_seeker_defaulting_and_chaining(self):
     '''this action makes the first seeker default'''
     action = NullAction(rspec="clean")
     action.set_nexus(self.nexus)
     alt = MockAlternative(u"my", u"spoken", u"words")
     sira = StackItemRegisteredAction(action, {"_node":alt})
     self.nexus.state.add(sira)
     
     #
     
     mutable_integer = {"value": 0}
     def increment():
         mutable_integer["value"] += 1
     
     '''make backward seekers'''
     back_seeker = ContextSeeker(back=[L(S(["def"], Function(lambda: None)), 
                                          S(["abc"], Function(increment)))], rspec="abc")
     back_seeker.set_nexus(self.nexus)
     '''create backward seeker stack items'''
     stack_seeker1 = StackItemSeeker(back_seeker, {"_node":alt})
     stack_seeker2 = StackItemSeeker(back_seeker, {"_node":alt})
     '''add one'''
     self.nexus.state.add(stack_seeker1)
     
     '''at this point, the first seeker should have defaulted and done nothing'''
     self.assertEqual(mutable_integer["value"], 0)
     
     self.nexus.state.add(stack_seeker2)
     '''the second context seeker should have been triggered by the first, incrementing the value'''
     self.assertEqual(mutable_integer["value"], 1)
Exemple #3
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>"), 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] ")))
        ]),
        "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 _ "), rspec="ashes"),
        "bravery":
        RegisteredAction(Text("bravery _ "), rspec="bravery"),
        "charcoal <text> [<n>]":
        R(Text("charcoal _ %(text)s"), rspec="charcoal"),
        "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": ""}
Exemple #4
0
    def test_seeker_backward(self):
        for i in range(0, 2):
            '''make 2 fake NullActions'''
            trigger1 = NullAction(rspec="bell")
            trigger2 = NullAction(rspec="door")
            trigger1.set_nexus(self.nexus)
            trigger2.set_nexus(self.nexus)
            '''make fake StackItemRegisteredActions'''
            alt2 = MockAlternative(u"my", u"spoken", u"words")
            sira1 = StackItemRegisteredAction(trigger1, {"_node": alt2})
            sira2 = StackItemRegisteredAction(trigger2, {"_node": alt2})
            '''add them'''
            self.nexus.state.add(sira1)
            self.nexus.state.add(sira2)
            '''set up backward looking seeker'''
            mutable_string = {"value": ""}

            def append_a():
                mutable_string["value"] += "a"

            def append_b():
                mutable_string["value"] += "b"

            def append_c():
                mutable_string["value"] += "c"

            def append_d():
                mutable_string["value"] += "d"

            '''create context levels'''
            set_1_1 = S(["arch"], append_a)
            set_1_2 = S(["bell"], append_b)
            level_1 = L(set_1_1, set_1_2)
            set_2_1 = S(["cellar"], append_c)
            set_2_2 = S(["door"], append_d)
            level_2 = L(set_2_1, set_2_2)
            '''create context seeker'''
            levels = [level_1, level_2]
            seeker = ContextSeeker(back=levels)
            if i == 0:
                seeker.reverse = True
            seeker.set_nexus(self.nexus)
            '''create context seeker stack item'''
            alt = MockAlternative(u"my", u"spoken", u"words")
            stack_seeker = StackItemSeeker(seeker, {"_node": alt})
            '''add it'''
            self.nexus.state.add(stack_seeker)

            if i == 0:
                self.assertEqual(mutable_string["value"], "db")
            else:
                self.assertEqual(mutable_string["value"], "bd")
Exemple #5
0
    def __init__(self,
                 list_function,
                 filter_function,
                 selection_function,
                 default_1=True,
                 rspec="default",
                 rdescript="unnamed command (FM)"):
        def get_choices(data):
            choices = list_function()
            if filter_function:
                choices = filter_function(
                    data, choices
                )  # the filter function is responsible for using the data to filter the choices
            while len(choices) < len(FuzzyMatchAction.TEN):
                choices.append("")  # this is questionable
            return choices

        self.choice_generator = get_choices

        mutable_list = {
            "value": None
        }  # only generate the choices once, and show them between the action and the stack item
        self.mutable_list = mutable_list

        def execute_choice(spoken_words=[]):
            n = -1
            while len(
                    spoken_words
            ) > 2:  # in the event the last words spoken were a command chain,
                spoken_words.pop()  # get only the number trigger
            j = ""
            if len(spoken_words) > 0:
                j = " ".join(spoken_words)
            if j in FuzzyMatchAction.TEN:
                n = FuzzyMatchAction.TEN.index(j)
            if n == -1: n = 0
            selection_function(mutable_list["value"][n])

        def cancel_message():
            control.nexus().intermediary.text("Cancel (" + rdescript + ")")

        forward = [
            L(S([""], execute_choice, consume=False),
              S(["number"], execute_choice, use_spoken=True),
              S(["cancel", "clear"], cancel_message))
        ]
        if not default_1:  # make cancel the default
            context_level = forward[0]
            a = context_level.sets[0]
            context_level.sets[0] = context_level.sets[2]
            context_level.sets[2] = a
        ContextSeeker.__init__(self, None, forward, rspec, rdescript)
Exemple #6
0
    def test_seeker_backward(self):
        for i in range(0, 2):
            '''make 2 fake NullActions'''
            trigger1 = NullAction(rspec="bell")
            trigger2 = NullAction(rspec="door")
            trigger1.set_nexus(self.nexus)
            trigger2.set_nexus(self.nexus)
            '''make fake StackItemRegisteredActions'''
            alt2 = MockAlternative(u"my", u"spoken", u"words")
            sira1 = StackItemRegisteredAction(trigger1, {"_node": alt2})
            sira2 = StackItemRegisteredAction(trigger2, {"_node": alt2})
            '''add them'''
            self.nexus.state.add(sira1)
            self.nexus.state.add(sira2)
            '''set up backward looking seeker'''
            mutable_string = {"value": ""}

            def append_a():
                mutable_string["value"] += "a"

            def append_b():
                mutable_string["value"] += "b"

            def append_c():
                mutable_string["value"] += "c"

            def append_d():
                mutable_string["value"] += "d"

            '''create context levels'''
            set_1_1 = S(["arch"], append_a)
            set_1_2 = S(["bell"], append_b)
            level_1 = L(set_1_1, set_1_2)
            set_2_1 = S(["cellar"], append_c)
            set_2_2 = S(["door"], append_d)
            level_2 = L(set_2_1, set_2_2)
            '''create context seeker'''
            levels = [level_1, level_2]
            seeker = ContextSeeker(back=levels)
            if i == 0:
                seeker.reverse = True
            seeker.set_nexus(self.nexus)
            '''create context seeker stack item'''
            alt = MockAlternative(u"my", u"spoken", u"words")
            stack_seeker = StackItemSeeker(seeker, {"_node": alt})
            '''add it'''
            self.nexus.state.add(stack_seeker)

            if i == 0:
                self.assertEqual(mutable_string["value"], "db")
            else:
                self.assertEqual(mutable_string["value"], "bd")
Exemple #7
0
 def __init__(self, node, grammar, stat_msg=None, is_reset=False):
     # for self modification
     self.node = node
     first = False
     if self.master_node == None:
         self.master_node = self.node
         first = True
         self.post = ContextSeeker(forward=[L(S(["cancel"], self.reset_node, consume=False))], rspec=self.master_node.spec)
     if self.stat_msg == None:
         self.stat_msg = stat_msg        
     
     mapping = {}
     extras = []
     defaults = {}
     
     # each child node gets turned into a mapping key/value
     for child in self.node.children:
         child.fill_out_rule(mapping, extras, defaults, self)
     
     if len(mapping)==0:
         if self.stat_msg!=None and not first:
             self.stat_msg.text("Node Reset")# status window messaging
         self.reset_node()
         for child in self.node.children:
             child.fill_out_rule(mapping, extras, defaults, self)
     else:
         if self.stat_msg!=None and not first and not is_reset:# status window messaging
             self.stat_msg.hint("\n".join([x.get_spec_and_base_and_node()[0] for x in self.node.children]))
     
     
     MappingRule.__init__(self, "node_" + str(self.master_node.spec), mapping, extras, defaults)
     self.grammar = grammar
Exemple #8
0
 def __init__(self, list_function, filter_function, selection_function, default_1=True, rspec="default", 
              rdescript="unnamed command (FM)", log_file_path=None):
     def get_choices(data):
         choices = list_function()
         if filter_function:
             choices = filter_function(data, choices) # the filter function is responsible for using the data to filter the choices
         while len(choices)<len(FuzzyMatchAction.TEN):
             choices.append("") # this is questionable
         return choices
     self.choice_generator = get_choices
     mutable_list = {"value": None} # only generate the choices once, and show them between the action and the stack item
     self.mutable_list = mutable_list
     self.filter_text = ""
     
     def execute_choice(spoken_words=[]):
         n = -1
         while len(spoken_words)>2:# in the event the last words spoken were a command chain,
             spoken_words.pop()    # get only the number trigger
         j = ""
         if len(spoken_words)>0:
             j = " ".join(spoken_words)
         if j in FuzzyMatchAction.TEN:
             n = FuzzyMatchAction.TEN.index(j)
         if n == -1: n = 0
         choices = mutable_list["value"]
         selection_function(choices[n])
         if log_file_path and settings.SETTINGS["miscellaneous"]["enable_match_logging"]:
             log_entry = [self.filter_text] + [choices[n]] + [s for s,i in zip(choices, range(len(choices))) if i != n]
             with open(log_file_path, "a") as log_file:
                 log_file.write(str(log_entry) + "\n")
     def cancel_message():
         self.nexus().intermediary.text("Cancel ("+rdescript+")")
     forward = [L(S([""], execute_choice, consume=False),
                  S(["number"], execute_choice, use_spoken=True), 
                  S(["cancel", "clear"], cancel_message)
                 )
               ]
     if not default_1: # make cancel the default
         context_level = forward[0]
         a = context_level.sets[0]
         context_level.sets[0] = context_level.sets[2]
         context_level.sets[2] = a
     ContextSeeker.__init__(self, None, forward, rspec, rdescript)
Exemple #9
0
    def __init__(self, node, nexus, is_reset=False):
        first = False
        if self.master_node is None:
            self.master_node = node
            self.nexus = nexus
            '''self.post is added to every entry in the mapping; 
            its purpose is to handle cancels; if it detects another of itself, 
            it does nothing; 
            
            but looking forward, won't it never find itself? 
            how is it that the node isn't constantly getting reset? '''
            self.post = ContextSeeker(forward=[
                L(S(["cancel"], lambda: self.reset_node(), consume=False),
                  S([self.master_node.spec], lambda: None, consume=False))
            ],
                                      rspec=self.master_node.spec)
            self.post.set_nexus(nexus)
            first = True
            SelfModifyingRule.__init__(self,
                                       self.master_node.spec,
                                       refresh=False)

        self.refresh(node, first, is_reset)
Exemple #10
0
 def __init__(self, list_function, filter_function, selection_function, default_1=True, rspec="default", rdescript="unnamed command (FM)"):
     def get_choices(data):
         choices = list_function()
         if filter_function:
             choices = filter_function(data, choices) # the filter function is responsible for using the data to filter the choices
         while len(choices)<len(FuzzyMatchAction.TEN):
             choices.append("") # this is questionable
         return choices
     self.choice_generator = get_choices
     
     mutable_list = {"value": None} # only generate the choices once, and show them between the action and the stack item
     self.mutable_list = mutable_list
     
     def execute_choice(spoken_words=[]):
         n = -1
         while len(spoken_words)>2:# in the event the last words spoken were a command chain,
             spoken_words.pop()    # get only the number trigger
         j = ""
         if len(spoken_words)>0:
             j = " ".join(spoken_words)
         if j in FuzzyMatchAction.TEN:
             n = FuzzyMatchAction.TEN.index(j)
         if n == -1: n = 0
         selection_function(mutable_list["value"][n])
     def cancel_message():
         control.nexus().intermediary.text("Cancel ("+rdescript+")")
     forward = [L(S([""], execute_choice, consume=False),
                  S(["number"], execute_choice, use_spoken=True), 
                  S(["cancel", "clear"], cancel_message)
                 )
               ]
     if not default_1: # make cancel the default
         context_level = forward[0]
         a = context_level.sets[0]
         context_level.sets[0] = context_level.sets[2]
         context_level.sets[2] = a
     ContextSeeker.__init__(self, None, forward, rspec, rdescript)
Exemple #11
0
 def __init__(self, node, nexus, is_reset=False):
     first = False
     if self.master_node is None:
         self.master_node = node
         self.nexus = nexus
         '''self.post is added to every entry in the mapping; 
         its purpose is to handle cancels; if it detects another of itself, 
         it does nothing; 
         
         but looking forward, won't it never find itself? 
         how is it that the node isn't constantly getting reset? '''
         self.post = ContextSeeker(forward=[L(S(["cancel"], lambda: self.reset_node(), consume=False), 
                                              S([self.master_node.spec], lambda: None, consume=False))], 
                                   rspec=self.master_node.spec)
         self.post.set_nexus(nexus)
         first = True
         SelfModifyingRule.__init__(self, self.master_node.spec, refresh=False)
     
     self.refresh(node, first, is_reset)
Exemple #12
0
class NodeRule(SelfModifyingRule):
    master_node = None
    
    def __init__(self, node, nexus, is_reset=False):
        first = False
        if self.master_node is None:
            self.master_node = node
            self.nexus = nexus
            '''self.post is added to every entry in the mapping; 
            its purpose is to handle cancels; if it detects another of itself, 
            it does nothing; 
            
            but looking forward, won't it never find itself? 
            how is it that the node isn't constantly getting reset? '''
            self.post = ContextSeeker(forward=[L(S(["cancel"], lambda: self.reset_node(), consume=False), 
                                                 S([self.master_node.spec], lambda: None, consume=False))], 
                                      rspec=self.master_node.spec)
            self.post.set_nexus(nexus)
            first = True
            SelfModifyingRule.__init__(self, self.master_node.spec, refresh=False)
        
        self.refresh(node, first, is_reset)
    
    def get_name(self):
        return self.master_node.spec
    
    def refresh(self, *args):
        self.node = args[0]
        first = args[1]
        is_reset = args[2]
            
        mapping = {}
        extras = []
        defaults = {}
        
        '''each child node gets turned into a mapping key/value'''
        for child in self.node.children:
            child.fill_out_rule(mapping, extras, defaults, self)
        if len(mapping)==0:
            if not first:
                self.nexus.intermediary.text("Node Reset")# status window messaging
            self.reset_node()
            for child in self.node.children:
                child.fill_out_rule(mapping, extras, defaults, self)
        else:
            if not first and not is_reset:# status window messaging
                choices = [x.get_spec_and_base_and_node()[0] for x in self.node.children]
                for choice in choices:
                    self.nexus.intermediary.text(choice)
        
        self.extras = extras
        self.defaults = defaults
        self.reset(mapping)
        
    
    def change_node(self, node, reset=False):
        self.refresh(node, False, reset)
    
    def reset_node(self):
        if self.node is not self.master_node:
            self.change_node(self.master_node, True)
Exemple #13
0
 def test_seeker_consume(self):
     '''seeker actions have the option to not/consume their triggers;
     that is, the trigger actions do not execute and only act as triggers'''
     
     mutable_string = {"value": ""}
     def append_a():
         mutable_string["value"] += "a"
     def append_b():
         mutable_string["value"] += "b"
     def append_c():
         mutable_string["value"] += "c"
     def append_d():
         mutable_string["value"] += "d"
     def append_e():
         mutable_string["value"] += "e"
     def append_f():
         mutable_string["value"] += "f"
     
     '''create context levels'''
     set_1_1 = S(["arch"], append_a)
     set_1_2 = S(["bell"], append_b)
     set_1_2.consume = False
     level_1 = L(set_1_1, set_1_2)
     set_2_1 = S(["cellar"], append_c)
     set_2_2 = S(["door"], append_d)
     level_2 = L(set_2_1, set_2_2)
     set_3_1 = S(["echo"], append_e)
     set_3_2 = S(["frame"], append_f)
     set_3_2.consume = False
     level_3 = L(set_3_1, set_3_2)
     
     '''create context seeker'''
     levels = [level_1, level_2, level_3]
     seeker = ContextSeeker(forward=levels)
     seeker.set_nexus(self.nexus)
     
     '''create context seeker stack item'''
     alt = MockAlternative(u"my", u"spoken", u"words")
     stack_seeker = StackItemSeeker(seeker, {"_node":alt})
     '''add it'''
     self.nexus.state.add(stack_seeker)
     
     '''make 3 fake triggering RegisteredActions;
     the first and third do not consume their triggers'''
     trigger1 = RegisteredAction(Function(append_a), rspec="bell")
     trigger2 = RegisteredAction(Function(append_c), rspec="door")
     trigger3 = RegisteredAction(Function(append_e), rspec="frame")
     trigger1.set_nexus(self.nexus)
     trigger2.set_nexus(self.nexus)
     trigger3.set_nexus(self.nexus)
     '''make fake StackItemRegisteredActions'''
     alt2 = MockAlternative(u"my", u"spoken", u"words")
     sira1 = StackItemRegisteredAction(trigger1, {"_node":alt2})
     sira2 = StackItemRegisteredAction(trigger2, {"_node":alt2})
     sira3 = StackItemRegisteredAction(trigger3, {"_node":alt2})
     '''add them'''
     self.nexus.state.add(sira1)
     self.nexus.state.add(sira2)
     self.nexus.state.add(sira3)
     
     self.assertEqual(mutable_string["value"], "aebdf")
Exemple #14
0
    def test_seeker_consume(self):
        '''seeker actions have the option to not/consume their triggers;
        that is, the trigger actions do not execute and only act as triggers'''

        mutable_string = {"value": ""}

        def append_a():
            mutable_string["value"] += "a"

        def append_b():
            mutable_string["value"] += "b"

        def append_c():
            mutable_string["value"] += "c"

        def append_d():
            mutable_string["value"] += "d"

        def append_e():
            mutable_string["value"] += "e"

        def append_f():
            mutable_string["value"] += "f"

        '''create context levels'''
        set_1_1 = S(["arch"], append_a)
        set_1_2 = S(["bell"], append_b)
        set_1_2.consume = False
        level_1 = L(set_1_1, set_1_2)
        set_2_1 = S(["cellar"], append_c)
        set_2_2 = S(["door"], append_d)
        level_2 = L(set_2_1, set_2_2)
        set_3_1 = S(["echo"], append_e)
        set_3_2 = S(["frame"], append_f)
        set_3_2.consume = False
        level_3 = L(set_3_1, set_3_2)
        '''create context seeker'''
        levels = [level_1, level_2, level_3]
        seeker = ContextSeeker(forward=levels)
        seeker.set_nexus(self.nexus)
        '''create context seeker stack item'''
        alt = MockAlternative(u"my", u"spoken", u"words")
        stack_seeker = StackItemSeeker(seeker, {"_node": alt})
        '''add it'''
        self.nexus.state.add(stack_seeker)
        '''make 3 fake triggering RegisteredActions;
        the first and third do not consume their triggers'''
        trigger1 = RegisteredAction(Function(append_a), rspec="bell")
        trigger2 = RegisteredAction(Function(append_c), rspec="door")
        trigger3 = RegisteredAction(Function(append_e), rspec="frame")
        trigger1.set_nexus(self.nexus)
        trigger2.set_nexus(self.nexus)
        trigger3.set_nexus(self.nexus)
        '''make fake StackItemRegisteredActions'''
        alt2 = MockAlternative(u"my", u"spoken", u"words")
        sira1 = StackItemRegisteredAction(trigger1, {"_node": alt2})
        sira2 = StackItemRegisteredAction(trigger2, {"_node": alt2})
        sira3 = StackItemRegisteredAction(trigger3, {"_node": alt2})
        '''add them'''
        self.nexus.state.add(sira1)
        self.nexus.state.add(sira2)
        self.nexus.state.add(sira3)

        self.assertEqual(mutable_string["value"], "aebdf")
Exemple #15
0
    def test_actions_cleaned(self):
        '''these test functions should stay in sync with the clean methods for each stack action'''
        def registered_is_clean(r):
            return r.dragonfly_data is None and r.base is None

        def seeker_is_clean(s):
            result = True
            levels = []
            if s.back is not None: levels += s.back
            if s.forward is not None: levels += s.forward
            for context_level in levels:
                result &= context_level.dragonfly_data is None
            return result

        def asynchronous_is_clean(a):
            return a.closure is None

        '''mock words being the same doesn't matter for this test, or most tests'''
        alt = MockAlternative(u"my", u"spoken", u"words")
        '''make fake NullActions'''
        action1 = NullAction(rspec="barkley")
        action2 = NullAction(rspec="gaiden")
        action3 = NullAction(rspec="is")
        action4 = NullAction(rspec="awesome")
        action1.set_nexus(self.nexus)
        action2.set_nexus(self.nexus)
        action3.set_nexus(self.nexus)
        action4.set_nexus(self.nexus)
        '''make fake StackItemRegisteredActions'''
        sira1 = StackItemRegisteredAction(action1, {"_node": alt})
        sira2 = StackItemRegisteredAction(action2, {"_node": alt})
        sira3 = StackItemRegisteredAction(action3, {"_node": alt})
        sira4 = StackItemRegisteredAction(action4, {"_node": alt})
        '''should not be clean before it's executed'''
        self.assertFalse(registered_is_clean(sira1))
        '''add first one for backward seeker'''
        self.nexus.state.add(sira1)
        '''should be clean as soon as it's executed'''
        self.assertTrue(registered_is_clean(sira1))
        '''make backward seeker'''
        back_seeker = ContextSeeker(
            back=[L(S(["minecraft"], Function(lambda: None)))])
        back_seeker.set_nexus(self.nexus)
        '''create backward seeker stack item'''
        stack_seeker = StackItemSeeker(back_seeker, {"_node": alt})
        '''add it'''
        self.nexus.state.add(stack_seeker)
        '''levels should be clean as soon as it's executed'''
        self.assertTrue(
            registered_is_clean(stack_seeker)
            and seeker_is_clean(stack_seeker))

        #
        '''make forward seeker'''
        forward_seeker = ContextSeeker(forward=[
            L(S(["cave"], Function(lambda: None))),
            L(S(["story"], Function(lambda: None)))
        ])
        forward_seeker.set_nexus(self.nexus)
        '''create context seeker stack item'''
        stack_seeker2 = StackItemSeeker(forward_seeker, {"_node": alt})
        '''add it'''
        self.nexus.state.add(stack_seeker2)

        self.nexus.state.add(sira2)
        '''levels should not be clean before seeker is executed'''
        self.assertFalse(
            registered_is_clean(stack_seeker2)
            or seeker_is_clean(stack_seeker2))

        self.nexus.state.add(sira3)
        '''levels should be clean as soon as it's executed'''
        self.assertTrue(
            registered_is_clean(stack_seeker2)
            and seeker_is_clean(stack_seeker2))

        #
        '''make asynchronous action'''
        asynchronous = AsynchronousAction(
            [L(S(["eternal", "daughter", "awesome"], lambda: None))],
            blocking=False)
        asynchronous.set_nexus(self.nexus)
        '''make StackItemAsynchronous'''
        sia1 = StackItemAsynchronous(asynchronous, {"_node": alt})
        '''add it'''
        self.nexus.state.add(sia1)
        '''closure should not be clean before asynchronous is executed'''
        self.assertFalse(
            registered_is_clean(sia1) or seeker_is_clean(sia1)
            or asynchronous_is_clean(sia1))

        self.nexus.state.add(sira4)
        '''closure should be clean after asynchronous is executed'''
        self.assertTrue(
            registered_is_clean(sia1) and seeker_is_clean(sia1)
            and asynchronous_is_clean(sia1))
Exemple #16
0
    def test_use_spoken_words_or_rspec(self):
        '''seekers can take the spoken words or rspecs
        of their trigger actions and feed them to the
        function objects of their ContextSets'''
        '''make triggers for context seekers
        (2 forward, 2 backward / 2 spoken, 2 rspec)'''
        action1 = NullAction(rspec="alpha")
        action2 = NullAction(rspec="_")
        action3 = NullAction(rspec="charlie")
        action4 = NullAction(rspec="_")
        action1.set_nexus(self.nexus)
        action2.set_nexus(self.nexus)
        action3.set_nexus(self.nexus)
        action4.set_nexus(self.nexus)
        alt = MockAlternative(u"_")
        spec1 = [u"here", u"are", u"words"]
        spec2 = [u"some", u"more", u"words"]
        sira1 = StackItemRegisteredAction(action1, {"_node": alt})
        sira2 = StackItemRegisteredAction(action2,
                                          {"_node": MockAlternative(*spec1)})
        sira3 = StackItemRegisteredAction(action3, {"_node": alt})
        sira4 = StackItemRegisteredAction(action4,
                                          {"_node": MockAlternative(*spec2)})

        #

        mutable_integer = {"value": 0}

        def increment():
            mutable_integer["value"] += 1

        #
        def _1(params):
            if params == "alpha": increment()

        def _2(params):
            if params == spec1: increment()

        def _3(params):
            if params == "charlie": increment()

        def _4(params):
            if params == spec2: increment()

        '''make seekers'''
        back_seeker1 = ContextSeeker(
            back=[L(S(["alpha"], _1, parameters="_", use_rspec=True))],
            rspec="_")
        back_seeker2 = ContextSeeker(
            back=[L(S(["_"], _2, parameters=["_"], use_spoken=True))],
            rspec="_")
        forward_seeker1 = ContextSeeker(
            forward=[L(S(["_"], _3, parameters="_", use_rspec=True))],
            rspec="_")
        forward_seeker2 = ContextSeeker(
            forward=[L(S(["delta"], _4, parameters=["_"], use_spoken=True))],
            rspec="_")
        back_seeker1.set_nexus(self.nexus)
        back_seeker2.set_nexus(self.nexus)
        forward_seeker1.set_nexus(self.nexus)
        forward_seeker2.set_nexus(self.nexus)
        '''create seeker stack items'''
        stack_seeker_b1 = StackItemSeeker(back_seeker1, {"_node": alt})
        stack_seeker_b2 = StackItemSeeker(back_seeker2, {"_node": alt})
        stack_seeker_f1 = StackItemSeeker(forward_seeker1, {"_node": alt})
        stack_seeker_f2 = StackItemSeeker(forward_seeker2, {"_node": alt})

        #
        '''trigger the first backward seeker; uses rspec ("alpha") '''
        self.nexus.state.add(sira1)
        self.nexus.state.add(stack_seeker_b1)
        self.assertEqual(mutable_integer["value"], 1)
        '''trigger the second backward seeker; uses spoken words (spec1) '''
        self.nexus.state.add(sira2)
        self.nexus.state.add(stack_seeker_b2)
        self.assertEqual(mutable_integer["value"], 2)
        '''trigger the first forward seeker; uses rspec ("charlie") '''
        self.nexus.state.add(stack_seeker_f1)
        self.nexus.state.add(sira3)
        self.assertEqual(mutable_integer["value"], 3)
        '''trigger the first forward seeker; uses spoken words (spec2) '''
        self.nexus.state.add(stack_seeker_f2)
        self.nexus.state.add(sira4)
        self.assertEqual(mutable_integer["value"], 4)
Exemple #17
0
 def test_use_spoken_words_or_rspec(self):
     '''seekers can take the spoken words or rspecs
     of their trigger actions and feed them to the
     function objects of their ContextSets'''
     
     '''make triggers for context seekers
     (2 forward, 2 backward / 2 spoken, 2 rspec)'''
     action1 = NullAction(rspec="alpha")
     action2 = NullAction(rspec="_")
     action3 = NullAction(rspec="charlie")
     action4 = NullAction(rspec="_")
     action1.set_nexus(self.nexus)
     action2.set_nexus(self.nexus)
     action3.set_nexus(self.nexus)
     action4.set_nexus(self.nexus)
     alt = MockAlternative(u"_")
     spec1 = [u"here", u"are", u"words"]
     spec2 = [u"some", u"more", u"words"]
     sira1 = StackItemRegisteredAction(action1, {"_node":alt})  
     sira2 = StackItemRegisteredAction(action2, {"_node":MockAlternative(*spec1)})
     sira3 = StackItemRegisteredAction(action3, {"_node":alt})
     sira4 = StackItemRegisteredAction(action4, {"_node":MockAlternative(*spec2)})
     
     #
     
     mutable_integer = {"value": 0}
     def increment(): 
         mutable_integer["value"] += 1
     #
     def _1(params):
         if params == "alpha": increment()
     def _2(params):
         if params == spec1: increment()
     def _3(params):
         if params == "charlie": increment()
     def _4(params):
         if params == spec2: increment()
         
     
     '''make seekers'''
     back_seeker1 = ContextSeeker(back=[L(S(["alpha"], _1, parameters="_", use_rspec=True))], rspec="_")
     back_seeker2 = ContextSeeker(back=[L(S(["_"], _2, parameters=["_"], use_spoken=True))], rspec="_")
     forward_seeker1 = ContextSeeker(forward=[L(S(["_"], _3, parameters="_", use_rspec=True))], rspec="_")
     forward_seeker2 = ContextSeeker(forward=[L(S(["delta"], _4, parameters=["_"], use_spoken=True))], rspec="_")
     back_seeker1.set_nexus(self.nexus)
     back_seeker2.set_nexus(self.nexus)
     forward_seeker1.set_nexus(self.nexus)
     forward_seeker2.set_nexus(self.nexus)
     '''create seeker stack items'''
     stack_seeker_b1 = StackItemSeeker(back_seeker1, {"_node":alt})
     stack_seeker_b2 = StackItemSeeker(back_seeker2, {"_node":alt})
     stack_seeker_f1 = StackItemSeeker(forward_seeker1, {"_node":alt})
     stack_seeker_f2 = StackItemSeeker(forward_seeker2, {"_node":alt})
     
     #
             
     '''trigger the first backward seeker; uses rspec ("alpha") '''
     self.nexus.state.add(sira1)
     self.nexus.state.add(stack_seeker_b1)
     self.assertEqual(mutable_integer["value"], 1)
     
     '''trigger the second backward seeker; uses spoken words (spec1) '''
     self.nexus.state.add(sira2)
     self.nexus.state.add(stack_seeker_b2)
     self.assertEqual(mutable_integer["value"], 2)
     
     '''trigger the first forward seeker; uses rspec ("charlie") '''
     self.nexus.state.add(stack_seeker_f1)
     self.nexus.state.add(sira3)        
     self.assertEqual(mutable_integer["value"], 3)
     
     '''trigger the first forward seeker; uses spoken words (spec2) '''
     self.nexus.state.add(stack_seeker_f2)
     self.nexus.state.add(sira4)        
     self.assertEqual(mutable_integer["value"], 4)
Exemple #18
0
class Navigation(MergeRule):
    non = NavigationNon
    pronunciation = CCRMerger.CORE[1]

    mapping = {
    # "periodic" repeats whatever comes next at 1-second intervals until "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, nexus=_NEXUS)))
                                                   ], time_in_seconds=0.2, repetitions=50, rdescript="Fill" ),
    "jump in":                      AsynchronousAction([L(S(["cancel"], context.nav, ["right", "(~[~{~<"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: In" ),
    "jump out":                     AsynchronousAction([L(S(["cancel"], context.nav, ["right", ")~]~}~>"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Out" ),
    "jump back":                    AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Back" ),
    "jump back in":                 AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))
                                                   ], finisher=Key("right"),
                                                      time_in_seconds=0.1,
                                                      repetitions=50,
                                                      rdescript="Jump: Back In" ),

    # keyboard shortcuts
    'salve':                         R(Key("c-s"), rspec="save", rdescript="Save"),
    'slap [<nnavi50>]':              R(Key("enter"), rspec="slap", rdescript="Enter")* Repeat(extra="nnavi50"),
    'slap up':                       R(Key("escape, up, end, enter"), rspec="slap up", rdescript="Line Above"),
    'slap down':                     R(Key("escape, end, enter"), rspec="slap down", rdescript="Line Below"),
    'curslap':                       R(Key("escape, lbrace, rbrace, left, enter"), rspec="curslap", rdescript="Curly New Line"),

    'north':                     R(Key("c-home"), rspec="north", rdescript="Ctrl Home"),
    'south':                     R(Key("c-end"), rspec="south", rdescript="Ctrl End"),
    'east':                     R(Key("end"), rspec="east", rdescript="End"),
    'west':                     R(Key("home"), rspec="west", rdescript="Home"),

    'page up':                     R(Key("pgup"), rspec="page up", rdescript="Page Up"),
    'page down':                     R(Key("pgdown"), rspec="page down", rdescript="Page Down"),

    "(<mtn_dir> | <mtn_mode> [<mtn_dir>]) [(<nnavi500> | <extreme>)]": R(Function(textformat.master_text_nav), rdescript="Keyboard Text Navigation"),
    "<short_mode> <key> [<nnavi500>]":        R(Function(textformat.master_short), rdescript="Keyboard Shortcut"),
    "<short_mode> <mouse_action>":            R(Function(textformat.master_short_mouse), rdescript="Mouse Shortcut"),
    "hold <short_mode>":                      R(Function(textformat.hold_modifier), rdescript="Hold Modifier"),
    "alt":                          R(Key("alt"), rdescript="Alt"),
    "wind":                         R(Key("win"), rdescript="Win"),
    "null":                         R(Key("n, u, l, l"), rdescript="Null"),

    "stoosh [<nnavi500>]":          R(Key("c-c")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"),
    "cut [<nnavi500>]":             R(Key("c-x")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="cut", rdescript="Cut"),
    "spark [<nnavi500>]":           R(Function(navigation.drop, nexus=_NEXUS), rspec="spark", rdescript="Paste"),

    "deli [<nnavi50>]":             R(Key("del/5"), rspec="deli", rdescript="Delete") * Repeat(extra="nnavi50"),
    "clear [<nnavi50>]":            R(Key("backspace/5:%(nnavi50)d"), rspec="clear", rdescript="Backspace"),
    SymbolSpecs.CANCEL:             R(Key("escape"), rspec="cancel", rdescript="Cancel Action"),


    "shackle":                      R(Key("home/5, s-end"), rspec="shackle", rdescript="Select Line"),
    "(tell | tau) <semi>":          R(Function(navigation.next_line), rspec="tell dock", rdescript="Complete Line"),
    "duple [<nnavi50>]":            R(Key("escape, home, s-end, c-c, end, enter, c-v"), rspec="duple", rdescript="Duplicate Line") * Repeat(extra="nnavi50"),
    "Kraken":                       R(Key("c-space"), rspec="Kraken", rdescript="Control Space"),

    # text formatting
    "set format (<spacing> <capitalization> | <capitalization> | <spacing>)":  R(Function(textformat.set_text_format), rdescript="Set Text Format"),
    "clear caster formatting":      R(Function(textformat.clear_text_format), rdescript="Clear Caster Formatting"),
    "peek format":                  R(Function(textformat.peek_text_format), rdescript="Peek Format"),
    "camel <textnv>":                        R(Function(textformat.master_format_text_camel), rdescript="Camel Case"),
    "pascal <textnv>":                       R(Function(textformat.master_format_text_pascal), rdescript="Pascal Case"),
    "dock mel <textnv>":                     R(Key("dot")+Function(textformat.master_format_text_camel), rdescript="Dot Camel Case"),
    "(dop|dot) scal <textnv>":                     R(Key("dot")+Function(textformat.master_format_text_pascal), rdescript="Dot Pascal Case"),
    "(<spacing> <capitalization> | <capitalization> | <spacing>) <textnv>":  R(Function(textformat.master_format_text), rdescript="Text Format"),
    "format <textnv>":              R(Function(textformat.prior_text_format), rdescript="Last Text Format"),

    "dredge":                       R(Key("a-tab"), rdescript="Alt-Tab"),

    }

    extras = [
        alphanumeric.get_key_choice("key"),
        Choice(
            "short_mode", {
                "shift": "s",
                "troll": "c",
                "alt": "a",
                "wind": "w",
                "trot": "ca",
                "shoal": "cs",
                "tron": "wc",
                "shalt": "sa",
                "walt": "wa",
                "shin": "ws",
                "trash": "cas"
            }),
        Choice(
            "mouse_action", {
                "kick": "left",
                "kick mid": "middle",
                "psychic": "right",
                "dub kick": "left:2"
            }),
        IntegerRefST("nnavi50", 1, 50),
        IntegerRefST("nnavi500", 1, 500),
        Dictation("textnv"),
        Choice("capitalization", {
            "scream": 1,
            "scal": 2,
            "mel": 3,
            "tense": 4,
            "laws": 5
        }),
        Choice("spacing", {
            "smash": 1,
            "spine": 2,
            "snake": 3
        }),
        Choice("semi", {
            "dock": ";",
            "doc": ";",
            "sink": ""
        }),
        navigation.TARGET_CHOICE,
        navigation.get_direction_choice("mtn_dir"),
        Choice("mtn_mode", {
            "shin": "s",
            "queue": "cs",
            "fly": "c",
        }),
        Choice("extreme", {
            "Wally": "way",
        }),
    ]

    defaults = {
        "nnavi500": 1,
        "nnavi50": 1,
        "textnv": "",
        "capitalization": 0,
        "spacing": 0,
        "mtn_mode": None,
        "mtn_dir": "right",
        "extreme": None
    }
Exemple #19
0
class NodeRule(SelfModifyingRule):
    master_node = None

    def __init__(self, node, nexus, is_reset=False):
        first = False
        if self.master_node is None:
            self.master_node = node
            self.nexus = nexus
            '''self.post is added to every entry in the mapping; 
            its purpose is to handle cancels; if it detects another of itself, 
            it does nothing; 
            
            but looking forward, won't it never find itself? 
            how is it that the node isn't constantly getting reset? '''
            self.post = ContextSeeker(forward=[
                L(S(["cancel"], lambda: self.reset_node(), consume=False),
                  S([self.master_node.spec], lambda: None, consume=False))
            ],
                                      rspec=self.master_node.spec)
            self.post.set_nexus(nexus)
            first = True
            SelfModifyingRule.__init__(self,
                                       self.master_node.spec,
                                       refresh=False)

        self.refresh(node, first, is_reset)

    def get_name(self):
        return self.master_node.spec

    def refresh(self, *args):
        self.node = args[0]
        first = args[1]
        is_reset = args[2]

        mapping = {}
        extras = []
        defaults = {}
        '''each child node gets turned into a mapping key/value'''
        for child in self.node.children:
            child.fill_out_rule(mapping, extras, defaults, self)
        if len(mapping) == 0:
            self.reset_node()
            for child in self.node.children:
                child.fill_out_rule(mapping, extras, defaults, self)
        else:
            if not first and not is_reset:  # sta#tus win#dow messaging
                choices = [
                    x.get_spec_and_base_and_node()[0]
                    for x in self.node.children
                ]
                #for choice in choices:
                #    self.nexus.intermediary.text(choice)

        self.extras = extras
        self.defaults = defaults
        self.reset(mapping)

    def change_node(self, node, reset=False):
        self.refresh(node, False, reset)

    def reset_node(self):
        if self.node is not self.master_node:
            self.change_node(self.master_node, True)
Exemple #20
0
    def test_actions_cleaned(self):
        '''these test functions should stay in sync with the clean methods for each stack action'''
        def registered_is_clean(r):
            return r.dragonfly_data is None and r.base is None
        def seeker_is_clean(s):
            result = True
            levels = []
            if s.back is not None: levels += s.back
            if s.forward is not None: levels += s.forward
            for context_level in levels:
                result &= context_level.dragonfly_data is None
            return result
        def asynchronous_is_clean(a):
            return a.closure is None
        
        '''mock words being the same doesn't matter for this test, or most tests'''
        alt = MockAlternative(u"my", u"spoken", u"words")
        
        '''make fake NullActions'''
        action1 = NullAction(rspec="barkley")
        action2 = NullAction(rspec="gaiden")
        action3 = NullAction(rspec="is")
        action4 = NullAction(rspec="awesome")
        action1.set_nexus(self.nexus)
        action2.set_nexus(self.nexus)
        action3.set_nexus(self.nexus)
        action4.set_nexus(self.nexus)
        '''make fake StackItemRegisteredActions'''
        sira1 = StackItemRegisteredAction(action1, {"_node":alt})
        sira2 = StackItemRegisteredAction(action2, {"_node":alt})
        sira3 = StackItemRegisteredAction(action3, {"_node":alt})
        sira4 = StackItemRegisteredAction(action4, {"_node":alt})
        
        '''should not be clean before it's executed'''
        self.assertFalse(registered_is_clean(sira1))
        
        '''add first one for backward seeker'''
        self.nexus.state.add(sira1)
        
        '''should be clean as soon as it's executed'''
        self.assertTrue(registered_is_clean(sira1))
        
        '''make backward seeker'''
        back_seeker = ContextSeeker(back=[L(S(["minecraft"], Function(lambda: None)))])
        back_seeker.set_nexus(self.nexus)
        '''create backward seeker stack item'''
        stack_seeker = StackItemSeeker(back_seeker, {"_node":alt})
        '''add it'''
        self.nexus.state.add(stack_seeker)
        
        '''levels should be clean as soon as it's executed'''
        self.assertTrue(registered_is_clean(stack_seeker) and seeker_is_clean(stack_seeker))
        
        #
        
        '''make forward seeker'''
        forward_seeker = ContextSeeker(forward=[L(S(["cave"], Function(lambda: None))), 
                                                L(S(["story"], Function(lambda: None)))])
        forward_seeker.set_nexus(self.nexus)
        '''create context seeker stack item'''
        stack_seeker2 = StackItemSeeker(forward_seeker, {"_node":alt})
        '''add it'''
        self.nexus.state.add(stack_seeker2)
    
        self.nexus.state.add(sira2)
        '''levels should not be clean before seeker is executed'''
        self.assertFalse(registered_is_clean(stack_seeker2) or seeker_is_clean(stack_seeker2))

        self.nexus.state.add(sira3)
        '''levels should be clean as soon as it's executed'''
        self.assertTrue(registered_is_clean(stack_seeker2) and seeker_is_clean(stack_seeker2))
        
        #
        
        '''make asynchronous action'''
        asynchronous = AsynchronousAction([L(S(["eternal", "daughter", "awesome"], lambda: None))], 
                                          blocking=False)
        asynchronous.set_nexus(self.nexus)
        '''make StackItemAsynchronous'''
        sia1 = StackItemAsynchronous(asynchronous, {"_node":alt})
        '''add it'''
        self.nexus.state.add(sia1)
        
        '''closure should not be clean before asynchronous is executed'''
        self.assertFalse(registered_is_clean(sia1) or seeker_is_clean(sia1) or asynchronous_is_clean(sia1))
        
        self.nexus.state.add(sira4)
        
        '''closure should be clean after asynchronous is executed'''
        self.assertTrue(registered_is_clean(sia1) and seeker_is_clean(sia1) and asynchronous_is_clean(sia1))
Exemple #21
0
class Navigation(MergeRule):
    non = NavigationNon
    pronunciation = CCRMerger.CORE[1]

    mapping = {
    # "periodic" repeats whatever comes next at 1-second intervals until "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, nexus=_NEXUS)))
                                                   ], time_in_seconds=0.2, repetitions=50, rdescript="Fill" ),
    "jump in":                      AsynchronousAction([L(S(["cancel"], context.nav, ["right", "(~[~{~<"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: In" ),
    "jump out":                     AsynchronousAction([L(S(["cancel"], context.nav, ["right", ")~]~}~>"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Out" ),
    "jump back":                    AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))
                                                   ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Back" ),
    "jump back in":                 AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))
                                                   ], finisher=Key("right"),
                                                      time_in_seconds=0.1,
                                                      repetitions=50,
                                                      rdescript="Jump: Back In" ),

    # keyboard shortcuts
    'save':                         R(Key("c-s"), rspec="save", rdescript="Save"),
    'shock [<nnavi50>]':            R(Key("enter"), rspec="shock", rdescript="Enter")* Repeat(extra="nnavi50"),

    "(<mtn_dir> | <mtn_mode> [<mtn_dir>]) [(<nnavi500> | <extreme>)]": R(Function(textformat.master_text_nav), rdescript="Keyboard Text Navigation"),

    "stoosh [<nnavi500>]":          R(Key("c-c")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"),
    "cut [<nnavi500>]":             R(Key("c-x")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="cut", rdescript="Cut"),
    "spark [<nnavi500>]":           R(Function(navigation.drop, nexus=_NEXUS), rspec="spark", rdescript="Paste"),

    "deli [<nnavi50>]":             R(Key("del/5"), rspec="deli", rdescript="Delete") * Repeat(extra="nnavi50"),
    "clear [<nnavi50>]":            R(Key("backspace/5:%(nnavi50)d"), rspec="clear", rdescript="Backspace"),
    SymbolSpecs.CANCEL:             R(Key("escape"), rspec="cancel", rdescript="Cancel Action"),


    "shackle":                      R(Key("home/5, s-end"), rspec="shackle", rdescript="Select Line"),
    "(tell | tau) <semi>":          R(Function(navigation.next_line), rspec="tell dock", rdescript="Complete Line"),
    "duple [<nnavi50>]":            R(Key("escape, home, s-end, c-c, end, enter, c-v"), rspec="duple", rdescript="Duplicate Line") * Repeat(extra="nnavi50"),
    "Kraken":                       R(Key("c-space"), rspec="Kraken", rdescript="Control Space"),

    # text formatting
    "set format (<capitalization> <spacing> | <capitalization> | <spacing>) (bow|bowel)":  R(Function(textformat.set_text_format), rdescript="Set Text Format"),
    "clear caster formatting":      R(Function(textformat.clear_text_format), rdescript="Clear Caster Formatting"),
    "peek format":                  R(Function(textformat.peek_text_format), rdescript="Peek Format"),
    "(<capitalization> <spacing> | <capitalization> | <spacing>) (bow|bowel) <textnv> [brunt]":  R(Function(textformat.master_format_text), rdescript="Text Format"),
    "format <textnv>":              R(Function(textformat.prior_text_format), rdescript="Last Text Format"),
    "<word_limit> format <textnv>": R(Function(textformat.partial_format_text), rdescript="Partial Text Format"),
    "dredge":                       R(Key("a-tab"), rdescript="Alt-Tab"),

    }

    extras = [
        IntegerRefST("nnavi50", 1, 50),
        IntegerRefST("nnavi500", 1, 500),
        Dictation("textnv"),
        Choice("capitalization", {
            "yell": 1,
            "tie": 2,
            "Gerrish": 3,
            "sing": 4,
            "laws": 5
        }),
        Choice("spacing", {
            "gum": 1,
            "gun": 1,
            "spine": 2,
            "snake": 3
        }),
        Choice("semi", {
            "dock": ";",
            "doc": ";",
            "sink": ""
        }),
        Choice("word_limit", {
            "single": 1,
            "double": 2,
            "triple": 3,
            "Quadra": 4
        }),
        navigation.TARGET_CHOICE,
        navigation.get_direction_choice("mtn_dir"),
        Choice("mtn_mode", {
            "shin": "s",
            "queue": "cs",
            "fly": "c",
        }),
        Choice("extreme", {
            "Wally": "way",
        }),
    ]

    defaults = {
        "nnavi500": 1,
        "nnavi50": 1,
        "textnv": "",
        "capitalization": 0,
        "spacing": 0,
        "mtn_mode": None,
        "mtn_dir": "right",
        "extreme": None
    }
Exemple #22
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}