How to use the paperwork.backend.img.doc.ImgDoc 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 / scripts / obfuscate.py View on Github external
salt = gen_salt()
    sys.stdout.write("Done\n")
    print("Will use [%s] as salt for the hash" % salt)

    sys.stdout.write("Generating char mapping ... ")
    sys.stdout.flush()
    mapping = generate_mapping(chars)
    sys.stdout.write("Done\n")

    print_mapping(mapping)

    os.mkdir(dst_dir)

    sys.stdout.write("Generating document %s ... " % dst_dir)
    sys.stdout.flush()
    dst_doc = ImgDoc(dst_dir, os.path.basename(dst_dir))
    clone_doc_content(src_doc, dst_doc, mapping, salt)
    sys.stdout.write("... Done\n")

    print("All done")
github openpaperwork / paperwork / scripts / obfuscate.py View on Github external
def main(src_dir, dst_dir):
    sys.stdout.write("Loading document %s ... " % src_dir)
    sys.stdout.flush()
    src_doc = ImgDoc(src_dir, os.path.basename(src_dir))
    sys.stdout.write("Done\n")

    if (src_doc.nb_pages <= 0):
        raise Exception("No pages found. Is this an image doc ?")

    sys.stdout.write("Analyzing document ... ")
    sys.stdout.flush()
    chars = get_chars(src_doc)
    sys.stdout.write("Done\n")

    sys.stdout.write("Generating salt ... ")
    sys.stdout.flush()
    salt = gen_salt()
    sys.stdout.write("Done\n")
    print("Will use [%s] as salt for the hash" % salt)
github openpaperwork / paperwork / src / paperwork / backend / docsearch.py View on Github external
last_mod = datetime.datetime.fromtimestamp(doc.last_mod)
                if old_infos[1] != last_mod:
                    on_doc_modified(doc)
                else:
                    on_doc_unchanged(doc)
            else:
                on_new_doc(doc)
            progress_cb(progress, len(docdirs),
                        DocSearch.INDEX_STEP_CHECKING, doc)
            progress += 1

        # remove all documents from the index that don't exist anymore
        for old_doc in old_doc_list:
            # Will be a document with 0 pages
            docpath = os.path.join(self.docsearch.rootdir, old_doc)
            on_doc_deleted(ImgDoc(docpath, old_doc))

        progress_cb(1, 1, DocSearch.INDEX_STEP_CHECKING)
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow.py View on Github external
def __insert_new_doc(self):
        sentence = unicode(self.search_field.get_text(), encoding='utf-8')
        logger.info("Search: %s" % (sentence.encode('utf-8', 'replace')))

        doc_list = self.lists['matches']['doclist']

        # When a scan is done, we try to refresh only the current document.
        # However, the current document may be "New document". In which case
        # it won't appear as "New document" anymore. So we have to add a new
        # one to the list
        if sentence == u"" and (len(doc_list) == 0 or not doc_list[0].is_new):
            # append a new document to the list
            new_doc = ImgDoc(self.__config.workdir)
            doc_list.insert(0, new_doc)
            new_doc_line = self.__get_doc_model_line(new_doc)
            self.lists['matches']['model'].insert(0, new_doc_line)
            return True
        return False
github openpaperwork / paperwork / src / paperwork / backend / docimport.py View on Github external
def import_doc(file_uri, docsearch, current_doc=None):
        """
        Import the specified image
        """
        logger.info("Importing doc '%s'" % (file_uri))
        if current_doc is None:
            current_doc = ImgDoc(docsearch.rootdir)
        new = current_doc.is_new
        if file_uri[:7] == "file://":
            # XXX(Jflesch): bad bad bad
            file_uri = urllib.unquote(file_uri[7:])
        img = Image.open(file_uri)
        page = current_doc.add_page(img, [])
        return ([current_doc], page, new)
github openpaperwork / paperwork / src / paperwork / backend / docimport.py View on Github external
def can_import(file_uri, current_doc=None):
        """
        Check that the specified file looks like an image supported by PIL
        """
        for ext in ImgDoc.IMPORT_IMG_EXTENSIONS:
            if file_uri.lower().endswith(ext):
                return True
        return False
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow.py View on Github external
def do(self):
        SimpleAction.do(self)

        must_insert_new = False

        doclist = self.__main_win.lists['matches']['doclist']
        if (len(doclist) <= 0):
            must_insert_new = True
        else:
            must_insert_new = not doclist[0].is_new

        if must_insert_new:
            doc = ImgDoc(self.__config.workdir)
            doclist.insert(0, doc)
            self.__main_win.lists['matches']['model'].insert(
                0,
                [
                    doc.name,
                    doc,
                    None,
                    None,
                    Gtk.IconSize.DIALOG,
                ])

        path = Gtk.TreePath(0)
        self.__main_win.lists['matches']['gui'].select_path(path)
        self.__main_win.lists['matches']['gui'].scroll_to_path(
            path, False, 0.0, 0.0)
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow.py View on Github external
img = PIL.Image.new("RGB", (
            JobDocThumbnailer.THUMB_WIDTH,
            JobDocThumbnailer.THUMB_HEIGHT
        ), color="#CCCCCC")
        self.default_thumbnail = image2pixbuf(img)

        widget_tree = load_uifile("mainwindow.glade")

        self.window = widget_tree.get_object("mainWindow")

        self.__config = config
        self.__scan_start = 0.0
        self.__scan_progress_job = None

        self.docsearch = DummyDocSearch()
        self.doc = (0, ImgDoc(self.__config.workdir))
        self.page = DummyPage(self.doc[1])

        self.lists = {
            'suggestions': {
                'gui': widget_tree.get_object("entrySearch"),
                'model': widget_tree.get_object("liststoreSuggestion")
            },
            'matches': {
                'gui': widget_tree.get_object("iconviewMatch"),
                'model': widget_tree.get_object("liststoreMatch"),
                'doclist': [],
                'active_idx': -1,
            },
            'pages': {
                'gui': widget_tree.get_object("iconviewPage"),
                'model': widget_tree.get_object("liststorePage"),