Esempio n. 1
0
    def test_asynchronous_finisher(self):
        '''make termination action'''
        termination = NullAction(rspec="kill")
        termination.set_nexus(self.nexus)
        alt = MockAlternative(u"my", u"spoken", u"words")
        sira = StackItemRegisteredAction(termination, {"_node": alt})
        '''setup function for asynchronous finisher'''
        mutable_integer = {"value": 0}

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

        #
        '''make asynchronous action'''
        asynchronous = AsynchronousAction([L(S(["kill"], lambda: None))],
                                          blocking=False,
                                          finisher=Function(increment))
        asynchronous.set_nexus(self.nexus)
        '''make StackItemAsynchronous'''
        sia1 = StackItemAsynchronous(asynchronous, {"_node": alt})
        '''add it'''
        self.nexus.state.add(sia1)

        #

        self.nexus.state.add(sira)
        '''finisher should be executed when asynchronous finishes'''
        self.assertEqual(mutable_integer["value"], 1)
Esempio n. 2
0
 def test_cancel(self):
     mutable_integer = {"value": 0}
     def increment():
         mutable_integer["value"]+=1
     
     '''make fake AsynchronousAction'''
     context_set = S(["test", "words"], increment)
     unused_context_set = S(["other"], Text, "words")
     context_level = L(context_set, unused_context_set)
     aa1 = AsynchronousAction([context_level], 
                             time_in_seconds=0.2, 
                             repetitions=20,
                             blocking=False)
     aa1.set_nexus(self.nexus)
     
     '''make fake StackItemAsynchronous'''
     alt = MockAlternative(u"gray", u"fox")
     sia1 = StackItemAsynchronous(aa1, {"_node":alt})# the dictionary is fake Dragonfly data
     '''add it'''
     self.nexus.state.add(sia1)
     
     '''make fake canceling RegisteredAction'''
     cancel = R(NullAction(), rspec="test")
     cancel.set_nexus(self.nexus)
     '''make fake StackItemRegisteredAction'''
     alt2 = MockAlternative(u"my", u"spoken", u"words")
     sira1 = StackItemRegisteredAction(cancel, {"_node":alt2})
     '''add it'''
     self.nexus.state.add(sira1)
     
     '''AsynchronousAction should have executed exactly once, 
     when it was added, then immediately gotten canceled'''
     self.assertEqual(mutable_integer["value"], 1)
Esempio n. 3
0
    def test_cancel(self):
        mutable_integer = {"value": 0}

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

        '''make fake AsynchronousAction'''
        context_set = S(["test", "words"], increment)
        unused_context_set = S(["other"], Text, "words")
        context_level = L(context_set, unused_context_set)
        aa1 = AsynchronousAction([context_level],
                                 time_in_seconds=0.2,
                                 repetitions=20,
                                 blocking=False)
        aa1.set_nexus(self.nexus)
        '''make fake StackItemAsynchronous'''
        alt = MockAlternative(u"gray", u"fox")
        sia1 = StackItemAsynchronous(
            aa1, {"_node": alt})  # the dictionary is fake Dragonfly data
        '''add it'''
        self.nexus.state.add(sia1)
        '''make fake canceling RegisteredAction'''
        cancel = R(NullAction(), rspec="test")
        cancel.set_nexus(self.nexus)
        '''make fake StackItemRegisteredAction'''
        alt2 = MockAlternative(u"my", u"spoken", u"words")
        sira1 = StackItemRegisteredAction(cancel, {"_node": alt2})
        '''add it'''
        self.nexus.state.add(sira1)
        '''AsynchronousAction should have executed exactly once, 
        when it was added, then immediately gotten canceled'''
        self.assertEqual(mutable_integer["value"], 1)
