]> sigrok.org Git - sigrok-meter.git/blobdiff - sigrok-meter
license: remove FSF postal address from boiler plate license text
[sigrok-meter.git] / sigrok-meter
index ffda9471f41bf00b4ea4be7b3fe6e7c9aae45b79..b2f60070d5442d284d76a58aa74b814599e458f6 100755 (executable)
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 ##
 ## This file is part of the sigrok-meter project.
 ##
 ## 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
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
 ##
 
 import argparse
-import sigrok.core as sr
 import sys
 import textwrap
+import signal
 
 default_drivers = [('demo:analog_channels=4', 'samplerate=4')]
-default_loglevel = 2
 
 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). The nth
-            CONFIG is applied to the nth DRIVER. If there are more drivers
-            than configs, the remaining drivers use the default configuration.
+            The DRIVER string is the same as for sigrok-cli(1). Multiple
+            DRIVER and CONFIG items can be supplied. The nth CONFIG is applied
+            to the nth DRIVER. If there are more drivers than configs, the
+            remaining drivers use the default configuration.
 
-            examples:
+            Examples:
 
               %(prog)s --driver tecpel-dmm-8061-ser:conn=/dev/ttyUSB0
 
@@ -45,6 +43,10 @@ def parse_cli():
 
               %(prog)s --driver demo:analog_channels=1 \\
                        --config samplerate=10
+
+              %(prog)s --driver voltcraft-k204:conn=/dev/ttyUSB0 \\
+                       --driver uni-t-ut61d:conn=1a86.e008 \\
+                       --driver uni-t-ut61e-ser:conn=/dev/ttyUSB1
         '''),
         formatter_class=argparse.RawDescriptionHelpFormatter)
 
@@ -58,7 +60,7 @@ def parse_cli():
         help='Specify device configuration options')
     parser.add_argument('-l', '--loglevel',
         type=int,
-        default=default_loglevel,
+        default=None,
         help='Set loglevel (5 is most verbose)')
     parser.add_argument('--pyside',
         action='store_true',
@@ -67,13 +69,13 @@ def parse_cli():
     args = parser.parse_args()
 
     if len(args.config) > len(args.driver):
-        sys.exit('error: more configurations than drivers given')
+        sys.exit('Error: More configurations than drivers given.')
 
-    # merge drivers and configurations into a list of tuples
+    # Merge drivers and configurations into a list of tuples.
     setattr(args, 'drivers', [])
     if not args.driver:
         args.drivers = default_drivers
-        sys.stderr.write('no driver given, using demo driver\n')
+        sys.stderr.write('No driver given, using demo driver.\n')
     if args.driver:
         args.config.extend([''] * (len(args.driver) - len(args.config)))
         args.drivers = zip(args.driver, args.config)
@@ -83,22 +85,40 @@ def parse_cli():
     return args
 
 if __name__ == '__main__':
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
+
     args = parse_cli()
 
     import qtcompat
     qtcompat.load_modules(args.pyside)
     QtCore = qtcompat.QtCore
     QtGui = qtcompat.QtGui
-    import mainwindow
 
-    context = sr.Context_create()
+    app = QtGui.QApplication([])
+
     try:
-        loglevel = sr.LogLevel.get(args.loglevel)
-        context.log_level = loglevel
-    except:
-        sys.exit('error: invalid log level')
+        import sigrok.core as sr
+    except Exception as e:
+        QtGui.QMessageBox.critical(None, 'Error starting sigrok-meter',
+           'Unable to use the sigrok Python bindings:\n{}.'.format(e))
+        sys.exit(1)
+
+    # Initialize modules that need a QApplication to exist.
+    import settings
+    settings.init()
+    import icons
+    icons.load_icons()
 
-    app = QtGui.QApplication([])
+    context = sr.Context_create()
+
+    if args.loglevel != None:
+        try:
+            loglevel = sr.LogLevel.get(args.loglevel)
+            settings.logging.level.setValue(loglevel)
+        except:
+            sys.exit('Error: invalid log level.')
+
+    import mainwindow
     s = mainwindow.MainWindow(context, args.drivers)
     s.show()