Allow --qt-arg and --qt-flag to be given multiple times

Fixes #2151
This commit is contained in:
Florian Bruhin 2016-12-06 06:47:42 +01:00
parent 7b8af9ebbf
commit 0ab23a74fb
3 changed files with 15 additions and 5 deletions

View File

@ -114,9 +114,10 @@ def get_argparser():
debug.add_argument('--qt-arg', help="Pass an argument with a value to Qt. "
"For example, you can do "
"`--qt-arg geometry 650x555+200+300` to set the window "
"geometry.", nargs=2, metavar=('NAME', 'VALUE'))
"geometry.", nargs=2, metavar=('NAME', 'VALUE'),
action='append')
debug.add_argument('--qt-flag', help="Pass an argument to Qt as flag.",
nargs=1)
nargs=1, action='append')
parser.add_argument('command', nargs='*', help="Commands to execute on "
"startup.", metavar=':command')
# URLs will actually be in command

View File

@ -129,11 +129,14 @@ def get_args(namespace):
The argv list to be passed to Qt.
"""
argv = [sys.argv[0]]
if namespace.qt_flag is not None:
argv.append('-' + namespace.qt_flag[0])
argv += ['-' + flag[0] for flag in namespace.qt_flag]
if namespace.qt_arg is not None:
argv.append('-' + namespace.qt_arg[0])
argv.append(namespace.qt_arg[1])
for name, value in namespace.qt_arg:
argv += ['-' + name, value]
return argv

View File

@ -112,6 +112,12 @@ class TestGetQtArgs:
# Qt argument with value
(['--qt-arg', 'stylesheet', 'foo'],
[sys.argv[0], '-stylesheet', 'foo']),
# --qt-arg given twice
(['--qt-arg', 'stylesheet', 'foo', '--qt-arg', 'geometry', 'bar'],
[sys.argv[0], '-stylesheet', 'foo', '-geometry', 'bar']),
# --qt-flag given twice
(['--qt-flag', 'foo', '--qt-flag', 'bar'],
[sys.argv[0], '-foo', '-bar']),
])
def test_qt_args(self, args, expected, parser):
"""Test commandline with no Qt arguments given."""