How to use paperwork - 10 common examples

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 / settingswindow / __init__.py View on Github external
if self.__settings_win.grips is not None:
            coords = self.__settings_win.grips.get_coords()
            self.__config['scanner_calibration'].value = (
                self.__settings_win.calibration['resolution'], coords)

        self.__config.write()

        self.__settings_win.hide()

        if need_reindex:
            self.__settings_win.emit("need-reindex")
        self.__settings_win.emit("config-changed")


class ActionScanCalibration(SimpleAction):
    enabled = True

    def __init__(self, settings_win):
        self.settings_win = settings_win
        super(ActionScanCalibration, self).__init__("Scan calibration sheet")

    def do(self):
        win = self.settings_win
        setting = win.device_settings['devid']
        idx = setting['gui'].get_active()
        assert(idx >= 0)
        devid = setting['stores']['loaded'][idx][1]

        setting = win.device_settings['source']
        idx = setting['gui'].get_active()
        if idx >= 0:
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / docs.py View on Github external
def do(self):
        SimpleAction.do(self)

        # Open the russian dolls to retrieve the selected label.
        label_list = self.__doc_properties.lists['labels']['gui']
        selected_row = label_list.get_selected_row()
        if selected_row is None:
            logger.warning("No label selected")
            return True
        label_box = selected_row.get_children()[0]
        label_name = label_box.get_children()[2].get_text()
        label_color = label_box.get_children()[1].get_rgba().to_string()
        label = Label(label_name, label_color)

        new_label = copy(label)
        self._dialog = editor = LabelEditor(new_label)
        reply = editor.edit(self.__main_win.window)
        if reply != "ok":
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow.py View on Github external
self.__config = config

    def do(self):
        SimpleAction.do(self)

        for scheduler in self.__main_win.schedulers.values():
            scheduler.stop()

        self.__config.write()
        Gtk.main_quit()

    def on_window_close_cb(self, window):
        self.do()


class ActionRefreshIndex(SimpleAction):
    def __init__(self, main_window, config, force=False):
        SimpleAction.__init__(self, "Refresh index")
        self.__main_win = main_window
        self.__config = config
        self.__force = force
        self.__connect_handler_id = None

    def do(self):
        SimpleAction.do(self)
        self.__main_win.schedulers['main'].cancel_all(
            self.__main_win.job_factories['index_reloader'])
        self.__main_win.schedulers['main'].cancel_all(
            self.__main_win.job_factories['doc_examiner'])
        self.__main_win.schedulers['main'].cancel_all(
            self.__main_win.job_factories['index_updater'])
        docsearch = self.__main_win.docsearch
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow.py View on Github external
def do(self):
        SimpleAction.do(self)
        labeleditor = LabelEditor()
        if labeleditor.edit(self.__main_win.window):
            logger.info("Adding label %s to doc %s"
                        % (labeleditor.label, self.__main_win.doc[1]))
            self.__main_win.docsearch.add_label(self.__main_win.doc[1],
                                                labeleditor.label)
        self.__main_win.refresh_label_list()
        self.__main_win.refresh_docs([self.__main_win.doc])
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / diag / __init__.py View on Github external
return
            self._get_scanner_info()
        except Exception as exc:
            logger.exception(exc)
        finally:
            self.emit('scan-done')

    def stop(self, will_resume=False):
        logger.info("InfoGetter interrupted")
        self.can_run = False


GObject.type_register(JobInfoGetter)


class JobFactoryInfoGetter(JobFactory):

    def __init__(self, diag_win, main_win):
        super(JobFactoryInfoGetter, self).__init__("InfoGetter")
        self.diag_win = diag_win
        self.main_win = main_win

    def make(self):
        job = JobInfoGetter(self, next(self.id_generator), self.main_win)
        job.connect(
            'scan-progression',
            lambda job, step, progression: GLib.idle_add(
                self.diag_win.on_scan_progression_cb, step, progression
            )
        )
        job.connect(
            'scan-done',
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / mainwindow / docs.py View on Github external
doc.name)

    def do(self):
        self.emit('label-updating-start')
        self._wait(0.5)  # give a little bit of time to Gtk to update
        try:
            self.__docsearch.update_label(self.__old_label, self.__new_label,
                                          self.__progress_cb)
        finally:
            self.emit('label-updating-end')


