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