]>
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, write to the Free Software | |
20 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | ## | |
22 | ||
23 | import argparse | |
24 | import sys | |
25 | import textwrap | |
26 | import signal | |
27 | ||
28 | default_drivers = [('demo:analog_channels=4', 'samplerate=4')] | |
29 | ||
30 | def parse_cli(): | |
31 | parser = argparse.ArgumentParser( | |
32 | description='Simple sigrok GUI for multimeters and dataloggers.', | |
33 | epilog=textwrap.dedent('''\ | |
34 | The DRIVER string is the same as for sigrok-cli(1). Multiple | |
35 | DRIVER and CONFIG items can be supplied. The nth CONFIG is applied | |
36 | to the nth DRIVER. If there are more drivers than configs, the | |
37 | remaining drivers use the default configuration. | |
38 | ||
39 | Examples: | |
40 | ||
41 | %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0 | |
42 | ||
43 | %(prog)s --driver uni-t-ut61e:conn=1a86.e008 | |
44 | ||
45 | %(prog)s --driver demo:analog_channels=1 \\ | |
46 | --config samplerate=10 | |
47 | ||
48 | %(prog)s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\ | |
49 | --driver uni-t-ut61d:conn=1a86.e008 \\ | |
50 | --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1 | |
51 | '''), | |
52 | formatter_class=argparse.RawDescriptionHelpFormatter) | |
53 | ||
54 | parser.add_argument('-d', '--driver', | |
55 | action='append', | |
56 | default=[], | |
57 | help='The driver to use') | |
58 | parser.add_argument('-c', '--config', | |
59 | action='append', | |
60 | default=[], | |
61 | help='Specify device configuration options') | |
62 | parser.add_argument('-l', '--loglevel', | |
63 | type=int, | |
64 | default=None, | |
65 | help='Set loglevel (5 is most verbose)') | |
66 | parser.add_argument('--pyside', | |
67 | action='store_true', | |
68 | default=False, | |
69 | help='Force use of PySide (default is to use PyQt4)') | |
70 | args = parser.parse_args() | |
71 | ||
72 | if len(args.config) > len(args.driver): | |
73 | sys.exit('Error: More configurations than drivers given.') | |
74 | ||
75 | # Merge drivers and configurations into a list of tuples. | |
76 | setattr(args, 'drivers', []) | |
77 | if not args.driver: | |
78 | args.drivers = default_drivers | |
79 | sys.stderr.write('No driver given, using demo driver.\n') | |
80 | if args.driver: | |
81 | args.config.extend([''] * (len(args.driver) - len(args.config))) | |
82 | args.drivers = zip(args.driver, args.config) | |
83 | del args.driver | |
84 | del args.config | |
85 | ||
86 | return args | |
87 | ||
88 | if __name__ == '__main__': | |
89 | signal.signal(signal.SIGINT, signal.SIG_DFL) | |
90 | ||
91 | args = parse_cli() | |
92 | ||
93 | import qtcompat | |
94 | qtcompat.load_modules(args.pyside) | |
95 | QtCore = qtcompat.QtCore | |
96 | QtGui = qtcompat.QtGui | |
97 | ||
98 | app = QtGui.QApplication([]) | |
99 | ||
100 | try: | |
101 | import sigrok.core as sr | |
102 | except Exception as e: | |
103 | QtGui.QMessageBox.critical(None, 'Error starting sigrok-meter', | |
104 | 'Unable to use the sigrok python bindings:\n{}'.format(e)) | |
105 | sys.exit(1) | |
106 | ||
107 | # Initialize modules that need a QApplication to exist. | |
108 | import settings | |
109 | settings.init() | |
110 | import icons | |
111 | icons.load_icons() | |
112 | ||
113 | context = sr.Context_create() | |
114 | ||
115 | if args.loglevel != None: | |
116 | try: | |
117 | loglevel = sr.LogLevel.get(args.loglevel) | |
118 | settings.logging.level.setValue(loglevel) | |
119 | except: | |
120 | sys.exit('Error: invalid log level.') | |
121 | ||
122 | import mainwindow | |
123 | s = mainwindow.MainWindow(context, args.drivers) | |
124 | s.show() | |
125 | ||
126 | sys.exit(app.exec_()) |