]> sigrok.org Git - sigrok-meter.git/blame_incremental - sigrok-meter
Shorten argument parsing.
[sigrok-meter.git] / sigrok-meter
... / ...
CommitLineData
1#!/usr/bin/env python
2
3##
4## This file is part of the sigrok-meter project.
5##
6## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
7## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com>
8##
9## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published by
11## the Free Software Foundation; either version 2 of the License, or
12## (at your option) any later version.
13##
14## This program is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17## GNU General Public License for more details.
18##
19## You should have received a copy of the GNU General Public License
20## along with this program; if not, write to the Free Software
21## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22##
23
24import argparse
25import sigrok.core as sr
26import sys
27import textwrap
28
29default_drivers = ['demo:analog_channels=4']
30default_loglevel = 2
31
32def 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).
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 formatter_class=argparse.RawDescriptionHelpFormatter)
45
46 parser.add_argument('-d', '--driver',
47 action='append',
48 help='The driver to use')
49 parser.add_argument('-l', '--loglevel',
50 type=int,
51 default=default_loglevel,
52 help='Set loglevel (5 is most verbose)')
53 parser.add_argument('--pyside',
54 action='store_true',
55 default=False,
56 help='Force use of PySide (default is to use PyQt4)')
57 args = parser.parse_args()
58
59 if not args.driver:
60 args.driver = default_drivers
61
62 return args
63
64if __name__ == '__main__':
65 args = parse_cli()
66
67 import qtcompat
68 qtcompat.load_modules(args.pyside)
69 QtCore = qtcompat.QtCore
70 QtGui = qtcompat.QtGui
71 import mainwindow
72
73 context = sr.Context_create()
74 try:
75 loglevel = sr.LogLevel.get(args.loglevel)
76 context.log_level = loglevel
77 except:
78 sys.exit('error: invalid log level')
79
80 app = QtGui.QApplication([])
81 s = mainwindow.MainWindow(context, args.driver)
82 s.show()
83
84 sys.exit(app.exec_())