How to use the paperwork-backend.paperwork_backend.img.page.ImgPage function in paperwork-backend

To help you get started, we’ve selected a few paperwork-backend 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-backend / paperwork_backend / img / doc.py View on Github external
def __getitem__(self, idx):
        if not self.__pages:
            nb_pages = self.doc.nb_pages
            self.__pages = [
                ImgPage(self.doc, i) for i in range(0, nb_pages)
            ]
        return self.__pages[idx]
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def is_img_doc(fs, docpath):
    if not fs.isdir(docpath):
        return False
    try:
        filelist = fs.listdir(docpath)
    except OSError as exc:
        logger.warn("Warning: Failed to list files in %s: %s"
                    % (docpath, str(exc)))
        return False
    for filepath in filelist:
        if (filepath.lower().endswith(ImgPage.EXT_IMG) and
                not filepath.lower().endswith(ImgPage.EXT_THUMB)):
            return True
    return False
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def _get_nb_pages(self):
        """
        Compute the number of pages in the document. It basically counts
        how many JPG files there are in the document.
        """
        try:
            filelist = self.fs.listdir(self.path)
            count = 0
            for filepath in filelist:
                filename = self.fs.basename(filepath)
                if not ImgPage.FILE_REGEX.match(filename):
                    continue
                count += 1
            return count
        except IOError as exc:
            logger.debug("Exception while trying to get the number of"
                         " pages of '%s': %s", self.docid, exc)
            return 0
        except OSError as exc:
            if exc.errno != errno.ENOENT:
                logger.error("Exception while trying to get the number of"
                             " pages of '%s': %s", self.docid, exc)
                raise
            return 0
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def insert_page(self, img, boxes, page_nb):
        self.fs.mkdir_p(self.path)

        logger.info("Inserting page %d to %s" % (page_nb, str(self)))

        if page_nb > self.nb_pages:
            page_nb = self.nb_pages

        # make a hole ..
        pages = self.pages
        for page_nb in range(self.nb_pages - 1, page_nb - 1, -1):
            page = pages[page_nb]
            page.change_index(offset=1)

        # .. and fill it
        page = ImgPage(self, page_nb)
        page.img = img
        page.boxes = boxes
        return self.pages[page_nb]
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def print_page_cb(self, print_op, print_context, page_nb, keep_refs={}):
        """
        Called for printing operation by Gtk
        """
        page = ImgPage(self, page_nb)
        page.print_page_cb(print_op, print_context, keep_refs=keep_refs)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def steal_page(self, page):
        """
        Steal a page from another document
        """
        if page.doc == self:
            return
        self.fs.mkdir_p(self.path)

        new_page = ImgPage(self, self.nb_pages)
        logger.info("%s --> %s" % (str(page), str(new_page)))
        new_page._steal_content(page)
github openpaperwork / paperwork / paperwork-backend / paperwork_backend / img / doc.py View on Github external
def add_page(self, img, boxes):
        self.fs.mkdir_p(self.path)
        logger.info("Adding page %d to %s (%s)",
                    self.nb_pages, str(self), self.path)
        page = ImgPage(self, self.nb_pages)
        page.img = img
        page.boxes = boxes
        return self.pages[-1]