Esempio n. 4
0
 def __init__(self, receiver, rspec="default", rdescript="unnamed command (BA)", repetitions=60,
              box_type=settings.QTYPE_DEFAULT, box_settings={}, log_failure=False):
     _ = {"tries": 0}
     self._ = _ # signals to the stack to cease waiting, return True terminates
     def check_for_response():
         try:
             _data = self.nexus().comm.get_com("hmc").get_message()
         except Exception:
             if log_failure: utilities.simple_log()
             _["tries"]+=1
             if _["tries"]>9: return True # try 10 times max if there's no Homonculus response
             else: return False
         if _data is None: return False
         try:
             _data.append(_["dragonfly_data"]) # pass dragonfly data into receiver function
             _["dragonfly_data"] = None
             receiver(_data)
         except Exception:
             if log_failure: utilities.simple_log()
         return True
         
     AsynchronousAction.__init__(self, # cannot block, if it does, it'll block its own confirm command
                                 [L(S(["cancel"], check_for_response, None))], 
                                 1, repetitions, rdescript, False)
     self.rspec = rspec
     self.box_type = box_type
     self.box_settings = box_settings # custom instructions for setting up the tk window ("Homunculus")
     self.log_failure = log_failure
Esempio n. 5
0
    def __init__(self,
                 base,
                 rspec="default",
                 rdescript="unnamed command (CA)",
                 instructions="instructions missing",
                 nexus=None):
        self.set_nexus(nexus)
        on_complete = AsynchronousAction.hmc_complete(
            lambda data: receive_response(data), self.nexus())
        AsynchronousAction.__init__(
            self, [L(S(["cancel"], on_complete))], 1, 60, rdescript, False
        )  # cannot block, if it does, it'll block its own confirm command

        self.base = base
        self.rspec = rspec
        self.instructions = instructions

        mutable_integer = {"value": 0}

        def receive_response(
            data
        ):  # signals to the stack to cease waiting, return True terminates
            '''
            receives response from homunculus, uses it to
            stop the stack and tell the ConfirmAction how
            to execute
            '''
            mutable_integer["value"] = data["confirm"]

        self.mutable_integer = mutable_integer
Esempio n. 6
0
 def __init__(self, executable=None, title=None, time_in_seconds=1, repetitions=15, 
     rdescript="unnamed command (SFW)", blocking=False):
     assert executable!=None or title!=None, "SuperFocusWindow needs executable or title"
     def attempt_focus():
         for win in Window.get_all_windows():
             w=win
             found_match=True
             if title!=None:
                 found_match=title in w.title
             if found_match and executable!=None:
                 found_match=executable in w.executable
             if found_match:
                 try:
                     BringApp(w.executable).execute()
                 except Exception:
                     print("Unable to set focus:\ntitle: "+w.title+"\nexe: "+w.executable)
                 break
          
         # do not assume that it worked
         success = SuperFocusWindow.focus_was_success(title, executable)
         if not success:
             if title!=None:
                 print("title failure: ", title, w.title)
             if executable!=None:
                 print("executable failure: ", executable, w.executable, executable in w.executable)
         return success
         
     forward=[L(S(["cancel"], attempt_focus))]
     AsynchronousAction.__init__(self, forward, time_in_seconds=time_in_seconds, repetitions=repetitions, 
                                 rdescript=rdescript, blocking=blocking, 
                                 finisher=Function(lambda message: self.nexus().intermediary.text(message), message="SuperFocus Complete")+Key("escape"))
     self.show = False
Esempio n. 7
0
 def test_asynchronous_finisher(self):
     '''make termination action'''
     termination = NullAction(rspec="kill")
     termination.set_nexus(self.nexus)
     alt = MockAlternative(u"my", u"spoken", u"words")
     sira = StackItemRegisteredAction(termination, {"_node":alt})
     
     '''setup function for asynchronous finisher'''
     mutable_integer = {"value": 0}
     def increment():
         mutable_integer["value"] += 1
     
     #
     
     '''make asynchronous action'''
     asynchronous = AsynchronousAction([L(S(["kill"], lambda: None))], 
                                       blocking=False, 
                                       finisher=Function(increment))
     asynchronous.set_nexus(self.nexus)
     '''make StackItemAsynchronous'''
     sia1 = StackItemAsynchronous(asynchronous, {"_node":alt})
     '''add it'''
     self.nexus.state.add(sia1)
     
     #
     
     self.nexus.state.add(sira)
     '''finisher should be executed when asynchronous finishes'''
     self.assertEqual(mutable_integer["value"], 1)
