Esempio n. 1
0
    def __on_scan_info_cb(self, x, y):
        size = fit((x, y), self.canvas.visible_size)
        position = (
            int(self.position[0] + (self.canvas.visible_size[0] / 2) -
                (size[0] / 2)),
            int(self.position[1]),
        )

        scan_drawer = ScanAnimation(position, (x, y), self.canvas.visible_size)
        scan_drawer.set_canvas(self.canvas)
        ratio = scan_drawer.ratio

        self.scan_drawers = [scan_drawer]

        calibration = self.scan_workflow.calibration
        if calibration:
            calibration_drawer = TargetAreaDrawer(
                position,
                size,
                (
                    int(position[0] + (ratio * calibration[0][0])),
                    int(position[1] + (ratio * calibration[0][1])),
                ),
                (
                    int(ratio * (calibration[1][0] - calibration[0][0])),
                    int(ratio * (calibration[1][1] - calibration[0][1])),
                ),
            )
            calibration_drawer.set_canvas(self.canvas)

            self.scan_drawers.append(calibration_drawer)

        self.redraw()
Esempio n. 2
0
    def __on_scan_info_cb(self, x, y):
        size = fit((x, y), self.canvas.visible_size)
        position = (
            int(self.position[0] + (self.canvas.visible_size[0] / 2) -
                (size[0] / 2)),
            int(self.position[1]),
        )

        scan_drawer = ScanAnimation(position, (x, y),
                                    self.canvas.visible_size)
        scan_drawer.set_canvas(self.canvas)
        ratio = scan_drawer.ratio

        self.scan_drawers = [scan_drawer]

        calibration = self.scan_workflow.calibration
        if calibration:
            calibration_drawer = TargetAreaDrawer(
                position, size,
                (
                    int(position[0] + (ratio * calibration[0][0])),
                    int(position[1] + (ratio * calibration[0][1])),
                ),
                (
                    int(ratio * (calibration[1][0] - calibration[0][0])),
                    int(ratio * (calibration[1][1] - calibration[0][1])),
                ),
            )
            calibration_drawer.set_canvas(self.canvas)

            self.scan_drawers.append(calibration_drawer)

        self.redraw()
Esempio n. 3
0
 def __on_scan_info(self, size):
     self.scan_animation = ScanAnimation(self.position, size, self.size)
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         self.scan_animation,
     ]
     assert(self.canvas)
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     for drawer in self.drawers:
         drawer.redraw()
Esempio n. 4
0
 def __on_scan_info(self, size):
     self.scan_animation = ScanAnimation(self.position, size, self.size)
     self.drawers = [
         RectangleDrawer(self.position, self.size,
                         inside_color=ScanAnimation.BACKGROUND_COLOR),
         self.scan_animation,
     ]
     assert(self.canvas)
     self.set_canvas(self.canvas)  # reset canvas on all new drawers
     for drawer in self.drawers:
         drawer.redraw()
Esempio n. 5
0
 def on_scan_info(self, size):
     self.calibration['scan_drawer'] = ScanAnimation(
         (0, 0),
         size, self.calibration['image_gui'].visible_size)
     self.calibration['image_gui'].add_drawer(
         self.calibration['scan_drawer'])
