def image_vanish(pattern: Pattern, timeout: float = None, region: Rectangle = None) -> None or bool: """ Search if an image is NOT in a Region or full screen. :param Pattern pattern: Name of the searched image. :param timeout: Number as maximum waiting time in seconds. :param Region region: Region object. :return: Location. """ if not _is_pattern_size_correct(pattern, region): return None pattern_found = True start_time = datetime.datetime.now() end_time = start_time + datetime.timedelta(seconds=timeout) while pattern_found and start_time < end_time: time_remaining = end_time - start_time logger.debug("Image vanish: {} - {} seconds remaining".format( pattern.get_filename(), time_remaining)) image_found = match_template(pattern, region, MatchTemplateType.SINGLE) if len(image_found) == 0: pattern_found = False else: pattern_found = True start_time = datetime.datetime.now() return None if pattern_found else True
def wait_vanish( pattern: Pattern, timeout: float = None, region: Rectangle = None ) -> bool or FindError: """Wait until a Pattern disappears. :param pattern: Pattern. :param timeout: Number as maximum waiting time in seconds. :param region: Rectangle object in order to minimize the area. :return: True if vanished. """ if timeout is None: timeout = Settings.auto_wait_timeout image_found = image_vanish(pattern, timeout, region) if image_found is not None: return True else: raise FindError("%s did not vanish" % pattern.get_filename())
def _get_pattern_click_location(ps: Pattern, region: Rectangle = None, align: Alignment = None): """Returns the click location based on the pattern/string found location and alignment.""" if align is None: align = Alignment.CENTER width, height = ps.get_size() find_location = image_find(ps, region=region) if find_location is None: raise FindError("Unable to find pattern {}".format(ps.get_filename())) if ps.get_target_offset(): target_offset = ps.get_target_offset() find_location.x += target_offset.x find_location.y += target_offset.y rect = Rectangle(find_location.x, find_location.y, width, height) return rect.apply_alignment(align)