]> sigrok.org Git - sigrok-meter.git/blame - sigrok-meter
license: remove FSF postal address from boiler plate license text
[sigrok-meter.git] / sigrok-meter
CommitLineData
5add80f6 1#!/usr/bin/env python
c09ca11b
UH
2##
3## This file is part of the sigrok-meter project.
4##
5## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
73f2129a 6## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com>
c09ca11b
UH
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
0b63748b 19## along with this program; if not, see <http://www.gnu.org/licenses/>.
c09ca11b
UH
20##
21
782f5926 22import argparse
782f5926 23import sys
f94bb73f 24import textwrap
baf990de 25import signal
13e332b7 26
739a1d54 27default_drivers = [('demo:analog_channels=4', 'samplerate=4')]
782f5926 28
1f199679
JS
29def parse_cli():
30 parser = argparse.ArgumentParser(
31 description='Simple sigrok GUI for multimeters and dataloggers.',
32 epilog=textwrap.dedent('''\
8fa01018
UH
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.
1f199679 37
480cdb7b 38 Examples:
1f199679
JS
39
40 %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0
41
42 %(prog)s --driver uni-t-ut61e:conn=1a86.e008
739a1d54
JS
43
44 %(prog)s --driver demo:analog_channels=1 \\
45 --config samplerate=10
8fa01018
UH
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
1f199679
JS
50 '''),
51 formatter_class=argparse.RawDescriptionHelpFormatter)
52
53 parser.add_argument('-d', '--driver',
54 action='append',
739a1d54 55 default=[],
1f199679 56 help='The driver to use')
739a1d54
JS
57 parser.add_argument('-c', '--config',
58 action='append',
59 default=[],
60 help='Specify device configuration options')
1f199679
JS
61 parser.add_argument('-l', '--loglevel',
62 type=int,
a6fe45e1 63 default=None,
1f199679
JS
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
739a1d54 71 if len(args.config) > len(args.driver):
480cdb7b 72 sys.exit('Error: More configurations than drivers given.')
739a1d54 73
480cdb7b 74 # Merge drivers and configurations into a list of tuples.
739a1d54 75 setattr(args, 'drivers', [])
4ce8c1c0 76 if not args.driver:
739a1d54 77 args.drivers = default_drivers
480cdb7b 78 sys.stderr.write('No driver given, using demo driver.\n')
739a1d54
JS
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
1f199679 84
4ce8c1c0 85 return args
1f199679
JS
86
87if __name__ == '__main__':
baf990de
JS
88 signal.signal(signal.SIGINT, signal.SIG_DFL)
89
1f199679
JS
90 args = parse_cli()
91
48723bbb 92 import qtcompat
4ce8c1c0 93 qtcompat.load_modules(args.pyside)
48723bbb
JS
94 QtCore = qtcompat.QtCore
95 QtGui = qtcompat.QtGui
58d308d1 96
73f2129a 97 app = QtGui.QApplication([])
68348e5a 98
4946c320
JS
99 try:
100 import sigrok.core as sr
101 except Exception as e:
102 QtGui.QMessageBox.critical(None, 'Error starting sigrok-meter',
911ab26e 103 'Unable to use the sigrok Python bindings:\n{}.'.format(e))
4946c320
JS
104 sys.exit(1)
105
2abf5a93
JS
106 # Initialize modules that need a QApplication to exist.
107 import settings
108 settings.init()
68348e5a
JS
109 import icons
110 icons.load_icons()
111
a6fe45e1
JS
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
4946c320 121 import mainwindow
739a1d54 122 s = mainwindow.MainWindow(context, args.drivers)
73f2129a
JS
123 s.show()
124
e65cc368 125 sys.exit(app.exec_())