7 except ImportError as e:
8 print 'Cannot run gnunet-qr, please install zbar-python'
13 Scan a QR code using a video device and import\n\
14 Arguments mandatory for long options are also mandatory for short options.\n\
15 -c, --config=FILENAME use configuration file FILENAME\n\
16 -d, --device=DEVICE use device DEVICE\n\
17 -s, --silent do not show preview windows\n\
18 -h, --help print this help\n\
19 Report bugs to gnunet-developers@gnu.org.\n\
20 GNUnet home page: http://www.gnu.org/software/gnunet/\n\
21 General help using GNU software: http://www.gnu.org/gethelp/'
24 if __name__ == '__main__':
26 device = '/dev/video0'
30 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:s", ["config","help", "device","silent"])
31 except getopt.GetoptError as e:
37 if o in ("-h", "--help"):
40 elif o in ("-c", "--config"):
42 elif o in ("-d", "--device"):
44 elif o in ("-s", "--silent"):
47 proc = zbar.Processor()
49 # configure the Processor
50 proc.parse_config('enable')
52 # initialize the Processor
55 except Exception as e:
56 print 'Failed to open device ' + device
59 # enable the preview window
65 # read at least one barcode (or until window closed)
68 except Exception as e:
69 # Window was closed without finding code
72 # hide the preview window
76 for symbol in proc.results:
77 # do something useful with results
78 print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data