Process Qt args via argparse
This commit is contained in:
parent
63d17d4675
commit
1179d84ee8
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user