]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | ||
3 | ## | |
4 | ## This file is part of the sigrok-meter project. | |
5 | ## | |
6 | ## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de> | |
7 | ## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com> | |
8 | ## | |
9 | ## This program is free software; you can redistribute it and/or modify | |
10 | ## it under the terms of the GNU General Public License as published by | |
11 | ## the Free Software Foundation; either version 2 of the License, or | |
12 | ## (at your option) any later version. | |
13 | ## | |
14 | ## This program is distributed in the hope that it will be useful, | |
15 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ## GNU General Public License for more details. | |
18 | ## | |
19 | ## You should have received a copy of the GNU General Public License | |
20 | ## along with this program; if not, write to the Free Software | |
21 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
22 | ## | |
23 | ||
24 | import argparse | |
25 | import sigrok.core as sr | |
26 | import sys | |
27 | import textwrap | |
28 | ||
29 | default_drivers = [('demo:analog_channels=4', 'samplerate=4')] | |
30 | default_loglevel = 2 | |
31 | ||
32 | def parse_cli(): | |
33 | parser = argparse.ArgumentParser( | |
34 | description='Simple sigrok GUI for multimeters and dataloggers.', | |
35 | epilog=textwrap.dedent('''\ | |
36 | The DRIVER string is the same as for sigrok-cli(1). The nth | |
37 | CONFIG is applied to the nth DRIVER. If there are more drivers | |
38 | than configs, the remaining drivers use the default configuration. | |
39 | ||
40 | examples: | |
41 | ||
42 | %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0 | |
43 | ||
44 | %(prog)s --driver uni-t-ut61e:conn=1a86.e008 | |
45 | ||
46 | %(prog)s --driver demo:analog_channels=1 \\ | |
47 | --config samplerate=10 | |
48 | '''), | |
49 | formatter_class=argparse.RawDescriptionHelpFormatter) | |
50 | ||
51 | parser.add_argument('-d', '--driver', | |
52 | action='append', | |
53 | default=[], | |
54 | help='The driver to use') | |
55 | parser.add_argument('-c', '--config', | |
56 | action='append', | |
57 | default=[], | |
58 | help='Specify device configuration options') | |
59 | parser.add_argument('-l', '--loglevel', | |
60 | type=int, | |
61 | default=default_loglevel, | |
62 | help='Set loglevel (5 is most verbose)') | |
63 | parser.add_argument('--pyside', | |
64 | action='store_true', | |
65 | default=False, | |
66 | help='Force use of PySide (default is to use PyQt4)') | |
67 | args = parser.parse_args() | |
68 | ||
69 | if len(args.config) > len(args.driver): | |
70 | sys.exit('error: more configurations than drivers given') | |
71 | ||
72 | # merge drivers and configurations into a list of tuples | |
73 | setattr(args, 'drivers', []) | |
74 | if not args.driver: | |
75 | args.drivers = default_drivers | |
76 | sys.stderr.write('no driver given, using demo driver\n') | |
77 | if args.driver: | |
78 | args.config.extend([''] * (len(args.driver) - len(args.config))) | |
79 | args.drivers = zip(args.driver, args.config) | |
80 | del args.driver | |
81 | del args.config | |
82 | ||
83 | return args | |
84 | ||
85 | if __name__ == '__main__': | |
86 | args = parse_cli() | |
87 | ||
88 | import qtcompat | |
89 | qtcompat.load_modules(args.pyside) | |
90 | QtCore = qtcompat.QtCore | |
91 | QtGui = qtcompat.QtGui | |
92 | import mainwindow | |
93 | ||
94 | context = sr.Context_create() | |
95 | try: | |
96 | loglevel = sr.LogLevel.get(args.loglevel) | |
97 | context.log_level = loglevel | |
98 | except: | |
99 | sys.exit('error: invalid log level') | |
100 | ||
101 | app = QtGui.QApplication([]) | |
102 | s = mainwindow.MainWindow(context, args.drivers) | |
103 | s.show() | |
104 | ||
105 | sys.exit(app.exec_()) |