From 1179d84ee8600d5a345d4df707dcae0ede21ecf3 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 6 Jun 2014 16:32:57 +0200 Subject: [PATCH] Process Qt args via argparse --- qutebrowser/app.py | 31 ++++++++++++++++++++++++++++++- qutebrowser/qutebrowser.py | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 9eda50817..e9f9a42ed 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -94,7 +94,7 @@ class Application(QApplication): Args: Argument namespace from argparse. """ - super().__init__(sys.argv) + super().__init__(self._get_qt_args(args)) self._quit_status = { 'crash': True, 'tabs': False, @@ -146,6 +146,35 @@ class Application(QApplication): if self._crashdlg is not None: self._crashdlg.raise_() + def _get_qt_args(self, namespace): + """Get the Qt QApplication arguments based on an argparse namespace. + + Args: + namespace: The argparse namespace. + + Return: + The argv list to be passed to Qt. + """ + argv = [sys.argv[0]] + qt_args = ['style', 'stylesheet', 'widget-count', 'reverse', + 'qmljsdebugger'] + for argname in qt_args: + try: + val = getattr(namespace, 'qt_' + argname) + except AttributeError: + pass + 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) + log.init.debug("Qt arguments: {}, based on {}".format(argv, namespace)) + return argv + def _init_config(self): """Inizialize and read the config.""" if self._args.confdir is None: diff --git a/qutebrowser/qutebrowser.py b/qutebrowser/qutebrowser.py index 65338a40a..a2bc03624 100644 --- a/qutebrowser/qutebrowser.py +++ b/qutebrowser/qutebrowser.py @@ -49,6 +49,20 @@ def _parse_args(): debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'], default='auto', help="HarfBuzz engine version to use. " "Default: auto.") + 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 " + "stylesheet.", metavar='STYLESHEET') + 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') + debug.add_argument('--qt-reverse', help="Set the application's layout " + "direction to right-to-left.", action='store_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 " + "connects to it.", metavar='port:PORT[,block]') parser.add_argument('command', nargs='*', help="Commands to execute on " "startup.", metavar=':command') # URLs will actually be in command