]> sigrok.org Git - sigrok-meter.git/blob - sigrok-meter
884ad2d08781a187db2f83f67615484166061ca8
[sigrok-meter.git] / sigrok-meter
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 sigrok.core as sr
25 import sys
26 import textwrap
27
28 default_drivers = [('demo:analog_channels=4', 'samplerate=4')]
29 default_loglevel = 2
30
31 def parse_cli():
32     parser = argparse.ArgumentParser(
33         description='Simple sigrok GUI for multimeters and dataloggers.',
34         epilog=textwrap.dedent('''\
35             The DRIVER string is the same as for sigrok-cli(1). The nth
36             CONFIG is applied to the nth DRIVER. If there are more drivers
37             than configs, the 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         formatter_class=argparse.RawDescriptionHelpFormatter)
49
50     parser.add_argument('-d', '--driver',
51         action='append',
52         default=[],
53         help='The driver to use')
54     parser.add_argument('-c', '--config',
55         action='append',
56         default=[],
57         help='Specify device configuration options')
58     parser.add_argument('-l', '--loglevel',
59         type=int,
60         default=default_loglevel,
61         help='Set loglevel (5 is most verbose)')
62     parser.add_argument('--pyside',
63         action='store_true',
64         default=False,
65         help='Force use of PySide (default is to use PyQt4)')
66     args = parser.parse_args()
67
68     if len(args.config) > len(args.driver):
69         sys.exit('Error: More configurations than drivers given.')
70
71     # Merge drivers and configurations into a list of tuples.
72     setattr(args, 'drivers', [])
73     if not args.driver:
74         args.drivers = default_drivers
75         sys.stderr.write('No driver given, using demo driver.\n')
76     if args.driver:
77         args.config.extend([''] * (len(args.driver) - len(args.config)))
78         args.drivers = zip(args.driver, args.config)
79     del args.driver
80     del args.config
81
82     return args
83
84 if __name__ == '__main__':
85     args = parse_cli()
86
87     import qtcompat
88     qtcompat.load_modules(args.pyside)
89     QtCore = qtcompat.QtCore
90     QtGui = qtcompat.QtGui
91     import mainwindow
92
93     context = sr.Context_create()
94     try:
95         loglevel = sr.LogLevel.get(args.loglevel)
96         context.log_level = loglevel
97     except:
98         sys.exit('Error: invalid log level.')
99
100     app = QtGui.QApplication([])
101     s = mainwindow.MainWindow(context, args.drivers)
102     s.show()
103
104     sys.exit(app.exec_())