Esempio n. 8
0
    def __init__(self,
                 executable=None,
                 title=None,
                 time_in_seconds=1,
                 repetitions=15,
                 rdescript="unnamed command (SFW)",
                 blocking=False):
        assert executable != None or title != None, "SuperFocusWindow needs executable or title"

        def attempt_focus():
            for win in Window.get_all_windows():
                w = win
                found_match = True
                if title != None:
                    found_match = title in w.title
                if found_match and executable != None:
                    found_match = executable in w.executable
                if found_match:
                    try:
                        # this is still broken
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0,
                            win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_TOPMOST, 0, 0, 0, 0,
                            win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
                        win32gui.SetWindowPos(
                            w.handle, win32con.HWND_NOTOPMOST, 0, 0, 0, 0,
                            win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE +
                            win32con.SWP_NOSIZE)
                        Key("alt").execute()
                        time.sleep(0.5)
                        win32gui.SetForegroundWindow(w.handle)
                        w.set_foreground()
                    except Exception:
                        utilities.report("Unable to set focus:\ntitle: " +
                                         w.title + "\nexe: " + w.executable)
                    break

            # do not assume that it worked
            success = SuperFocusWindow.focus_was_success(title, executable)
            if not success:
                if title != None:
                    print "title failure: ", title, w.title
                if executable != None:
                    print "executable failure: ", executable, w.executable, executable in w.executable
            return success

        forward = [L(S(["cancel"], attempt_focus))]
        AsynchronousAction.__init__(
            self,
            forward,
            time_in_seconds=time_in_seconds,
            repetitions=repetitions,
            rdescript=rdescript,
            blocking=blocking,
            finisher=Function(control.nexus().intermediary.text,
                              message="SuperFocus Complete") + Key("escape"))
        self.show = False
Esempio n. 9
0
def settings_window(nexus):
    h_launch.launch(settings.WXTYPE_SETTINGS)
    on_complete = AsynchronousAction.hmc_complete(
        lambda data: receive_settings(data), nexus)
    AsynchronousAction([L(S(["cancel"], on_complete))],
                       time_in_seconds=1,
                       repetitions=300,
                       blocking=False).execute()
Esempio n. 10
0
    def test_blocking(self):
        '''tests:
        1 - successful termination (queued actions execute immediately)
        2 - unsuccessful termination (queued actions are dropped)
        3 - cancellation (queued actions are dropped)
        '''

        for i in range(0, 3):
            '''make fake AsynchronousAction'''
            context_set = S(["cancel", "words"], NullAction())
            context_level = L(context_set)
            aa1 = AsynchronousAction([context_level],
                                     blocking=True)  # turn blocking on
            aa1.set_nexus(self.nexus)
            '''make fake StackItemAsynchronous'''
            alt = MockAlternative(u"run", u"blocker")
            sia1 = StackItemAsynchronous(
                aa1, {"_node": alt})  # the dictionary is fake Dragonfly data
            '''add it'''
            self.nexus.state.add(sia1)
            '''blocked function'''
            mutable_integer = {"value": 0}

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

            '''make fake incrementing RegisteredAction'''
            inc = R(Function(increment), rspec="inc")
            inc.set_nexus(self.nexus)
            '''make fake StackItemRegisteredAction'''
            alt2 = MockAlternative(u"my", u"spoken", u"words")
            sira1 = StackItemRegisteredAction(inc, {"_node": alt2})
            '''add it'''
            self.nexus.state.add(sira1)
            '''incrementing should be blocked at this point'''
            self.assertEqual(mutable_integer["value"], 0)

            if i == 0:
                '''incrementing should happen that moment of unblocking'''
                self.nexus.state.terminate_asynchronous(True)
                self.assertEqual(mutable_integer["value"], 1)
            elif i == 1:
                '''incrementing gets dropped'''
                self.nexus.state.terminate_asynchronous(False)
                self.assertEqual(mutable_integer["value"], 0)
            elif i == 2:
                '''make fake canceling RegisteredAction'''
                cancel = NullAction(rspec="cancel")
                cancel.set_nexus(self.nexus)
                '''make fake StackItemRegisteredAction'''
                alt3 = MockAlternative(u"my", u"cancel", u"words")
                sira2 = StackItemRegisteredAction(cancel, {"_node": alt3})
                '''add it'''
                self.nexus.state.add(sira2)
                '''incrementing gets dropped'''
                self.assertEqual(mutable_integer["value"], 0)
