Пример #1
0
def test__match_lines():
    lines = [[
        {
            "text": "Open",
            "region": Region(left=1356, top=440, right=1417, bottom=473),
        },
        {
            "text": "Edit",
            "region": Region(left=1493, top=440, right=1536, bottom=473),
        },
        {
            "text": "New",
            "region": Region(left=1641, top=446, right=1690, bottom=464),
        },
        {
            "text": "Delete",
            "region": Region(left=1755, top=444, right=1831, bottom=464),
        },
    ]]

    expected = [{
        "text": "New",
        "region": Region(left=1641, top=446, right=1690, bottom=464),
        "confidence": 100.0,
    }]
    result = ocr._match_lines(lines, "New", 100)

    assert result == expected
Пример #2
0
    def _find(self, locator: str) -> List[Geometry]:
        """Internal method for resolving and searching locators."""
        if isinstance(locator, (Region, Point)):
            return [locator]

        locator: Locator = parse_locator(locator)
        self.logger.info("Using locator: %s", locator)

        if isinstance(locator, PointLocator):
            position = Point(locator.x, locator.y)
            return [position]
        elif isinstance(locator, OffsetLocator):
            position = self.ctx.get_mouse_position()
            position = position.move(locator.x, locator.y)
            return [position]
        elif isinstance(locator, RegionLocator):
            region = Region(locator.left, locator.top, locator.right,
                            locator.bottom)
            return [region]
        elif isinstance(locator, ImageLocator):
            ensure_recognition()
            return self._find_templates(locator)
        elif isinstance(locator, OcrLocator):
            ensure_recognition()
            return self._find_ocr(locator)
        else:
            raise NotImplementedError(f"Unsupported locator: {locator}")
Пример #3
0
    def _find_region(self, base: Geometry, region: RegionLocator):
        """Find absolute region on screen. Can not be based on existing value."""
        if not isinstance(base, Undefined):
            self.logger.warning("Using absolute region coordinates")

        position = Region(region.left, region.top, region.right, region.bottom)
        return [position]
Пример #4
0
def test_find_template(region_and_template):
    region, template = region_and_template
    region = Region(*region)

    matches = templates.find(image=IMAGES / "source.png",
                             template=IMAGES / template)

    assert len(matches) == 1
    match = matches[0]
    assert match.center == region.center
Пример #5
0
    def define_region(self, left: int, top: int, right: int,
                      bottom: int) -> Region:
        """
        Return a new ``Region`` with the given dimensions.

        :param left: left edge coordinate.
        :param top: top edge coordinate.
        :param right: right edge coordinate.
        :param bottom: bottom edge coordinate.
        """
        return Region(left, top, right, bottom)
Пример #6
0
    def highlight_elements(self, locator: str):
        """Draw an outline around all matching elements."""
        if not utils.is_windows():
            raise NotImplementedError("Not supported on non-Windows platforms")

        matches = self.ctx.find(locator)

        for match in matches:
            if isinstance(match, Region):
                _draw_outline(match)
            elif isinstance(match, Point):
                region = Region(match.x - 5, match.y - 5, match.x + 5,
                                match.y + 5)
                _draw_outline(region)
            else:
                raise TypeError(f"Unknown location type: {match}")
Пример #7
0
    def define_region(self, left: int, top: int, right: int,
                      bottom: int) -> Region:
        """
        Return a new ``Region`` with the given dimensions.

        :param left: Left edge coordinate.
        :param top: Top edge coordinate.
        :param right: Right edge coordinate.
        :param bottom: Bottom edge coordinate.

        Usage examples:

        .. code-block:: robotframework

            ${region}=  Define Region  10  10  50  30

        .. code-block:: python

            region = desktop.define_region(10, 10, 50, 30)

        """
        return Region(left, top, right, bottom)