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()`.
This commit is contained in:
Chris Billington 2020-05-15 14:31:42 -04:00 committed by GitHub
parent fb56d3eaa9
commit 9a9be68d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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