Esempio n. 6
0
class PageScanDrawer(Animation):
    layer = Drawer.IMG_LAYER
    visible = True

    DEFAULT_SIZE = (70, 100)

    def __init__(self, position):
        Animation.__init__(self)
        self.position = position
        self.scan_animation = None
        self.size = self.DEFAULT_SIZE
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
        ]

    def set_canvas(self, canvas):
        Animation.set_canvas(self, canvas)
        assert(self.canvas)
        for drawer in self.drawers:
            drawer.set_canvas(canvas)

    def set_scan_workflow(self, page_scan, scan_workflow):
        GLib.idle_add(self.__set_scan_workflow, scan_workflow)

    def __set_scan_workflow(self, scan_workflow):
        scan_workflow.connect("scan-info", lambda _, x, y:
                              GLib.idle_add(self.__on_scan_info, (x, y)))
        scan_workflow.connect("scan-chunk", lambda _, line, chunk:
                              GLib.idle_add(self.__on_scan_chunk, line, chunk))
        scan_workflow.connect("scan-done", lambda _, img:
                              GLib.idle_add(self.__on_scan_done, img))
        scan_workflow.connect("process-done", lambda _, img, boxes:
                              GLib.idle_add(self.__on_process_done, img))

    def on_tick(self):
        for drawer in self.drawers:
            drawer.on_tick()

    def do_draw(self, cairo_ctx):
        for drawer in self.drawers:
            drawer.draw(cairo_ctx)

    def __on_scan_info(self, size):
        self.scan_animation = ScanAnimation(self.position, size, self.size)
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            self.scan_animation,
        ]
        assert(self.canvas)
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        for drawer in self.drawers:
            drawer.redraw()

    def __on_scan_chunk(self, line, img):
        assert(self.canvas)
        self.scan_animation.add_chunk(line, img)

    def __on_scan_done(self, img):
        size = fit(img.size, self.size)
        img = img.resize(size)
        self.scan_animation = None
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            PillowImageDrawer(self.position, img),
            SpinnerAnimation(((self.position[0] + (self.size[0] / 2) -
                               SpinnerAnimation.ICON_SIZE / 2),
                              (self.position[1] + (self.size[1] / 2) -
                               SpinnerAnimation.ICON_SIZE / 2))),
        ]
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        self.canvas.redraw()

    def __on_process_done(self, img):
        size = fit(img.size, self.size)
        img = img.resize(size)
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            PillowImageDrawer(self.position, img)
        ]
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        self.canvas.redraw()
Esempio n. 7
0
class PageScanDrawer(Animation):
    layer = Drawer.IMG_LAYER
    visible = True

    DEFAULT_SIZE = (70, 100)

    def __init__(self, position):
        Animation.__init__(self)
        self.position = position
        self.scan_animation = None
        self.size = self.DEFAULT_SIZE
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
        ]

    def set_canvas(self, canvas):
        Animation.set_canvas(self, canvas)
        assert(self.canvas)
        for drawer in self.drawers:
            drawer.set_canvas(canvas)

    def set_scan_workflow(self, page_scan, scan_workflow):
        GLib.idle_add(self.__set_scan_workflow, scan_workflow)

    def __set_scan_workflow(self, scan_workflow):
        scan_workflow.connect("scan-info", lambda _, x, y:
                              GLib.idle_add(self.__on_scan_info, (x, y)))
        scan_workflow.connect("scan-chunk", lambda _, line, chunk:
                              GLib.idle_add(self.__on_scan_chunk, line, chunk))
        scan_workflow.connect("scan-done", lambda _, img:
                              GLib.idle_add(self.__on_scan_done, img))
        scan_workflow.connect("process-done", lambda _, img, boxes:
                              GLib.idle_add(self.__on_process_done, img))

    def on_tick(self):
        for drawer in self.drawers:
            drawer.on_tick()

    def do_draw(self, cairo_ctx):
        for drawer in self.drawers:
            drawer.draw(cairo_ctx)

    def __on_scan_info(self, size):
        self.scan_animation = ScanAnimation(self.position, size, self.size)
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            self.scan_animation,
        ]
        assert(self.canvas)
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        for drawer in self.drawers:
            drawer.redraw()

    def __on_scan_chunk(self, line, img):
        assert(self.canvas)
        self.scan_animation.add_chunk(line, img)

    def __on_scan_done(self, img):
        size = fit(img.size, self.size)
        img = img.resize(size)
        self.scan_animation = None
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            PillowImageDrawer(self.position, img),
            SpinnerAnimation(((self.position[0] + (self.size[0] / 2) -
                               SpinnerAnimation.ICON_SIZE / 2),
                              (self.position[1] + (self.size[1] / 2) -
                               SpinnerAnimation.ICON_SIZE / 2))),
        ]
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        self.canvas.redraw()

    def __on_process_done(self, img):
        size = fit(img.size, self.size)
        img = img.resize(size)
        self.drawers = [
            RectangleDrawer(self.position, self.size,
                            inside_color=ScanAnimation.BACKGROUND_COLOR),
            PillowImageDrawer(self.position, img)
        ]
        self.set_canvas(self.canvas)  # reset canvas on all new drawers
        self.canvas.redraw()