def wait_for_activate_and_press(self, index, timeout, step=0.5):
        states_to_wait = []
        for state in STATES_ACTIVE:
            if state in self.states:
                states_to_wait.append(
                    (self.states[state][0], self.states[state][1], True))

        assert bool(
            states_to_wait
        ), "Button has not active states in list of possible states"

        result = ImageProcessor().wait_for_one_of(states_to_wait, timeout)
        if not result.found:
            raise RuntimeError(
                "Button was not found on screen or is in unknown state")

        self.click_center(result.get_pos(), 1)
Exemple #2
0
    def _get_coordinates(self):
        screen = ImageProcessor()._get_screenshot()
        images_to_find = self.states.values()
        coords = ImageProcessor().find_one_of(images_to_find, screen=screen)
        if coords is not None:
            if STATE_DISABLED in self.states and self.states[STATE_DISABLED][
                    0] is coords.image:
                image_info = ("disabled", coords.image)
                screen_info = ("screen", coords.screen)
                ErrorHandler().report_warning(
                    "Trying to press disabled button!", image_info,
                    screen_info)
            return coords.get_pos()

        #no one state is found
        images = []
        images.append(("screen", screen))
        for state_name, state_info in sorted(self.states.items()):
            images.append((state_name, state_info[0]))

        msg = "Button not found on screen in all possible states"
        ErrorHandler().report_error(msg, *images)
        raise RuntimeError(msg)