]>
Commit | Line | Data |
---|---|---|
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 | 24 | import argparse |
f94bb73f | 25 | import re |
efdef4fa | 26 | import sigrok.core as sr |
782f5926 | 27 | import sys |
f94bb73f | 28 | import textwrap |
13e332b7 | 29 | |
58d308d1 | 30 | default_drivers = [('demo', {'analog_channels': 4})] |
782f5926 JS |
31 | default_loglevel = sr.LogLevel.WARN |
32 | ||
1f199679 JS |
33 | def parse_cli(): |
34 | parser = argparse.ArgumentParser( | |
35 | description='Simple sigrok GUI for multimeters and dataloggers.', | |
36 | epilog=textwrap.dedent('''\ | |
37 | The DRIVER string is the same as for sigrok-cli(1). | |
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 | formatter_class=argparse.RawDescriptionHelpFormatter) | |
46 | ||
47 | parser.add_argument('-d', '--driver', | |
48 | action='append', | |
49 | help='The driver to use') | |
50 | parser.add_argument('-l', '--loglevel', | |
51 | type=int, | |
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 | result = { | |
60 | 'drivers': default_drivers, | |
61 | 'loglevel': default_loglevel, | |
62 | 'pyside': args.pyside | |
63 | } | |
64 | ||
65 | if args.driver: | |
66 | result['drivers'] = [] | |
67 | for d in args.driver: | |
68 | m = re.match('(?P<name>[^:]+)(?P<opts>(:[^:=]+=[^:=]+)*)', d) | |
69 | if not m: | |
70 | sys.exit('error parsing option "{}"'.format(d)) | |
71 | ||
72 | opts = m.group('opts').split(':')[1:] | |
73 | opts = [tuple(kv.split('=')) for kv in opts] | |
74 | opts = dict(opts) | |
75 | ||
76 | result['drivers'].append((m.group('name'), opts)) | |
77 | ||
78 | if args.loglevel != None: | |
79 | try: | |
80 | result['loglevel'] = sr.LogLevel.get(args.loglevel) | |
81 | except: | |
82 | sys.exit('error: invalid log level') | |
83 | ||
84 | return result | |
85 | ||
86 | if __name__ == '__main__': | |
1f199679 JS |
87 | args = parse_cli() |
88 | ||
48723bbb JS |
89 | import qtcompat |
90 | qtcompat.load_modules(args['pyside']) | |
91 | QtCore = qtcompat.QtCore | |
92 | QtGui = qtcompat.QtGui | |
93 | import mainwindow | |
58d308d1 | 94 | |
e65cc368 JS |
95 | context = sr.Context_create() |
96 | context.log_level = args['loglevel'] | |
73f2129a JS |
97 | |
98 | app = QtGui.QApplication([]) | |
48723bbb | 99 | s = mainwindow.MainWindow(context, args['drivers']) |
73f2129a JS |
100 | s.show() |
101 | ||
e65cc368 | 102 | sys.exit(app.exec_()) |