Ejemplo n.º 1
0
    def __call__(self, progress):
        """
        """
        debug_print('BarcodePlugin.__call__')

        if InliteEngine.available():
            engine = InliteEngine(datamatrix=True)
        elif LibDMTXEngine.available():
            engine = LibDMTXEngine()
        else:
            raise InselectError('No barcode decoding engine available')

        progress('Loading full-res image')
        image_array = self.document.scanned.array

        items = self.document.items
        for index, item, crop in izip(count(), items, self.document.crops):
            msg = u'Reading barcodes in box {0} of {1}'.format(1 + index, len(items))
            progress(msg)
            barcodes = self._decode_barcodes(engine, crop, progress)
            if barcodes:
                debug_print('Crop [{0}] - found [{1}]'.format(index, barcodes))

                # TODO LH This mapping to come from metadata config?
                item['fields']['catalogNumber'] = barcodes
            else:
                debug_print('Crop [{0}] - no barcodes'.format(index))

        self.items = items

        debug_print('BarcodePlugin.__call__ exiting. [{0}] boxes'.format(len(items)))
Ejemplo n.º 2
0
def load_engine():
    """Returns an instance of the user's choice of barcode reading engine
    """
    try:
        from gouda.engines import InliteEngine, LibDMTXEngine, ZbarEngine
    except ImportError:
        raise InselectError('Barcode decoding is not available')
    else:
        settings = current_settings()
        engine = settings['engine']
        if 'libdmtx' == engine:
            return LibDMTXEngine()
        elif 'zbar' == engine:
            return ZbarEngine()
        elif 'inlite' == engine:
            return InliteEngine(settings['inlite-format'])
        else:
            raise ValueError(
                'Unrecognised barcode reader [{0}]'.format(engine))