Search code examples
pythonqr-codezbar

Limit Zbar to QR code only in Python


I'm using Zbar with it's Processor option in Python. I've been trying to figure out how to limit the symbology to QR-code only, but have only found answers for C as it follows:

scanner = new ImageScanner();
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);

I understand that the original code is written for C but is there anyway to do it in Python? Python isn't my main language and it's a bit difficult for me to understand what the arguments are in this case for processor.parse_config() (which I have currently set to 'enable'):

From https://github.com/npinchot/zbar/blob/master/processor.c

static PyObject*
processor_parse_config (zbarProcessor *self,
                    PyObject *args,
                    PyObject *kwds)
{
    const char *cfg = NULL;
    static char *kwlist[] = { "config", NULL };
    if(!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &cfg))
        return(NULL);

    if(zbar_processor_parse_config(self->zproc, cfg)) {
        PyErr_Format(PyExc_ValueError, "invalid configuration setting: %s",
                 cfg);
        return(NULL);
    }
    Py_RETURN_NONE;
}

I don't even understand why 'enable' is a valid argument.


Solution

  • Took me some time to figure this out since there's no documentation and the config format is counter-intuitive, IMO, but here you go:

    proc.parse_config('disable')
    proc.parse_config('qrcode.enable')
    

    The first line, disable, disables all scanners. The second line enables the qrcode scanner.