]> sigrok.org Git - sigrok-meter.git/blame - sigrok-meter
Better driver string handling and better error messages.
[sigrok-meter.git] / sigrok-meter
CommitLineData
5add80f6
JS
1#!/usr/bin/env python
2
c09ca11b
UH
3##
4## This file is part of the sigrok-meter project.
5##
6## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
73f2129a 7## Copyright (C) 2014 Jens Steinhauser <jens.steinhauser@gmail.com>
c09ca11b
UH
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
782f5926 24import argparse
efdef4fa 25import sigrok.core as sr
782f5926 26import sys
f94bb73f 27import textwrap
13e332b7 28
dab07392 29default_drivers = ['demo:analog_channels=4']
782f5926
JS
30default_loglevel = sr.LogLevel.WARN
31
1f199679
JS
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 help='Set loglevel (5 is most verbose)')
52 parser.add_argument('--pyside',
53 action='store_true',
54 default=False,
55 help='Force use of PySide (default is to use PyQt4)')
56 args = parser.parse_args()
57
58 result = {
59 'drivers': default_drivers,
60 'loglevel': default_loglevel,
61 'pyside': args.pyside
62 }
63
64 if args.driver:
dab07392 65 result['drivers'] = args.driver
1f199679
JS
66
67 if args.loglevel != None:
68 try:
69 result['loglevel'] = sr.LogLevel.get(args.loglevel)
70 except:
71 sys.exit('error: invalid log level')
72
73 return result
74
75if __name__ == '__main__':
1f199679
JS
76 args = parse_cli()
77
48723bbb
JS
78 import qtcompat
79 qtcompat.load_modules(args['pyside'])
80 QtCore = qtcompat.QtCore
81 QtGui = qtcompat.QtGui
82 import mainwindow
58d308d1 83
e65cc368
JS
84 context = sr.Context_create()
85 context.log_level = args['loglevel']
73f2129a
JS
86
87 app = QtGui.QApplication([])
48723bbb 88 s = mainwindow.MainWindow(context, args['drivers'])
73f2129a
JS
89 s.show()
90
e65cc368 91 sys.exit(app.exec_())