From 1dbd84b96370a31802cdae2eb2d6f13db678b2f6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 6 Jun 2014 16:40:49 +0200 Subject: [PATCH] Simplify _get_qt_args --- qutebrowser/app.py | 20 ++++++++------------ qutebrowser/qutebrowser.py | 24 +++++++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index e9f9a42ed..9c503e932 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -159,19 +159,15 @@ class Application(QApplication): qt_args = ['style', 'stylesheet', 'widget-count', 'reverse', 'qmljsdebugger'] for argname in qt_args: - try: - val = getattr(namespace, 'qt_' + argname) - except AttributeError: - pass + val = getattr(namespace, 'qt_' + argname, None) + if val is None: + # flag/argument not given + continue + elif val is True: + argv.append('-' + argname) else: - if val is True: - argv.append('-' + argname) - elif val in [False, None]: - # flag/argument not given - pass - else: - argv.append('-' + argname) - argv.append(val) + argv.append('-' + argname) + argv.append(val) log.init.debug("Qt arguments: {}, based on {}".format(argv, namespace)) return argv diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index a2bc03624..aa6387240 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -38,17 +38,22 @@ def _parse_args(): action='store_true') debug = parser.add_argument_group('debug arguments') debug.add_argument('-l', '--loglevel', dest='loglevel', - help="Set loglevel", default='info') + help="Set loglevel", default='info') debug.add_argument('--logfilter', - help="Comma-separated list of things to be logged " - "to the debug log on stdout.") + help="Comma-separated list of things to be logged " + "to the debug log on stdout.") debug.add_argument('--debug', help="Turn on debugging options.", - action='store_true') + action='store_true') debug.add_argument('--nocolor', help="Turn off colored logging.", - action='store_false', dest='color') + action='store_false', dest='color') debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'], - default='auto', help="HarfBuzz engine version to use. " - "Default: auto.") + default='auto', help="HarfBuzz engine version to use. " + "Default: auto.") + # Some notes on the Qt options: + # - If a new option is added, it also needs to be added to _get_qt_args in + # app.py. + # - We use store_const with const=True rather than store_true because we + # want the default to be None. debug.add_argument('--qt-style', help="Set the Qt GUI style to use.", metavar='STYLE') debug.add_argument('--qt-stylesheet', help="Override the Qt application " @@ -56,9 +61,10 @@ def _parse_args(): debug.add_argument('--qt-widget-count', help="Print debug message at the " "end about number of widgets left undestroyed and " "maximum number of widgets existed at the same time.", - action='store_true') + action='store_const', const=True) debug.add_argument('--qt-reverse', help="Set the application's layout " - "direction to right-to-left.", action='store_true') + "direction to right-to-left.", action='store_const', + const=True) debug.add_argument('--qt-qmljsdebugger', help="Activate the QML/JS " "debugger with a specified port. 'block' is optional " "and will make the application wait until a debugger "