Esempio n. 11
0
 def __init__(self, base, rspec="default", rdescript="unnamed command (RA)"):
     mutable_integer = {"value": 0}
     def check_response(): # signals to the stack to cease waiting, return True terminates
         return mutable_integer["value"]!=0
     self.mutable_integer = mutable_integer
     AsynchronousAction.__init__(self, 
                                 [L(S(["cancel"], check_response, None))], 
                                 1, 60, rdescript, False)# cannot block, if it does, it'll block its own confirm command
     self.base = base
     self.rspec = rspec
Esempio n. 12
0
    def test_blocking(self):
        """tests:
        1 - successful termination (queued actions execute immediately)
        2 - unsuccessful termination (queued actions are dropped)
        3 - cancellation (queued actions are dropped)
        """

        for i in range(0, 3):
            """make fake AsynchronousAction"""
            context_set = S(["cancel", "words"], NullAction())
            context_level = L(context_set)
            aa1 = AsynchronousAction([context_level], blocking=True)  # turn blocking on
            aa1.set_nexus(self.nexus)
            """make fake StackItemAsynchronous"""
            alt = MockAlternative(u"run", u"blocker")
            sia1 = StackItemAsynchronous(aa1, {"_node": alt})  # the dictionary is fake Dragonfly data
            """add it"""
            self.nexus.state.add(sia1)

            """blocked function"""
            mutable_integer = {"value": 0}

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

            """make fake incrementing RegisteredAction"""
            inc = R(Function(increment), rspec="inc")
            inc.set_nexus(self.nexus)
            """make fake StackItemRegisteredAction"""
            alt2 = MockAlternative(u"my", u"spoken", u"words")
            sira1 = StackItemRegisteredAction(inc, {"_node": alt2})
            """add it"""
            self.nexus.state.add(sira1)
            """incrementing should be blocked at this point"""
            self.assertEqual(mutable_integer["value"], 0)

            if i == 0:
                """incrementing should happen that moment of unblocking"""
                self.nexus.state.terminate_asynchronous(True)
                self.assertEqual(mutable_integer["value"], 1)
            elif i == 1:
                """incrementing gets dropped"""
                self.nexus.state.terminate_asynchronous(False)
                self.assertEqual(mutable_integer["value"], 0)
            elif i == 2:
                """make fake canceling RegisteredAction"""
                cancel = NullAction(rspec="cancel")
                cancel.set_nexus(self.nexus)
                """make fake StackItemRegisteredAction"""
                alt3 = MockAlternative(u"my", u"cancel", u"words")
                sira2 = StackItemRegisteredAction(cancel, {"_node": alt3})
                """add it"""
                self.nexus.state.add(sira2)
                """incrementing gets dropped"""
                self.assertEqual(mutable_integer["value"], 0)
Esempio n. 13
0
 def chain_alias(self):
     text = read_highlighted(10)
     if text is not None:
         h_launch.launch(settings.QTYPE_INSTRUCTIONS, data="Enter_spec_for_command|")
         on_complete = AsynchronousAction.hmc_complete(
             lambda data: self.refresh(data[0].replace("\n", ""), text), self.nexus)
         AsynchronousAction(
             [L(S(["cancel"], on_complete))],
             time_in_seconds=0.5,
             repetitions=300,
             blocking=False).execute()
Esempio n. 14
0
def scan_directory(nexus):
    on_complete = AsynchronousAction.hmc_complete(lambda data: _scan_directory(data, nexus), nexus)
    h_launch.launch(settings.QTYPE_DIRECTORY)
    AsynchronousAction([L(S(["cancel"], on_complete))], 
                           time_in_seconds=0.5, 
                           repetitions=300, 
                           blocking=False).execute()
Esempio n. 15
0
    def __init__(self,
                 base,
                 rspec="default",
                 rdescript="unnamed command (RA)"):
        mutable_integer = {"value": 0}

        def check_response(
        ):  # signals to the stack to cease waiting, return True terminates
            return mutable_integer["value"] != 0

        self.mutable_integer = mutable_integer
        AsynchronousAction.__init__(
            self, [L(S(["cancel"], check_response, None))], 1, 60, rdescript,
            False
        )  # cannot block, if it does, it'll block its own confirm command
        self.base = base
        self.rspec = rspec
Esempio n. 16
0
 def chain_alias(self):
     text = read_highlighted(10)
     if text is not None:
         h_launch.launch(settings.QTYPE_INSTRUCTIONS, data="Enter_spec_for_command|")
         on_complete = AsynchronousAction.hmc_complete(lambda data: self.refresh(data[0].replace("\n", ""), text), self.nexus)
         AsynchronousAction([L(S(["cancel"], on_complete, None))], 
                            time_in_seconds=0.5, 
                            repetitions=300, 
                            blocking=False).execute()
