Esempio n. 1
0
def find(ps: Pattern or str,
         region: Rectangle = None) -> Location or FindError:
    """Look for a single match of a Pattern or image.

    :param ps: Pattern or String.
    :param region: Rectangle object in order to minimize the area.
    :return: Location object.
    """
    if isinstance(ps, Pattern):
        image_found = match_template(ps, region, MatchTemplateType.SINGLE)
        if len(image_found) > 0:
            if Settings.highlight:
                highlight(region=region, ps=ps, location=image_found)
            return image_found[0]
        else:
            raise FindError("Unable to find image %s" % ps.get_filename())
    elif isinstance(ps, str):
        if not Settings.OCR_ENABLED:
            raise FindError("OCR is not enabled, cannot search for text.")
        text_found = text_find(ps, region)
        if len(text_found) > 0:
            if Settings.highlight:
                highlight(region=region, ps=ps, text_location=text_found)
            return Location(text_found[0].x, text_found[0].y)
        else:
            raise FindError("Unable to find text %s" % ps)
Esempio n. 2
0
def wait(ps, timeout=None, region=None) -> bool or FindError:
    """Verify that a Pattern or str appears.

    :param ps: String or Pattern.
    :param timeout: Number as maximum waiting time in seconds.
    :param region: Rectangle object in order to minimize the area.
    :return: True if found, otherwise raise FindError.
    """
    if isinstance(ps, Pattern):
        if timeout is None:
            timeout = Settings.auto_wait_timeout

        image_found = image_find(ps, timeout, region)
        if image_found is not None:
            if Settings.highlight:
                highlight(region=region, ps=ps, location=[image_found])
            return True
        else:
            raise FindError("Unable to find image %s" % ps.get_filename())
    elif isinstance(ps, str):
        text_found = text_find(ps, region)
        if len(text_found) > 0:
            if Settings.highlight:
                highlight(region=region, ps=ps, text_location=text_found)
            return Location(text_found[0].x, text_found[0].y)
        else:
            raise FindError("Unable to find text %s" % ps)
    else:
        raise ValueError("Invalid input")
Esempio n. 3
0
def _get_string_click_location(ps: str,
                               region: Rectangle = None,
                               align: Alignment = None):
    if align is None:
        align = Alignment.CENTER

    find_location = text_find(ps, region)

    if len(find_location) == 0:
        if isinstance(ps, Pattern):
            error_str = "Unable to find pattern {}".format(ps.get_filename())
        else:
            error_str = "Unable to find string {}".format(ps)
        raise FindError(error_str)

    return find_location[0].apply_alignment(align)