Пример #1
0
class JobDocScan(Job):
    __gsignals__ = {
        'scan-start': (GObject.SignalFlags.RUN_LAST, None,
                       # current page / total
                       (GObject.TYPE_INT, GObject.TYPE_INT)),
        'ocr-start': (GObject.SignalFlags.RUN_LAST, None,
                      # current page / total
                      (GObject.TYPE_INT, GObject.TYPE_INT)),
        'scan-done': (GObject.SignalFlags.RUN_LAST, None,
                      # current page, total
                      (GObject.TYPE_PYOBJECT, GObject.TYPE_INT)),
        'scan-error': (GObject.SignalFlags.RUN_LAST, None,
                       # exception
                       (GObject.TYPE_PYOBJECT,)),
    }

    can_stop = True
    priority = 500

    def __init__(self, factory, id,
                 config, nb_pages, line_in_treeview, docsearch, doc,
                 scan_src):
        Job.__init__(self, factory, id)
        self.__config = config
        self.__scan_src = scan_src
        self.docsearch = docsearch
        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 progression == 0 and step == ImgPage.SCAN_STEP_OCR:
            self.emit('ocr-start', self.current_page, self.nb_pages)

    def do(self):
        if self.doc is None:
            self.doc = ImgDoc(self.__config.workdir)
        for self.current_page in range(0, self.nb_pages):
            self.emit('scan-start', self.current_page, self.nb_pages)
            try:
                self.doc.scan_single_page(self.__scan_src,
                                          self.__config.scanner_resolution,
                                          self.__config.scanner_calibration,
                                          self.__config.langs,
                                          self.__progress_cb)
                page = self.doc.pages[self.doc.nb_pages - 1]
                self.docsearch.index_page(page)
                self.emit('scan-done', page, self.nb_pages)
            except StopIteration, exc:
                logger.warning("Feeder appears to be empty and we "
                               "haven't scanned all the pages yet !")
                self.emit('scan-error', exc)
                self._wait(5.0, force=True)  # wait for all the jobs to be cancelled
                return
            except Exception, exc:
                logger.error("Error: Exception: %s" % str(exc))
                self.emit('scan-error', exc)
                self._wait(5.0, force=True)  # wait for all the jobs to be cancelled
                return
Пример #2
0
class JobDocScan(Job):
    __gsignals__ = {
        'scan-start': (GObject.SignalFlags.RUN_LAST, None,
                       # current page / total
                       (GObject.TYPE_INT, GObject.TYPE_INT)),
        'ocr-start': (GObject.SignalFlags.RUN_LAST, None,
                      # current page / total
                      (GObject.TYPE_INT, GObject.TYPE_INT)),
        'scan-done': (GObject.SignalFlags.RUN_LAST, None,
                      # current page, total
                      (GObject.TYPE_PYOBJECT, GObject.TYPE_INT)),
        'scan-error': (GObject.SignalFlags.RUN_LAST, None,
                       # exception
                       (GObject.TYPE_PYOBJECT,)),
    }

    can_stop = True
    priority = 500

    def __init__(self, factory, id,
                 config, nb_pages, line_in_treeview, docsearch, doc,
                 scan_src):
        Job.__init__(self, factory, id)
        self.__config = config
        self.__scan_src = scan_src
        self.docsearch = docsearch
        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 progression == 0 and step == ImgPage.SCAN_STEP_OCR:
            self.emit('ocr-start', self.current_page, self.nb_pages)

    def do(self):
        if self.doc is None:
            self.doc = ImgDoc(self.__config.workdir)
        for self.current_page in range(0, self.nb_pages):
            self.emit('scan-start', self.current_page, self.nb_pages)
            try:
                self.doc.scan_single_page(self.__scan_src,
                                          self.__config.scanner_resolution,
                                          self.__config.scanner_calibration,
                                          self.__config.langs,
                                          self.__progress_cb)
                page = self.doc.pages[self.doc.nb_pages - 1]
                self.docsearch.index_page(page)
                self.emit('scan-done', page, self.nb_pages)
            except StopIteration, exc:
                logger.warning("Feeder appears to be empty and we "
                               "haven't scanned all the pages yet !")
                self.emit('scan-error', exc)
                self._wait(5.0, force=True)  # wait for all the jobs to be cancelled
                return
            except Exception, exc:
                logger.error("Error: Exception: %s" % str(exc))
                self.emit('scan-error', exc)
                self._wait(5.0, force=True)  # wait for all the jobs to be cancelled
                return
Пример #3
0
class DocScanWorker(Worker):
    __gsignals__ = {
        'scan-start': (
            GObject.SignalFlags.RUN_LAST,
            None,
            # current page / total
            (GObject.TYPE_INT, GObject.TYPE_INT)),
        'ocr-start': (
            GObject.SignalFlags.RUN_LAST,
            None,
            # current page / total
            (GObject.TYPE_INT, GObject.TYPE_INT)),
        'scan-done': (
            GObject.SignalFlags.RUN_LAST,
            None,
            # current page / total
            (GObject.TYPE_PYOBJECT, GObject.TYPE_INT)),
    }

    can_interrupt = True

    def __init__(self,
                 config,
                 nb_pages,
                 line_in_treeview,
                 docsearch,
                 doc=None):
        Worker.__init__(self, "Document scanner (doc %d)" % (line_in_treeview))
        self.__config = config
        self.docsearch = docsearch
        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 == ImgPage.SCAN_STEP_OCR:
            self.emit('ocr-start', self.current_page, self.nb_pages)

    def do(self, scan_src):
        if self.doc == None:
            self.doc = ImgDoc(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.scanner_calibration,
                                      self.__config.ocrlang,
                                      self.__progress_cb)
            page = self.doc.pages[self.doc.nb_pages - 1]
            self.docsearch.index_page(page)
            self.emit('scan-done', page, self.nb_pages)
        self.current_page = None
Пример #4
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, docsearch, doc=None):
        Worker.__init__(self, "Document scanner (doc %d)" % (line_in_treeview))
        self.__config = config
        self.docsearch = docsearch
        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 == ImgPage.SCAN_STEP_OCR:
            self.emit('ocr-start', self.current_page, self.nb_pages)

    def do(self, scan_src):
        if self.doc == None:
            self.doc = ImgDoc(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.scanner_calibration,
                                      self.__config.ocrlang,
                                      self.__progress_cb)
            page = self.doc.pages[self.doc.nb_pages - 1]
            self.docsearch.index_page(page)
            self.emit('scan-done', self.current_page, self.nb_pages)
        self.current_page = None