zbar for windows
This commit is contained in:
@@ -29,8 +29,8 @@ import ctypes
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
name = 'libzbar.dylib'
|
||||
elif sys.platform == 'windows':
|
||||
name = 'libzbar.dll'
|
||||
elif sys.platform in ('windows', 'win32'):
|
||||
name = 'libzbar-0.dll'
|
||||
else:
|
||||
name = 'libzbar.so.0'
|
||||
|
||||
@@ -40,7 +40,7 @@ except OSError:
|
||||
libzbar = None
|
||||
|
||||
|
||||
def scan_barcode(device='', timeout=-1, display=True, threaded=False):
|
||||
def scan_barcode(device='', timeout=-1, display=True, threaded=False, try_again=True):
|
||||
if libzbar is None:
|
||||
raise RuntimeError("Cannot start QR scanner; zbar not available.")
|
||||
libzbar.zbar_symbol_get_data.restype = ctypes.c_char_p
|
||||
@@ -50,6 +50,10 @@ def scan_barcode(device='', timeout=-1, display=True, threaded=False):
|
||||
proc = libzbar.zbar_processor_create(threaded)
|
||||
libzbar.zbar_processor_request_size(proc, 640, 480)
|
||||
if libzbar.zbar_processor_init(proc, device.encode('utf-8'), display) != 0:
|
||||
if try_again:
|
||||
# workaround for a bug in "ZBar for Windows"
|
||||
# libzbar.zbar_processor_init always seem to fail the first time around
|
||||
return scan_barcode(device, timeout, display, threaded, try_again=False)
|
||||
raise RuntimeError("Can not start QR scanner; initialization failed.")
|
||||
libzbar.zbar_processor_set_visible(proc)
|
||||
if libzbar.zbar_process_one(proc, timeout):
|
||||
|
||||
Reference in New Issue
Block a user