Beispiel #1
0
class DocScanWorker(Worker):
    __gsignals__ = {
        "scan-start": (
            gobject.SIGNAL_RUN_LAST,
            gobject.TYPE_NONE,
            # current page / total
            (gobject.TYPE_INT, gobject.TYPE_INT),
        ),
        "ocr-start": (
            gobject.SIGNAL_RUN_LAST,
            gobject.TYPE_NONE,
            # current page / total
            (gobject.TYPE_INT, gobject.TYPE_INT),
        ),
        "scan-done": (
            gobject.SIGNAL_RUN_LAST,
            gobject.TYPE_NONE,
            # current page / total
            (gobject.TYPE_INT, gobject.TYPE_INT),
        ),
    }

    can_interrupt = True

    def __init__(self, config, nb_pages, line_in_treeview, doc=None):
        Worker.__init__(self, "Document scanner (doc %d)" % (line_in_treeview))
        self.__config = config
        self.doc = doc
        self.nb_pages = nb_pages
        self.line_in_treeview = line_in_treeview
        self.current_page = None

    def __progress_cb(self, progression, total, step=None):
        if not self.can_run:
            raise Exception("Scan interrupted")
        if progression == 0 and step == ScannedPage.SCAN_STEP_OCR:
            self.emit("ocr-start", self.current_page, self.nb_pages)

    def do(self, scan_src):
        if self.doc == None:
            self.doc = ScannedDoc(self.__config.workdir)
        for self.current_page in range(0, self.nb_pages):
            self.emit("scan-start", self.current_page, self.nb_pages)
            self.doc.scan_single_page(
                scan_src,
                self.__config.scanner_resolution,
                self.__config.ocrlang,
                self.__config.scanner_calibration,
                self.__progress_cb,
            )
            self.emit("scan-done", self.current_page, self.nb_pages)
        self.current_page = None
Beispiel #2
0
 def do(self, scan_src):
     if self.doc == None:
         self.doc = ScannedDoc(self.__config.workdir)
     for self.current_page in range(0, self.nb_pages):
         self.emit("scan-start", self.current_page, self.nb_pages)
         self.doc.scan_single_page(
             scan_src,
             self.__config.scanner_resolution,
             self.__config.ocrlang,
             self.__config.scanner_calibration,
             self.__progress_cb,
         )
         self.emit("scan-done", self.current_page, self.nb_pages)
     self.current_page = None