Esempio n. 17
0
File: dev.py Progetto: mrob95/caster
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": ""}
Esempio n. 18
0
 def record_from_history(self):
     # save the list as it was when the command was spoken
     self.nexus.preserved = self.nexus.history[:]
     
     # format for display
     formatted = ""
     for t in self.nexus.preserved:
         for w in t:
             formatted += w.split("\\")[0] + "[w]"
         formatted += "[s]"
     
     # use a response window to get a spec and word sequences for the new macro
     h_launch.launch(settings.QTYPE_RECORDING, data=formatted)
     on_complete = AsynchronousAction.hmc_complete(lambda data: self.add_recorded_macro(data), self.nexus)
     AsynchronousAction([L(S(["cancel"], on_complete))], 
                        time_in_seconds=0.5, 
                        repetitions=300, 
                        blocking=False).execute()
Esempio n. 19
0
File: _hmc.py Progetto: seekM/caster
def settings_window(nexus):
    h_launch.launch(settings.WXTYPE_SETTINGS)
    on_complete = AsynchronousAction.hmc_complete(lambda data: receive_settings(data),
                                                  nexus)
    AsynchronousAction(
        [L(S(["cancel"], on_complete))],
        time_in_seconds=1,
        repetitions=300,
        blocking=False).execute()
Esempio n. 20
0
    def __init__(self,
                 receiver,
                 rspec="default",
                 rdescript="unnamed command (BA)",
                 repetitions=60,
                 box_type=settings.QTYPE_DEFAULT,
                 box_settings={},
                 log_failure=False):
        _ = {"tries": 0}
        self._ = _  # signals to the stack to cease waiting, return True terminates

        def check_for_response():
            try:
                _data = self.nexus().comm.get_com("hmc").get_message()
            except Exception:
                if log_failure: utilities.simple_log()
                _["tries"] += 1
                if _["tries"] > 9:
                    return True  # try 10 times max if there's no Homonculus response
                else:
                    return False
            if _data is None: return False
            try:
                _data.append(_["dragonfly_data"]
                             )  # pass dragonfly data into receiver function
                _["dragonfly_data"] = None
                receiver(_data)
            except Exception:
                if log_failure: utilities.simple_log()
            return True

        AsynchronousAction.__init__(
            self,  # cannot block, if it does, it'll block its own confirm command
            [L(S(["cancel"], check_for_response))],
            1,
            repetitions,
            rdescript,
            blocking=False)
        self.rspec = rspec
        self.box_type = box_type
        self.box_settings = box_settings  # custom instructions for setting up the tk window ("Homunculus")
        self.log_failure = log_failure
Esempio n. 21
0
 def __init__(self, base, rspec="default", rdescript="unnamed command (CA)", instructions="instructions missing", nexus=None):
     self.set_nexus(nexus)
     on_complete = AsynchronousAction.hmc_complete(lambda data: receive_response(data), self.nexus())
     AsynchronousAction.__init__(self, 
                                 [L(S(["cancel"], on_complete, None))], 
                                 1, 60, rdescript, False)# cannot block, if it does, it'll block its own confirm command
     
     self.base = base
     self.rspec = rspec
     self.instructions = instructions
     
     
     mutable_integer = {"value": 0}
     def receive_response(data): # signals to the stack to cease waiting, return True terminates
         '''
         receives response from homunculus, uses it to
         stop the stack and tell the ConfirmAction how
         to execute
         '''
         mutable_integer["value"] = data["confirm"]
     self.mutable_integer = mutable_integer
