Пример #1
0
    def run(self) -> None:
        self.sic.start()
        self.sic.set_language('en-US')

        action_runner = ActionRunner(self.sic)
        # This might give an SSL-exception on Pepper's tablet the first time; just click OK on the tablet in that case.
        action_runner.run_waiting_action(
            'tablet_open', additional_callback=self.tablet_open_callback)
        sleep(1)  # FIXME: Pepper needs some extra time for some reason

        text = self.get_text('Hello, world!')
        button = self.get_button('Done')
        html = self.get_header() + self.get_body(text +
                                                 button) + self.get_footer()
        action_runner.run_action('tablet_show', html)
    def run(self):
        self.sic.start()
        self.sic.set_language('en-US')

        #################
        # Action        #
        #################
        # Create an action that can be executed when needed and reused
        hello_action = Action(self.sic.say, 'Hello, Action!', callback=self.hello_action_callback,
                              lock=self.hello_action_lock)
        hello_action.perform().wait()  # perform() returns the lock, so you can immediately call wait() on it.
        hello_action.perform().wait()  # you can reuse an action.

        #################
        # Action Factory#
        #################
        # Use the ActionFactory to build actions. You can build actions with a lock build inside of them by
        # using build_waiting_action(). It saves you from keeping track of your locks.
        # build_action() and build_waiting_action() use the name of SIC method instead of an explicit reference to it
        # as input. For example build_action('say', ...) instead of build_action(self.sic.say, ...).
        action_factory = ActionFactory(self.sic)
        hello_action_factory = action_factory.build_waiting_action('say', 'Hello, Action Factory!',
                                                                   additional_callback=self.hello_action_factory_callback)
        hello_action_factory.perform().wait()

        #################
        # Action Runner #
        #################
        # With an ActionRunner you can run regular and waiting actions right away or load them to run them in parallel.
        # When running the loaded actions, it will wait automatically for all loaded waiting actions to finish.
        action_runner = ActionRunner(self.sic)
        action_runner.run_waiting_action('say', 'Hello, Action Runner!',
                                         additional_callback=self.hello_action_runner_callback)
        # run_waiting_action('say', ...) waits to finish talking before continuing

        # The following actions will run in parallel.
        #action_runner.load_waiting_action('wake_up')
        action_runner.load_waiting_action('set_eye_color', 'green')
        action_runner.load_waiting_action('say', 'I am standing up now')
        action_runner.run_loaded_actions()  # If you want to keep an action sequence for reuse, add False as input.
        # run_loaded_actions() will wait automatically before all loaded waiting actions (not regular actions) to finish
        # before continuing

        action_runner.run_action('say', 'I will start sitting down as I say this. Because I am not a waiting action')
        action_runner.run_action('set_eye_color', 'white')
        action_runner.run_waiting_action('rest')

        self.sic.stop()