예제 #1
0
 def wait(self, pattern, timeout=10.0):
     """Wait till pattern is found or time is out (default: 10s)."""
     t = time.time() + timeout
     while time.time() < t:
         ret = self.exists(pattern)
         if ret:
             return ret
         time.sleep(0.2)
     raise errors.ImageNotFoundError('Not found image %s' %(pattern,))
예제 #2
0
파일: mixin.py 프로젝트: zzzyw-work/ATX
 def wait_gone(self, pattern, timeout=10.0, safe=False, **match_kwargs):
     t = time.time() + timeout
     while time.time() < t:
         ret = self.exists(pattern, **match_kwargs)
         if not ret:
             return True
         time.sleep(0.2)
     if not safe:
         raise errors.ImageNotFoundError('Image not gone %s' %(pattern,))
예제 #3
0
파일: mixin.py 프로젝트: zzzyw-work/ATX
 def wait(self, pattern, timeout=10.0, safe=False, **match_kwargs):
     """Wait till pattern is found or time is out (default: 10s)."""
     t = time.time() + timeout
     while time.time() < t:
         ret = self.exists(pattern, **match_kwargs)
         if ret:
             return ret
         time.sleep(0.2)
     if not safe:
         raise errors.ImageNotFoundError('Not found image %s' %(pattern,))
예제 #4
0
    def click_image(self,
                    pattern,
                    timeout=20.0,
                    action='click',
                    safe=False,
                    desc=None,
                    **match_kwargs):
        """Simulate click according image position

        Args:
            - pattern (str or Pattern): filename or an opencv image object.
            - timeout (float): if image not found during this time, ImageNotFoundError will raise.
            - action (str): click or long_click
            - safe (bool): if safe is True, Exception will not raise and return None instead.
            - method (str): image match method, choice of <template|sift>

        Returns:
            None

        Raises:
            ImageNotFoundError: An error occured when img not found in current screen.
        """
        pattern = self.pattern_open(pattern)
        log.info('click image:%s %s', desc or '', pattern)
        start_time = time.time()
        found = False
        point = None
        while time.time() - start_time < timeout:
            point = self.match(pattern, **match_kwargs)
            if point is None:
                sys.stdout.write('.')
                sys.stdout.flush()
                continue

            log.debug('confidence: %s', point.confidence)
            if not point.matched:
                log.info('Ignore confidence: %s', point.confidence)
                continue

            func = getattr(self, action)
            func(*point.pos)

            found = True
            break
        sys.stdout.write('\n')

        if not found:
            if safe:
                log.info("Image(%s) not found, safe=True, skip", pattern)
                return None
            raise errors.ImageNotFoundError('Not found image %s' % (pattern, ))

        # FIXME(ssx): maybe this function is too complex
        return point  #collections.namedtuple('X', ['pattern', 'point'])(pattern, point)
예제 #5
0
    def click_image(self, pattern, timeout=20.0):
        """Simulate click according image position

        Args:
            - pattern (str or Pattern): filename or an opencv image object.
            - timeout (float): if image not found during this time, ImageNotFoundError will raise.
            - wait_change (bool): Depreciated, wait until background image changed.

        Returns:
            None

        Raises:
            ImageNotFoundError: An error occured when img not found in current screen.
        """
        pattern = self.pattern_open(pattern)
        log.info('click image: %s', pattern)
        start_time = time.time()
        found = False
        point = None
        while time.time() - start_time < timeout:
            point = self.match(pattern)
            if point is None:
                sys.stdout.write('.')
                sys.stdout.flush()
                continue

            log.debug('confidence: %s', point.confidence)
            if pattern.threshold:
                if point.confidence < pattern.threshold:
                    log.info('confidence %f below threshold %f',
                             point.confidence, pattern.threshold)
                    continue
            else:
                if not point.matched:
                    log.info('Ignore confidence: %s', point.confidence)
                    continue

            self.touch(*point.pos)
            # self._trigger_event(consts.EVENT_UIAUTO_CLICK, point)
            found = True
            break
        sys.stdout.write('\n')

        if not found:
            raise errors.ImageNotFoundError('Not found image %s' % (pattern, ))

        # FIXME(ssx): maybe this function is too complex
        return point  #collections.namedtuple('X', ['pattern', 'point'])(pattern, point)
예제 #6
0
    def click_image(self, pattern, timeout=20.0, wait_change=False):
        """Simulate click according image position

        Args:
            - pattern (str or Pattern): filename or an opencv image object.
            - timeout (float): if image not found during this time, ImageNotFoundError will raise.
            - wait_change (bool): wait until background image changed.

        Returns:
            None

        Raises:
            ImageNotFoundError: An error occured when img not found in current screen.
        """
        pattern = self.pattern_open(pattern)
        search_img = pattern.image
        log.info('click image: %s', pattern)
        start_time = time.time()
        found = False
        while time.time() - start_time < timeout:
            point = self.match(search_img)
            if point is None:
                sys.stdout.write('.')
                sys.stdout.flush()
                continue
            if not point.matched:
                log.debug('Ignore confidence: %s', point.confidence)
                continue
            log.debug('confidence: %s', point.confidence)
            self.touch(*point.pos)
            self._trigger_event(consts.EVENT_UIAUTO_CLICK, point)
            found = True
            break
        sys.stdout.write('\n')

        # wait until click area not same
        if found and wait_change:
            start_time = time.time()
            while time.time() - start_time < timeout:
                # screen_img = self.screenshot()
                ret = self.match(search_img)
                if ret is None:
                    break
        if not found:
            raise errors.ImageNotFoundError('Not found image %s' % (pattern, ))
예제 #7
0
    def click_image(self,
                    pattern,
                    timeout=20.0,
                    action='click',
                    safe=False,
                    desc=None,
                    delay=None,
                    **match_kwargs):
        pattern = self.pattern_open(pattern)
        log.info('click image:%s %s', desc or '', pattern)
        start_time = time.time()
        found = False
        point = None
        while time.time() - start_time < timeout:
            point = self.match(pattern, **match_kwargs)
            if point is None:
                continue

            log.debug('confidence: %s', point.confidence)
            if not point.matched:
                log.info('Ignore confidence: %s', point.confidence)
                continue

            # wait for program ready
            if delay and delay > 0:
                self.delay(delay)

            func = getattr(self, action)
            func(*point.pos)

            found = True
            break

        if not found:
            if safe:
                log.info("Image(%s) not found, safe=True, skip", pattern)
                return None
            raise errors.ImageNotFoundError('Not found image %s' % pattern,
                                            point)

        return point  # collections.namedtuple('X', ['pattern', 'point'])(pattern, point)