Esempio n. 22
0
 def __init__(self, executable=None, title=None, time_in_seconds=1, repetitions=15, 
     rdescript="unnamed command (SFW)", blocking=False):
     assert executable!=None or title!=None, "SuperFocusWindow needs executable or title"
     def attempt_focus():
         for win in Window.get_all_windows():
             w=win
             found_match=True
             if title!=None:
                 found_match=title in w.title
             if found_match and executable!=None:
                 found_match=executable in w.executable
             if found_match:
                 try:
                     # this is still broken
                     win32gui.SetWindowPos(w.handle,win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)  
                     win32gui.SetWindowPos(w.handle,win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)  
                     win32gui.SetWindowPos(w.handle,win32con.HWND_NOTOPMOST, 0, 0, 0, 0, win32con.SWP_SHOWWINDOW + win32con.SWP_NOMOVE + win32con.SWP_NOSIZE)
                     Key("alt").execute()
                     time.sleep(0.5)
                     win32gui.SetForegroundWindow(w.handle)
                     w.set_foreground()
                 except Exception:
                     utilities.report("Unable to set focus:\ntitle: "+w.title+"\nexe: "+w.executable)
                 break
          
         # do not assume that it worked
         success = SuperFocusWindow.focus_was_success(title, executable)
         if not success:
             if title!=None:
                 print "title failure: ", title, w.title
             if executable!=None:
                 print "executable failure: ", executable, w.executable, executable in w.executable
         return success
         
     forward=[L(S(["cancel"], attempt_focus))]
     AsynchronousAction.__init__(self, forward, time_in_seconds=time_in_seconds, repetitions=repetitions, 
                                 rdescript=rdescript, blocking=blocking, 
                                 finisher=Function(control.nexus().intermediary.text, message="SuperFocus Complete")+Key("escape"))
     self.show = False
     
Esempio n. 23
0
    def _create_asynchronous(self, n):
        if len(self.nexus.history) == 0:
            return

        last_utterance_index = 1
        if settings.WSR:  # ContextStack adds the word to history before executing it
            if len(self.nexus.history) == 1: return
            last_utterance_index = 2

        utterance = [
            str(x) for x in " ".join(self.nexus.history[
                len(self.nexus.history) - last_utterance_index]).split()
        ]
        if utterance[0] == "again": return
        forward = [L(S(["cancel"], lambda: self._repeat(utterance)))]
        AsynchronousAction(forward,
                           rdescript="Repeat Last Action",
                           time_in_seconds=0.2,
                           repetitions=int(n),
                           blocking=False).execute()
Esempio n. 24
0
def settings_window(nexus):
    if not utilities.window_exists(None, settings.STATUS_WINDOW_TITLE + settings.SOFTWARE_VERSION_NUMBER):
        h_launch.launch(settings.WXTYPE_SETTINGS)
        on_complete = AsynchronousAction.hmc_complete(lambda data: receive_settings(data), nexus)
        AsynchronousAction([L(S(["cancel"], on_complete))], time_in_seconds=1, repetitions=300, blocking=False).execute()
Esempio n. 25
0
 def __init__(self, action, t=3):
     AsynchronousAction.__init__(self, [L(S(["cancel"], action))], t, 100,
                                 "UC", False, None)
     self.show = True
Esempio n. 26
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))
Esempio n. 27
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
    }
Esempio n. 28
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}
Esempio n. 29
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
    }
