How to use the paperwork.frontend.util.canvas.drawers.Drawer function in paperwork

To help you get started, we’ve selected a few paperwork examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / pages.py View on Github external
self.surface, self.position,
                self.size, angle=self.angle
            )

    def on_img_processing_img(self, img, surface):
        self.img = img
        self.surface = surface

    def on_img_processing_done(self):
        self.parent.redraw()

    def __str__(self):
        return "Automatic Color Equalization"


class SimplePageDrawer(Drawer):
    layer = Drawer.IMG_LAYER
    DEFAULT_LINE_WIDTH = 1.0
    MAX_LINE_WIDTH = 5.0
    TMP_AREA = (0.85, 0.85, 0.85)
    BORDER_BASIC = (5, (0.85, 0.85, 0.85))
    MARGIN = 20
    BORDER_HIGHLIGHTED = (5, (0, 0.85, 0))

    priority = 0

    def __init__(self, parent_drawer, max_size, job_factories, job_schedulers,
                 search_sentence=u"", show_border=True, show_all_boxes=False,
                 show_boxes=True, previous_page_drawer=None):
        super(SimplePageDrawer, self).__init__()
        self.max_size = max_size
        self.page = parent_drawer.page
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / pages.py View on Github external
logger.info("Text copied ({})".format(len(text)))

    def notify_matching_boxes(self, boxes):
        self.parent.notify_matching_boxes(boxes)

    def select_boxes(self, boxes):
        self.boxes['selection_start'] = None
        self.boxes['selection_end'] = None
        self.boxes['selected'] = set(boxes)
        self.redraw()

    def __str__(self):
        return "Base page (size: {}|{})".format(self.size, self.max_size)


class PageDrawer(Drawer, GObject.GObject):
    """
    Global page drawer.
    Use various drawer internally to draw the required layers
    (pages, edited page preview, etc)
    """
    layer = Drawer.BUTTON_LAYER

    BUTTON_SIZE = 32
    BUTTON_BACKGROUND = (0.85, 0.85, 0.85)
    TOOLTIP_LENGTH = 200
    FONT_SIZE = 15
    ICON_EDIT_START = "document-properties"
    ICON_EDIT_CROP = "edit-cut"
    ICON_EDIT_ROTATE_COUNTERCLOCKWISE = "object-rotate-left"
    ICON_EDIT_ROTATE_CLOCKWISE = "object-rotate-right"
    ICON_EDIT_CANCEL = "edit-undo"
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / pages.py View on Github external
return self.simple_page_drawer.get_real_box_position(box)


GObject.type_register(PageDrawer)


class PageDropHandler(Drawer):
    """
    Drag'n'drop: Used when the user drop a page on the canvas.
    Display where the page will land
    """
    LINE_BORDERS = 10
    LINE_WIDTH = 3
    LINE_COLOR = (0.0, 0.8, 1.0, 1.0)

    layer = Drawer.BOX_LAYER

    def __init__(self, main_win):
        self.__main_win = main_win

        # None = means the new page will be the first one
        self.active = False
        self.target_previous_page_drawer = None

    def set_canvas(self, canvas):
        super(PageDropHandler, self).set_canvas(canvas)
        canvas = self.__main_win.img['canvas']
        canvas.connect(self, "drag-motion", self._on_drag_motion)
        canvas.connect(self, "drag-leave", self._on_drag_leave)
        canvas.connect(self, "drag-drop", self._on_drag_drop)
        canvas.connect(self, "drag-data-received", self._on_drag_data_received)
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / multiscan / scan.py View on Github external
self.scan_workflow.scan_and_ocr(self.resolution, self.__scan_session)

    def connect_next_page_scan(self, next_page_scan):
        self.connect(
            "done",
            lambda _, scan_session: GLib.idle_add(
                next_page_scan.start_scan_workflow
            )
        )


GObject.type_register(PageScan)


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)
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / pages.py View on Github external
self.boxes['selection_start'] = None
        self.boxes['selection_end'] = None
        self.boxes['selected'] = set(boxes)
        self.redraw()

    def __str__(self):
        return "Base page (size: {}|{})".format(self.size, self.max_size)


