Exemplo n.º 1
0
def create_region_from_image(image):
    """Create region starting from a pattern.

    :param image: Pattern used to create a region.
    :return: None.
    """
    try:
        from src.core.api.rectangle import Rectangle
        from src.core.api.enums import Alignment
        m = image_find(image)
        if m:
            sync_pattern = Pattern('sync_hamburger_menu.png')
            sync_width, sync_height = sync_pattern.get_size()
            sync_image = image_find(sync_pattern)
            top_left = Rectangle(sync_image.x, sync_image.y, sync_width, sync_width). \
                apply_alignment(Alignment.TOP_RIGHT)
            if OSHelper.is_mac():
                exit_pattern = Pattern('help_hamburger_menu.png')
            else:
                exit_pattern = Pattern('exit_hamburger_menu.png')
            exit_width, exit_height = exit_pattern.get_size()
            exit_image = image_find(exit_pattern)
            bottom_left = Rectangle(exit_image.x, exit_image.y, exit_width, exit_height). \
                apply_alignment(Alignment.BOTTOM_RIGHT)

            x0 = top_left.x + 2
            y0 = top_left.y
            height = bottom_left.y - top_left.y
            width = Screen().width - top_left.x - 2
            region = Region(x0, y0, width, height)
            return region
        else:
            raise APIHelperError('No matching found.')
    except FindError:
        raise APIHelperError('Image not present.')
Exemplo n.º 2
0
def _create_rectangle_from_ocr_data(data, scale):
    """Generates a Rectangle object based on OCR processed data and image scale."""
    x = int(int(data[6]) / (scale * (1 if scale - 1 == 0 else scale - 1)))
    y = int(int(data[7]) / (scale * (1 if scale - 1 == 0 else scale - 1)))
    width = int(int(data[8]) / (scale * (1 if scale - 1 == 0 else scale - 1)))
    height = int(int(data[9]) / (scale * (1 if scale - 1 == 0 else scale - 1)))
    return Rectangle(x, y, width, height)
Exemplo n.º 3
0
    def __init__(self,
                 x: int,
                 y: int,
                 width: int,
                 height: int,
                 color: Color = None,
                 thickness: int = None):
        Rectangle.__init__(self, x, y, width, height)

        if thickness is None:
            thickness = Settings.highlight_thickness

        if color is None:
            color = Settings.highlight_color

        self.color = color
        self.thickness = thickness
Exemplo n.º 4
0
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 click on: %s' % ps.get_file_path())

    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)
Exemplo n.º 5
0
 def __init__(self,
              x_start: int = 0,
              y_start: int = 0,
              width: int = 0,
              height: int = 0):
     self._area = Rectangle(x_start, y_start, width, height)
     self.x = x_start
     self.y = y_start
     self.width = width
     self.height = height
Exemplo n.º 6
0
def _assemble_results(result_list):
    """Merge all Rectangle objects into one that contains them all."""
    from operator import attrgetter
    x = min(result_list, key=attrgetter('x')).x
    y = min(result_list, key=attrgetter('y')).y

    x_max = max(result_list, key=attrgetter('x')).x
    width = max([x.width for x in result_list if x.x == x_max]) + x_max - x

    y_max = max(result_list, key=attrgetter('y')).y
    height = max([x.height for x in result_list if x.y == y_max]) + y_max - y
    return Rectangle(x, y, width, height)