#!/usr/bin/env python ## ## This file is part of the sigrok-meter project. ## ## Copyright (C) 2013 Uwe Hermann ## Copyright (C) 2014 Jens Steinhauser ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## import argparse import re import sigrok.core as sr import sys import textwrap default_drivers = [('demo', {'analog_channels': 4})] default_loglevel = sr.LogLevel.WARN def parse_cli(): parser = argparse.ArgumentParser( description='Simple sigrok GUI for multimeters and dataloggers.', epilog=textwrap.dedent('''\ The DRIVER string is the same as for sigrok-cli(1). examples: %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0 %(prog)s --driver uni-t-ut61e:conn=1a86.e008 '''), formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-d', '--driver', action='append', help='The driver to use') parser.add_argument('-l', '--loglevel', type=int, help='Set loglevel (5 is most verbose)') parser.add_argument('--pyside', action='store_true', default=False, help='Force use of PySide (default is to use PyQt4)') args = parser.parse_args() result = { 'drivers': default_drivers, 'loglevel': default_loglevel, 'pyside': args.pyside } if args.driver: result['drivers'] = [] for d in args.driver: m = re.match('(?P[^:]+)(?P(:[^:=]+=[^:=]+)*)', d) if not m: sys.exit('error parsing option "{}"'.format(d)) opts = m.group('opts').split(':')[1:] opts = [tuple(kv.split('=')) for kv in opts] opts = dict(opts) result['drivers'].append((m.group('name'), opts)) if args.loglevel != None: try: result['loglevel'] = sr.LogLevel.get(args.loglevel) except: sys.exit('error: invalid log level') return result if __name__ == '__main__': args = parse_cli() import qtcompat qtcompat.load_modules(args['pyside']) QtCore = qtcompat.QtCore QtGui = qtcompat.QtGui import mainwindow context = sr.Context_create() context.log_level = args['loglevel'] app = QtGui.QApplication([]) s = mainwindow.MainWindow(context, args['drivers']) s.show() sys.exit(app.exec_())