class PageDrawer(Drawer, GObject.GObject):
    """
    Global page drawer.
    Use various drawer internally to draw the required layers
    (pages, edited page preview, etc)
    """
    layer = Drawer.BUTTON_LAYER

    BUTTON_SIZE = 32
    BUTTON_BACKGROUND = (0.85, 0.85, 0.85)
    TOOLTIP_LENGTH = 200
    FONT_SIZE = 15
    ICON_EDIT_START = "document-properties"
    ICON_EDIT_CROP = "edit-cut"
    ICON_EDIT_ROTATE_COUNTERCLOCKWISE = "object-rotate-left"
    ICON_EDIT_ROTATE_CLOCKWISE = "object-rotate-right"
    ICON_EDIT_CANCEL = "edit-undo"
    ICON_EDIT_APPLY = "document-save"
    ICON_DELETE = "edit-delete"
    ICON_COPY = "edit-copy"

    PAGE_DRAG_ID = 128
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / util / imgcutting.py View on Github external
b_y += drawer_position[1]

        if self.selected:
            color = self.SELECTED_COLOR
        elif self.hover:
            color = self.HOVER_COLOR
        else:
            color = self.DEFAULT_COLOR
        cairo_ctx.set_source_rgb(color[0], color[1], color[2])
        cairo_ctx.set_line_width(1.0)
        cairo_ctx.rectangle(a_x, a_y, b_x - a_x, b_y - a_y)
        cairo_ctx.stroke()


class ImgGripRectangle(Drawer):
    layer = (Drawer.BOX_LAYER + 1)  # draw below/before the grips itself

    COLOR = (0.0, 0.25, 1.0)

    def __init__(self, grips):
        super(ImgGripRectangle, self).__init__()
        self.grips = grips

    def __get_size(self):
        positions = [grip.position for grip in self.grips]
        return (
            abs(positions[0][0] - positions[1][0]),
            abs(positions[0][1] - positions[1][1]),
        )

    size = property(__get_size)
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / util / imgcutting.py View on Github external
b_x += drawer_position[0]
        b_y += drawer_position[1]

        if self.selected:
            color = self.SELECTED_COLOR
        elif self.hover:
            color = self.HOVER_COLOR
        else:
            color = self.DEFAULT_COLOR
        cairo_ctx.set_source_rgb(color[0], color[1], color[2])
        cairo_ctx.set_line_width(1.0)
        cairo_ctx.rectangle(a_x, a_y, b_x - a_x, b_y - a_y)
        cairo_ctx.stroke()


class ImgGripRectangle(Drawer):
    layer = (Drawer.BOX_LAYER + 1)  # draw below/before the grips itself

    COLOR = (0.0, 0.25, 1.0)

    def __init__(self, grips):
        super(ImgGripRectangle, self).__init__()
        self.grips = grips

    def __get_size(self):
        positions = [grip.position for grip in self.grips]
        return (
            abs(positions[0][0] - positions[1][0]),
            abs(positions[0][1] - positions[1][1]),
        )

    size = property(__get_size)
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / util / canvas / animations.py View on Github external
import math

import cairo
import PIL.Image

from paperwork_backend.util import image2surface
from paperwork.frontend.util import load_image
from paperwork.frontend.util.canvas import Canvas
from paperwork.frontend.util.canvas.drawers import Drawer
from paperwork.frontend.util.canvas.drawers import fit


logger = logging.getLogger(__name__)


class Animation(Drawer):
    def __init__(self):
        Drawer.__init__(self)
        self.ticks_enabled = False

    def show(self):
        Drawer.show(self)
        if not self.ticks_enabled:
            self.ticks_enabled = True
            self.canvas.start_ticks()

    def hide(self):
        Drawer.hide(self)
        if self.ticks_enabled:
            self.ticks_enabled = False
            self.canvas.stop_ticks()
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / util / imgcutting.py View on Github external
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GObject

from paperwork.frontend.util.canvas.drawers import Drawer


logger = logging.getLogger(__name__)


class ImgGrip(Drawer):
    """
    Represents one of the grip that user can move to cut an image.
    """

    layer = Drawer.BOX_LAYER

    GRIP_SIZE = 40
    DEFAULT_COLOR = (0.0, 0.25, 1.0)
    HOVER_COLOR = (0.0, 1.0, 0.0)
    SELECTED_COLOR = (1.0, 0.0, 0.0)

    def __init__(self, handler, position):
        super(ImgGrip, self).__init__()
        self._img_position = position  # position relative to the image
        self.size = (0, 0)
        self.selected = False
        self.hover = False
        self.visible = True
        self.handler = handler

    def __get_img_position(self):
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / util / imgcutting.py View on Github external
#    You should have received a copy of the GNU General Public License
#    along with Paperwork.  If not, see .

import logging

from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GObject

from paperwork.frontend.util.canvas.drawers import Drawer


logger = logging.getLogger(__name__)


class ImgGrip(Drawer):
    """
    Represents one of the grip that user can move to cut an image.
    """

    layer = Drawer.BOX_LAYER

    GRIP_SIZE = 40
    DEFAULT_COLOR = (0.0, 0.25, 1.0)
    HOVER_COLOR = (0.0, 1.0, 0.0)
    SELECTED_COLOR = (1.0, 0.0, 0.0)

    def __init__(self, handler, position):
        super(ImgGrip, self).__init__()
        self._img_position = position  # position relative to the image
        self.size = (0, 0)
        self.selected = False