]>
Commit | Line | Data |
---|---|---|
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 | |
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 | ||
782f5926 | 23 | import argparse |
efdef4fa | 24 | import sigrok.core as sr |
782f5926 | 25 | import sys |
f94bb73f | 26 | import textwrap |
baf990de | 27 | import signal |
13e332b7 | 28 | |
739a1d54 | 29 | default_drivers = [('demo:analog_channels=4', 'samplerate=4')] |
782f5926 | 30 | |
1f199679 JS |
31 | def parse_cli(): |
32 | parser = argparse.ArgumentParser( | |
33 | description='Simple sigrok GUI for multimeters and dataloggers.', | |
34 | epilog=textwrap.dedent('''\ | |
8fa01018 UH |
35 | The DRIVER string is the same as for sigrok-cli(1). Multiple |
36 | DRIVER and CONFIG items can be supplied. The nth CONFIG is applied | |
37 | to the nth DRIVER. If there are more drivers than configs, the | |
38 | remaining drivers use the default configuration. | |
1f199679 | 39 | |
480cdb7b | 40 | Examples: |
1f199679 JS |
41 | |
42 | %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0 | |
43 | ||
44 | %(prog)s --driver uni-t-ut61e:conn=1a86.e008 | |
739a1d54 JS |
45 | |
46 | %(prog)s --driver demo:analog_channels=1 \\ | |
47 | --config samplerate=10 | |
8fa01018 UH |
48 | |
49 | %(prog)s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\ | |
50 | --driver uni-t-ut61d:conn=1a86.e008 \\ | |
51 | --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1 | |
1f199679 JS |
52 | '''), |
53 | formatter_class=argparse.RawDescriptionHelpFormatter) | |
54 | ||
55 | parser.add_argument('-d', '--driver', | |
56 | action='append', | |
739a1d54 | 57 | default=[], |
1f199679 | 58 | help='The driver to use') |
739a1d54 JS |
59 | parser.add_argument('-c', '--config', |
60 | action='append', | |
61 | default=[], | |
62 | help='Specify device configuration options') | |
1f199679 JS |
63 | parser.add_argument('-l', '--loglevel', |
64 | type=int, | |
a6fe45e1 | 65 | default=None, |
1f199679 JS |
66 | help='Set loglevel (5 is most verbose)') |
67 | parser.add_argument('--pyside', | |
68 | action='store_true', | |
69 | default=False, | |
70 | help='Force use of PySide (default is to use PyQt4)') | |
71 | args = parser.parse_args() | |
72 | ||
739a1d54 | 73 | if len(args.config) > len(args.driver): |
480cdb7b | 74 | sys.exit('Error: More configurations than drivers given.') |
739a1d54 | 75 | |
480cdb7b | 76 | # Merge drivers and configurations into a list of tuples. |
739a1d54 | 77 | setattr(args, 'drivers', []) |
4ce8c1c0 | 78 | if not args.driver: |
739a1d54 | 79 | args.drivers = default_drivers |
480cdb7b | 80 | sys.stderr.write('No driver given, using demo driver.\n') |
739a1d54 JS |
81 | if args.driver: |
82 | args.config.extend([''] * (len(args.driver) - len(args.config))) | |
83 | args.drivers = zip(args.driver, args.config) | |
84 | del args.driver | |
85 | del args.config | |
1f199679 | 86 | |
4ce8c1c0 | 87 | return args |
1f199679 JS |
88 | |
89 | if __name__ == '__main__': | |
baf990de JS |
90 | signal.signal(signal.SIGINT, signal.SIG_DFL) |
91 | ||
1f199679 JS |
92 | args = parse_cli() |
93 | ||
48723bbb | 94 | import qtcompat |
4ce8c1c0 | 95 | qtcompat.load_modules(args.pyside) |
48723bbb JS |
96 | QtCore = qtcompat.QtCore |
97 | QtGui = qtcompat.QtGui | |
98 | import mainwindow | |
58d308d1 | 99 | |
73f2129a | 100 | app = QtGui.QApplication([]) |
68348e5a | 101 | |
2abf5a93 JS |
102 | # Initialize modules that need a QApplication to exist. |
103 | import settings | |
104 | settings.init() | |
68348e5a JS |
105 | import icons |
106 | icons.load_icons() | |
107 | ||
a6fe45e1 JS |
108 | context = sr.Context_create() |
109 | ||
110 | if args.loglevel != None: | |
111 | try: | |
112 | loglevel = sr.LogLevel.get(args.loglevel) | |
113 | settings.logging.level.setValue(loglevel) | |
114 | except: | |
115 | sys.exit('Error: invalid log level.') | |
116 | ||
739a1d54 | 117 | s = mainwindow.MainWindow(context, args.drivers) |
73f2129a JS |
118 | s.show() |
119 | ||
e65cc368 | 120 | sys.exit(app.exec_()) |