GObject.type_register(JobLabelUpdater)


class JobFactoryLabelUpdater(JobFactory):
    def __init__(self, doc_list):
        JobFactory.__init__(self, "LabelUpdater")
        self.__doc_list = doc_list

    def make(self, docsearch, old_label, new_label):
        job = JobLabelUpdater(self, next(self.id_generator), docsearch,
                              old_label, new_label)
        job.connect('label-updating-start',
                    lambda updater:
                    GLib.idle_add(
                        self.__doc_list.on_label_updating_start_cb,
                        updater))
        job.connect('label-updating-doc-updated',
                    lambda updater, progression, doc_name:
                    GLib.idle_add(
                        self.__doc_list.on_label_updating_doc_updated_cb,
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow / __init__.py View on Github external
self.optimize = False
        self.emit('index-update-progression', 1.0, "")
        self.emit('index-update-end')

    def stop(self, will_resume=False):
        self.can_run = False
        if not will_resume:
            self.connect('index-update-interrupted',
                         lambda job:
                         GLib.idle_add(self.index_updater.cancel))


GObject.type_register(JobIndexUpdater)


class JobFactoryIndexUpdater(JobFactory):
    def __init__(self, main_win, config):
        JobFactory.__init__(self, "IndexUpdater")
        self.__main_win = main_win
        self.__config = config

    def make(self, docsearch,
             new_docs=set(), upd_docs=set(), del_docs=set(),
             optimize=True, reload_list=False):
        job = JobIndexUpdater(self, next(self.id_generator), self.__config,
                              docsearch, new_docs, upd_docs, del_docs,
                              optimize)
        job.connect('index-update-start',
                    lambda updater:
                    GLib.idle_add(self.__main_win.on_index_update_start_cb,
                                  updater))
        job.connect('index-update-progression',
github openpaperwork / paperwork / src / paperwork / frontend / mainwindow / __init__.py View on Github external
if not self.can_run:
            logger.info("Search cancelled. Won't look for suggestions")
            return
        suggestions = self.__docsearch.find_suggestions(self.search)
        self.emit('search-suggestions', suggestions)

    def stop(self, will_resume=False):
        self.can_run = False
        self._stop_wait()


GObject.type_register(JobDocSearcher)


class JobFactoryDocSearcher(JobFactory):
    def __init__(self, main_win, config):
        JobFactory.__init__(self, "Search")
        self.__main_win = main_win
        self.__config = config

    def make(self, docsearch, sort_func, search_type, search):
        job = JobDocSearcher(self, next(self.id_generator), self.__config,
                             docsearch, sort_func, search_type, search)
        job.connect('search-start', lambda searcher:
                    GLib.idle_add(self.__main_win.on_search_start_cb))
        job.connect('search-results',
                    lambda searcher, search, documents:
                    GLib.idle_add(self.__main_win.on_search_results_cb,
                                  search, documents))
        job.connect('search-invalid',
                    lambda searcher: GLib.idle_add(
github openpaperwork / paperwork / paperwork-gtk / src / paperwork / frontend / settingswindow / __init__.py View on Github external
res_array.append(res)
                resolutions = res_array

            for resolution in resolutions:
                name = self.__get_resolution_name(resolution)
                self.emit('resolution-found', name, resolution,
                          (resolution == self.__selected_resolution))
            logger.info("Got all the resolutions")
        finally:
            self.emit("resolution-finding-end")


GObject.type_register(JobResolutionFinder)


class JobFactoryResolutionFinder(JobFactory):

    def __init__(self, settings_win, selected_resolution,
                 recommended_resolution):
        JobFactory.__init__(self, "ResolutionFinder")
        self.__settings_win = settings_win
        self.__selected_resolution = selected_resolution
        self.__recommended_resolution = recommended_resolution

    def make(self, devid):
        job = JobResolutionFinder(self, next(self.id_generator),
                                  self.__selected_resolution,
                                  self.__recommended_resolution, devid)
        job.connect('resolution-finding-start',
                    lambda job: GLib.idle_add(
                        self.__settings_win.on_finding_start_cb,
                        self.__settings_win.device_settings['resolution']))