Esempio n. 30
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))
Esempio n. 31
0
class NavigationNon(MappingRule):
    mapping = {
        "<direction> <time_in_seconds>":
        AsynchronousAction(
            [L(S(["cancel"], Key("%(direction)s"), consume=False))],
            repetitions=1000,
            blocking=False),
        "erase multi clipboard":
        R(Function(navigation.erase_multi_clipboard, nexus=_NEXUS),
          rdescript="Erase Multi Clipboard"),
        "find":
        R(Key("c-f"), rdescript="Find"),
        "find next [<n>]":
        R(Key("f3"), rdescript="Find Next") * Repeat(extra="n"),
        "find prior [<n>]":
        R(Key("s-f3"), rdescript="Find Prior") * Repeat(extra="n"),
        "find everywhere":
        R(Key("cs-f"), rdescript="Find Everywhere"),
        "replace":
        R(Key("c-h"), rdescript="Replace"),
        "(F to | F2)":
        R(Key("f2"), rdescript="Key: F2"),
        "(F six | F6)":
        R(Key("f6"), rdescript="Key: F6"),
        "(F nine | F9)":
        R(Key("f9"), rdescript="Key: F9"),
        "[show] context menu":
        R(Key("s-f10"), rdescript="Context Menu"),
        'kick':
        R(Function(navigation.kick, nexus=_NEXUS),
          rdescript="Mouse: Left Click"),
        'kick mid':
        R(Function(navigation.kick_middle, nexus=_NEXUS),
          rdescript="Mouse: Middle Click"),
        'psychic':
        R(Function(navigation.kick_right, nexus=_NEXUS),
          rdescript="Mouse: Right Click"),
        '(kick double|double kick)':
        R(Function(navigation.kick, nexus=_NEXUS) * Repeat(2),
          rdescript="Mouse: Double Click"),
        "shift right click":
        R(Key("shift:down") + Mouse("right") + Key("shift:up"),
          rdescript="Mouse: Shift + Right Click"),
        "curse <direction> [<direction2>] [<nnavi500>] [<dokick>]":
        R(Function(navigation.curse), rdescript="Curse"),
        "scree <direction> [<nnavi500>]":
        R(Function(navigation.wheel_scroll), rdescript="Wheel Scroll"),
        "colic":
        R(Key("control:down") + Mouse("left") + Key("control:up"),
          rdescript="Mouse: Ctrl + Left Click"),
        "garb [<nnavi500>]":
        R(Mouse("left") + Mouse("left") + Key("c-c") +
          Function(navigation.clipboard_to_file, nexus=_NEXUS),
          rdescript="Highlight @ Mouse + Copy"),
        "drop [<nnavi500>]":
        R(Mouse("left") + Mouse("left") +
          Function(navigation.drop, nexus=_NEXUS),
          rdescript="Highlight @ Mouse + Paste"),
        "sure stoosh":
        R(Key("c-c"), rdescript="Simple Copy"),
        "sure cut":
        R(Key("c-x"), rdescript="Simple Cut"),
        "sure spark":
        R(Key("c-v"), rdescript="Simple Paste"),
        "undo [<n>]":
        R(Key("c-z"), rdescript="Undo") * Repeat(extra="n"),
        "redo [<n>]":
        R(Key("c-y"), rdescript="Redo") * Repeat(extra="n"),
        "refresh":
        R(Key("c-r"), rdescript="Refresh"),
        "maxiwin":
        R(Key("w-up"), rdescript="Maximize Window"),
        "move window":
        R(Key("a-space, r, a-space, m"), rdescript="Move Window"),
        "window (left | lease) [<n>]":
        R(Key("w-left"), rdescript="Window Left") * Repeat(extra="n"),
        "window (right | ross) [<n>]":
        R(Key("w-right"), rdescript="Window Right") * Repeat(extra="n"),
        "monitor (left | lease) [<n>]":
        R(Key("sw-left"), rdescript="Monitor Left") * Repeat(extra="n"),
        "monitor (right | ross) [<n>]":
        R(Key("sw-right"), rdescript="Monitor Right") * Repeat(extra="n"),
        "(next | prior) window":
        R(Key("ca-tab, enter"), rdescript="Next Window"),
        "switch (window | windows)":
        R(Key("ca-tab"), rdescript="Switch Window") * Repeat(extra="n"),
        "next tab [<n>]":
        R(Key("c-pgdown"), rdescript="Next Tab") * Repeat(extra="n"),
        "prior tab [<n>]":
        R(Key("c-pgup"), rdescript="Previous Tab") * Repeat(extra="n"),
        "close tab [<n>]":
        R(Key("c-w/20"), rdescript="Close Tab") * Repeat(extra="n"),
        "elite translation <text>":
        R(Function(alphanumeric.elite_text), rdescript="1337 Text"),
    }

    extras = [
        Dictation("text"),
        Dictation("mim"),
        IntegerRefST("n", 1, 50),
        IntegerRefST("nnavi500", 1, 500),
        Choice(
            "time_in_seconds", {
                "super slow": 5,
                "slow": 2,
                "normal": 0.6,
                "fast": 0.1,
                "superfast": 0.05
            }),
        navigation.get_direction_choice("direction"),
        navigation.get_direction_choice("direction2"),
        navigation.TARGET_CHOICE,
        Choice("dokick", {
            "kick": 1,
            "psychic": 2
        }),
        Choice("wm", {
            "ex": 1,
            "tie": 2
        }),
    ]
    defaults = {
        "n": 1,
        "mim": "",
        "nnavi500": 1,
        "direction2": "",
        "dokick": 0,
        "text": "",
        "wm": 2
    }
Esempio n. 32
0
 def __init__(self, action, t=3):
     AsynchronousAction.__init__(self, [L(S(["cancel"], action))], t, 100, "UC", False, None)
     self.show = True