示例#1
0
文件: history.py 项目: lahwran/Caster
    def _record_from_history(self):
        """
        Inspects the recognition history, formats it for the GUI component which
        lets the user choose which of their prior utterances will become the
        Playbacks for the new command.
        """

        # save the list as it was when the command was spoken
        self._preserved = self._history[:]

        # format for display
        formatted = ""
        for t in self._preserved:
            for w in t:
                formatted += w.split("\\")[0] + "[w]"
            formatted += "[s]"
        formatted = formatted.encode("unicode_escape")
        # 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))
        AsynchronousAction([L(S(["cancel"], on_complete))],
                           time_in_seconds=0.5,
                           repetitions=300,
                           blocking=False).execute()
示例#2
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))
        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
示例#3
0
def settings_window():
    h_launch.launch(settings.WXTYPE_SETTINGS)
    on_complete = AsynchronousAction.hmc_complete(lambda data: receive_settings(data))
    AsynchronousAction(
        [L(S(["cancel"], on_complete))],
        time_in_seconds=1,
        repetitions=300,
        blocking=False).execute()
示例#4
0
    def _alias(self, spec):
        """
        Takes highighted text and makes a Text action of it and the passed spec.
        Uses an AsynchronousAction to wait for a GUI to get the aliased word.

        :param spec: str
        :return:
        """
        text = BaseAliasRule._read_highlighted(10)
        spec = str(spec)
        if text is not None:
            if spec:
                self._refresh(spec, str(text))
            else:
                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))
                AsynchronousAction(
                    [L(S(["cancel"], on_complete))],
                    time_in_seconds=0.5,
                    repetitions=300,
                    blocking=False).execute()