diff options
-rwxr-xr-x | src/util/gnunet-qr.py.in | 95 |
1 files changed, 53 insertions, 42 deletions
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in index 086f6ae84..de4849023 100755 --- a/src/util/gnunet-qr.py.in +++ b/src/util/gnunet-qr.py.in | |||
@@ -12,7 +12,9 @@ def help (): | |||
12 | print 'gnunet-qr\n\ | 12 | print 'gnunet-qr\n\ |
13 | Scan a QR code using a video device and import\n\ | 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\ | 14 | Arguments mandatory for long options are also mandatory for short options.\n\ |
15 | -c, --config=FILENAME use configuration file FILENAME\n\ | ||
15 | -d, --device=DEVICE use device DEVICE\n\ | 16 | -d, --device=DEVICE use device DEVICE\n\ |
17 | -s, --silent do not show preview windows\n\ | ||
16 | -h, --help print this help\n\ | 18 | -h, --help print this help\n\ |
17 | Report bugs to gnunet-developers@gnu.org.\n\ | 19 | Report bugs to gnunet-developers@gnu.org.\n\ |
18 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ | 20 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ |
@@ -20,48 +22,57 @@ General help using GNU software: http://www.gnu.org/gethelp/' | |||
20 | 22 | ||
21 | 23 | ||
22 | if __name__ == '__main__': | 24 | if __name__ == '__main__': |
23 | # Parse arguments | 25 | configuration = '' |
24 | try: | 26 | device = '/dev/video0' |
25 | opts, args = getopt.gnu_getopt(sys.argv[1:], "hd:", ["help", "device"]) | 27 | silent = False |
26 | except getopt.GetoptError as e: | 28 | # Parse arguments |
27 | help () | 29 | try: |
28 | print str (e) | 30 | opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:s", ["config","help", "device","silent"]) |
29 | exit (1) | 31 | except getopt.GetoptError as e: |
30 | 32 | help () | |
31 | device = '/dev/video0' | 33 | print str (e) |
32 | for o,a in opts: | 34 | exit (1) |
33 | if o in ("-h", "--help"): | ||
34 | help () | ||
35 | sys.exit (0) | ||
36 | elif o in ("-d", "--device"): | ||
37 | device = a | ||
38 | # create a Processor | ||
39 | proc = zbar.Processor() | ||
40 | 35 | ||
41 | # configure the Processor | 36 | for o,a in opts: |
42 | proc.parse_config('enable') | 37 | if o in ("-h", "--help"): |
38 | help () | ||
39 | sys.exit (0) | ||
40 | elif o in ("-c", "--config"): | ||
41 | configuration = a | ||
42 | elif o in ("-d", "--device"): | ||
43 | device = a | ||
44 | elif o in ("-s", "--silent"): | ||
45 | silent = True | ||
46 | # create a Processor | ||
47 | proc = zbar.Processor() | ||
43 | 48 | ||
44 | # initialize the Processor | 49 | # configure the Processor |
45 | try: | 50 | proc.parse_config('enable') |
46 | proc.init(device) | ||
47 | except Exception as e: | ||
48 | print 'Failed to open device ' + device | ||
49 | exit (1) | ||
50 | 51 | ||
51 | # enable the preview window | 52 | # initialize the Processor |
52 | proc.visible = True | 53 | try: |
53 | 54 | proc.init(device) | |
54 | # read at least one barcode (or until window closed) | 55 | except Exception as e: |
55 | try: | 56 | print 'Failed to open device ' + device |
56 | proc.process_one() | 57 | exit (1) |
57 | except Exception as e: | 58 | |
58 | # Window was closed without finding code | 59 | # enable the preview window |
59 | exit (1) | 60 | if (True == silent): |
60 | 61 | proc.visible = True | |
61 | # hide the preview window | 62 | else: |
62 | proc.visible = False | 63 | proc.visible = False |
63 | 64 | ||
64 | # extract results | 65 | # read at least one barcode (or until window closed) |
65 | for symbol in proc.results: | 66 | try: |
66 | # do something useful with results | 67 | proc.process_one() |
67 | print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data | 68 | except Exception as e: |
69 | # Window was closed without finding code | ||
70 | exit (1) | ||
71 | |||
72 | # hide the preview window | ||
73 | proc.visible = False | ||
74 | |||
75 | # extract results | ||
76 | for symbol in proc.results: | ||
77 | # do something useful with results | ||
78 | print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data \ No newline at end of file | ||