]> sigrok.org Git - sigrok-meter.git/blob - sigrok-meter
Fix a bug with color picking.
[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 import signal
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). Multiple
37             DRIVER and CONFIG items can be supplied. The nth CONFIG is applied
38             to the nth DRIVER. If there are more drivers than configs, the
39             remaining drivers use the default configuration.
40
41             Examples:
42
43               %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0
44
45               %(prog)s --driver uni-t-ut61e:conn=1a86.e008
46
47               %(prog)s --driver demo:analog_channels=1 \\
48                        --config samplerate=10
49
50               %(prog)s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\
51                        --driver uni-t-ut61d:conn=1a86.e008 \\
52                        --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1
53         '''),
54         formatter_class=argparse.RawDescriptionHelpFormatter)
55
56     parser.add_argument('-d', '--driver',
57         action='append',
58         default=[],
59         help='The driver to use')
60     parser.add_argument('-c', '--config',
61         action='append',
62         default=[],
63         help='Specify device configuration options')
64     parser.add_argument('-l', '--loglevel',
65         type=int,
66         default=default_loglevel,
67         help='Set loglevel (5 is most verbose)')
68     parser.add_argument('--pyside',
69         action='store_true',
70         default=False,
71         help='Force use of PySide (default is to use PyQt4)')
72     args = parser.parse_args()
73
74     if len(args.config) > len(args.driver):
75         sys.exit('Error: More configurations than drivers given.')
76
77     # Merge drivers and configurations into a list of tuples.
78     setattr(args, 'drivers', [])
79     if not args.driver:
80         args.drivers = default_drivers
81         sys.stderr.write('No driver given, using demo driver.\n')
82     if args.driver:
83         args.config.extend([''] * (len(args.driver) - len(args.config)))
84         args.drivers = zip(args.driver, args.config)
85     del args.driver
86     del args.config
87
88     return args
89
90 if __name__ == '__main__':
91     signal.signal(signal.SIGINT, signal.SIG_DFL)
92
93     args = parse_cli()
94
95     import qtcompat
96     qtcompat.load_modules(args.pyside)
97     QtCore = qtcompat.QtCore
98     QtGui = qtcompat.QtGui
99     import mainwindow
100
101     context = sr.Context_create()
102     try:
103         loglevel = sr.LogLevel.get(args.loglevel)
104         context.log_level = loglevel
105     except:
106         sys.exit('Error: invalid log level.')
107
108     app = QtGui.QApplication([])
109     s = mainwindow.MainWindow(context, args.drivers)
110     s.show()
111
112     sys.exit(app.exec_())