8000 ENH: improve PySide2 loading · matplotlib/matplotlib@7f9c605 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f9c605

Browse files
committed
ENH: improve PySide2 loading
Don't require explicit QT_API setting for PySide2 in qt_compat.py
1 parent dc752b3 commit 7f9c605

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
# user has imported PySide before importing mpl
5050
QT_API = QT_API_PYSIDE
5151

52+
if 'PySide2' in sys.modules:
53+
# user has imported PySide before importing mpl
54+
QT_API = QT_API_PYSIDE2
55+
5256
if 'PyQt4' in sys.modules:
5357
# user has imported PyQt4 before importing mpl
5458
# this case also handles the PyQt4v2 case as once sip is imported
@@ -65,7 +69,7 @@
6569
except KeyError:
6670
raise RuntimeError(
6771
('Unrecognized environment variable %r, valid values are:'
68-
' %r, %r or %r' % (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5')))
72+
' %r, %r or %r' % (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5', 'pyside2')))
6973
if QT_ENV_MAJOR_VERSION == QT_RC_MAJOR_VERSION:
7074
# Only if backend and env qt major version are
7175
# compatible use the env variable.
@@ -99,7 +103,10 @@
99103
_sip_imported = True
100104
except ImportError:
101105
# Try using PySide
102-
QT_API = QT_API_PYSIDE
106+
if QT_RC_MAJOR_VERSION == 5:
107+
QT_API = QT_API_PYSIDE2
108+
else:
109+
QT_API = QT_API_PYSIDE
103110
cond = ("Could not import sip; falling back on PySide\n"
104111
"in place of PyQt4 or PyQt5.\n")
105112
verbose.report(cond, 'helpful')
@@ -166,7 +173,10 @@ def _getSaveFileName(*args, **kwargs):
166173
__version__ = QtCore.PYQT_VERSION_STR
167174
except NameError:
168175
# QtCore did not get imported, fall back to pyside
169-
QT_API = QT_API_PYSIDE
176+
if QT_RC_MAJOR_VERSION == 5:
177+
QT_API = QT_API_PYSIDE2
178+
else:
179+
QT_API = QT_API_PYSIDE
170180

171181

172182
if QT_API == QT_API_PYSIDE2:

0 commit comments

Comments
 (0)
0