From 9a9be68d9092ab08d6a6cf85d76ba69b7da09288 Mon Sep 17 00:00:00 2001 From: Chris Billington Date: Fri, 15 May 2020 14:31:42 -0400 Subject: [PATCH] mkQApp: Use sys.argv if non-empty and always set given name (#1199) Always pass `sys.argv`, if non-empty, to `QApplication` constructor. This allows code to continue to rely on the fact that the application name is by default set from `sys.argv[0]`, which is important for example on Linux where this determines the WM_CLASS X attribute used by desktop environments to match applications to their launchers. If `sys.argv` is empty, as it is in an interactive Python session, pass `["pyqtgraph"]` in its place as a sensible default for the application name, which causes issues if not set (issue #1165). If a `name` is given, set it using `setApplicationName()` instead of via the argument list. This ensures it will be set even if the singleton `QApplication` already existed prior to calling `mkQApp()`. --- pyqtgraph/Qt.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index cc8b3d0a..702bc2bd 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -330,21 +330,19 @@ if m is not None and list(map(int, m.groups())) < versionReq: QAPP = None -def mkQApp(name="pyqtgraph", qt_args=None): +def mkQApp(name=None): """ Creates new QApplication or returns current instance if existing. - ============== ================================================================================= + ============== ======================================================== **Arguments:** - name Application name, passed to Qt - qt_args Array of command line arguments passed to Qt - ============== ================================================================================= + name (str) Application name, passed to Qt + ============== ======================================================== """ global QAPP QAPP = QtGui.QApplication.instance() if QAPP is None: - args = [name] - if qt_args is not None: - args.extend(qt_args) - QAPP = QtGui.QApplication(args) + QAPP = QtGui.QApplication(sys.argv or ["pyqtgraph"]) + if name is not None: + QAPP.setApplicationName(name) return QAPP