コード例 #1
0
def test_wait_template(region_and_template):
    _, template = region_and_template
    library = Images()
    library.take_screenshot = lambda: to_image(IMAGES / "source.png")

    library.matcher = TemplateMatcher(opencv=True)
    matches = library.wait_template_on_screen(IMAGES / template, timeout=0.52)
    assert len(matches) == 1
コード例 #2
0
ファイル: test_images.py プロジェクト: up1/rpaframework
def test_find_template(region_and_template):
    region, template = region_and_template
    region = Region(*region)

    library = Images()
    library.matcher = TemplateMatcher(opencv=True)

    matches = library.find_template_in_image(image=IMAGES / "source.png",
                                             template=IMAGES / template,
                                             limit=1)

    assert len(matches) == 1
    match = matches[0]
    assert match.center == region.center
コード例 #3
0
def test_find_template(region_and_template):
    region, template = region_and_template
    region = Region(*region)

    library = Images()
    matches = library.find_template_in_image(
        image=IMAGES / "source.png",
        template=IMAGES / template,
        tolerance=0.8,
    )

    assert len(matches) == 1
    match = matches[0]
    assert match.center == region.center
コード例 #4
0
ファイル: Windows.py プロジェクト: krehl/rpaframework
    def screenshot(
        self,
        filename: str,
        element: dict = None,
        ctrl: Any = None,
        desktop: bool = False,
    ) -> None:
        """Save screenshot into filename.

        :param filename: name of the file
        :param element: take element screenshot if True, defaults to None
        :param ctrl: take control screenshot if True, defaults to None
        :param desktop: take desktop screenshot if True, defaults to False
        """
        if desktop:
            region = None
        elif element:
            region = self._get_element_coordinates(element["rectangle"])
        elif ctrl:
            region = self.get_dialog_rectangle(ctrl)
        else:
            region = self.get_dialog_rectangle()

        try:
            output_dir = BuiltIn().get_variable_value("${OUTPUT_DIR}")
        except (ModuleNotFoundError, RobotNotRunningError):
            output_dir = Path.cwd()

        filename = Path(output_dir, "images", clean_filename(filename))
        os.makedirs(filename.parent)
        Images().take_screenshot(filename=filename, region=region)

        self.logger.info("Saved screenshot as '%s'", filename)
コード例 #5
0
ファイル: desktop.py プロジェクト: robocorp/robot-playground
def click_image(
    imagefile: str, button: str = "left", clicks: int = 1, interval: float = 0.25
):
    """Click on the center of the given image file if it is found on the screen

    :param imagefile: click on the center of this image (filepath)
    :param button: which button to click, defaults to "left"
    :param clicks: how many times mouse is clicked, defaults to 1
    :param interval: time interval between clicks if more than 1 clicks, defaults to 0.25
    """
    os.environ["DISPLAY"] = ":99.0"
    match = Images().find_template_on_screen(imagefile, limit=1)
    if match:
        center = match[0].center
        pyautogui.click(
            x=center.x, y=center.y, button=button, clicks=clicks, interval=interval
        )
コード例 #6
0
ファイル: Windows.py プロジェクト: krehl/rpaframework
    def mouse_click_image(self,
                          template: str,
                          off_x: int = 0,
                          off_y: int = 0,
                          ctype: str = "click") -> None:
        """Click at template image on desktop

        :param image: [description]
        :param off_x: [description], defaults to 0
        :param off_y: [description], defaults to 0
        :param ctype: [description], defaults to "click"
        """
        matches = Images().find_template_on_screen(template, limit=1)

        center_x = matches[0].center.x + int(off_x)
        center_y = matches[0].center.y + int(off_y)

        self.click_type(center_x, center_y, ctype)
コード例 #7
0
ファイル: test_images.py プロジェクト: up1/rpaframework
def test_screenshot_region_and_find_it():
    library = Images()
    region = Region(0, 0, 100, 100)
    first_capture = library.take_screenshot(region=region)
    find_result = library.find_template_on_screen(first_capture)
    assert region == find_result[0]