示例#1
0
def test_data():
    """Create NormcapData instance for testing."""
    data = NormcapData()
    data.top = 0
    data.bottom = 10
    data.left = 0
    data.right = 20
    data.words = [
        {
            "line_num": 1,
            "block_num": 1,
            "par_num": 1,
            "text": "one"
        },
        {
            "line_num": 2,
            "block_num": 1,
            "par_num": 1,
            "text": "two"
        },
        {
            "line_num": 2,
            "block_num": 1,
            "par_num": 2,
            "text": "three"
        },
        {
            "line_num": 3,
            "block_num": 1,
            "par_num": 2,
            "text": "four"
        },
    ]
    return data
    def _select_region_with_gui(self, request: NormcapData) -> NormcapData:
        """Show window(s) with screenshots and select region.

        Arguments:
            request {NormcapData} -- NormCap's session data

        Returns:
            dict -- Selected region {"bottom": <int>,
                                     "top": <int>,
                                     "left": <int>,
                                     "right": <int>,
                                     "monitor": <int>,
                                     "mode": <int>}
        """
        # Create dummy window plus one for every monitor
        root = _RootWindow(request.cli_args, request.platform)
        for shot in request.shots:
            _CropWindow(root, shot)
        root.mainloop()

        # Store result in request class
        result = root.props.crop_result
        if result:
            request.bottom = result["lower"]
            request.top = result["upper"]
            request.left = result["left"]
            request.right = result["right"]
            request.monitor = result["monitor"]
            request.mode = result["mode"]
        else:
            self._logger.info("Exiting. No selection done.")
            sys.exit(0)

        return request
示例#3
0
def test_data():
    """Create NormcapData instance for testing."""
    data = NormcapData()
    data.cli_args = {
        "verbose": True,
        "mode": "parse",
        "lang": "eng+deu",
        "color": "#FF0000",
        "path": None,
    }
    data.test_mode = True
    data.top = 0
    data.bottom = 10
    data.left = 0
    data.right = 20
    data.words = [
        {"line_num": 1, "text": "one"},
        {"line_num": 2, "text": "two"},
        {"line_num": 2, "text": "three"},
        {"line_num": 3, "text": "four"},
    ]  # Space to check trimming

    test_img_folder = os.path.dirname(os.path.abspath(__file__)) + "/images/"
    img = Image.open(test_img_folder + "test_email_magic_1.jpg")
    data.shots = [{"monitor": 0, "image": img}]
    data.image = img

    return data
示例#4
0
    def _select_region(self, request: NormcapData) -> NormcapData:
        """Show window(s) with screenshots and select region.

        Arguments:
            request {NormcapData} -- NormCap's session data

        Returns:
            dict -- Selected region {"bottom": <int>,
                                     "top": <int>,
                                     "left": <int>,
                                     "right": <int>,
                                     "monitor": <int>,
                                     "mode": <int>}
        """
        # Create dummy window plus one for every monitor
        # root = _RootWindow(request.cli_args, request.platform)
        # for shot in request.shots:
        # _CropWindow(root, shot)
        # root.mainloop()

        # Store result in request class
        # result = root.props.crop_result

        request.bottom = self.lower
        request.top = self.upper
        request.left = self.left
        request.right = self.right
        request.monitor = 0
        request.mode = 'parse'

        return request
示例#5
0
def data_test_image(test_params):
    """Create NormcapData instance for testing."""
    data = NormcapData()
    data.test_mode = True
    data.cli_args = test_params["cli_args"]
    data.top = test_params["position"]["top"]
    data.bottom = test_params["position"]["bottom"]
    data.left = test_params["position"]["left"]
    data.right = test_params["position"]["right"]
    data.mode = test_params["cli_args"]["mode"]

    # Prep images
    test_img_folder = os.path.dirname(os.path.abspath(__file__)) + "/images/"
    img = Image.open(test_img_folder + test_params["filename"])
    data.shots = [{"monitor": 0, "image": img}]

    # Set tempfolder for storing
    data.cli_args["path"] = tempfile.gettempdir()

    return data
示例#6
0
    def _select_region_with_gui(self, request: NormcapData) -> NormcapData:
        """Show window(s) with screenshots and select region.

        Arguments:
            request {NormcapData} -- NormCap's session data

        Returns:
            dict -- Selected region {"bottom": <int>,
                                     "top": <int>,
                                     "left": <int>,
                                     "right": <int>,
                                     "monitor": <int>,
                                     "mode": <int>}
        """
        # Create window for every monitor
        root = tkinter.Tk()
        for idx, shot in enumerate(request.shots):
            if idx == 0:
                _CropWindow(root, root, shot, request.cli_args)
            else:
                top = tkinter.Toplevel()
                _CropWindow(root, top, shot, request.cli_args)
        root.mainloop()

        # Store result in request class
        result = root.result
        if result:
            request.bottom = result["lower"]
            request.top = result["upper"]
            request.left = result["left"]
            request.right = result["right"]
            request.monitor = result["monitor"]
            request.mode = result["mode"]
        else:
            self._logger.info("Exiting. No selection done.")
            sys.exit(0)

        return request