8000 Merge pull request #7252 from jrversteegh/master · matplotlib/matplotlib@de376dd · GitHub
[go: up one dir, main page]

Skip to content

Commit de376dd

Browse files
authored
Merge pull request #7252 from jrversteegh/master
MNT: improve PySide2 loading Select pyside2 backend if pyside2 is already imported
2 parents d308471 + c4a0873 commit de376dd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 14 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,8 @@
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, %r or %r'
73+
% (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5', 'pyside2')))
6974
if QT_ENV_MAJOR_VERSION == QT_RC_MAJOR_VERSION:
7075
# Only if backend and env qt major version are
7176
# compatible use the env variable.
@@ -99,7 +104,10 @@
99104
_sip_imported = True
100105
except ImportError:
101106
# Try using PySide
102-
QT_API = QT_API_PYSIDE
107+
if QT_RC_MAJOR_VERSION == 5:
108+
QT_API = QT_API_PYSIDE2
109+
else:
110+
QT_API = QT_API_PYSIDE
103111
cond = ("Could not import sip; falling back on PySide\n"
104112
"in place of PyQt4 or PyQt5.\n")
105113
verbose.report(cond, 'helpful')
@@ -166,7 +174,10 @@ def _getSaveFileName(*args, **kwargs):
166174
__version__ = QtCore.PYQT_VERSION_STR
167175
except NameError:
168176
# QtCore did not get imported, fall back to pyside
169-
QT_API = QT_API_PYSIDE
177+
if QT_RC_MAJOR_VERSION == 5:
178+
QT_API = QT_API_PYSIDE2
179+
else:
180+
QT_API = QT_API_PYSIDE
170181

171182

172183
if QT_API == QT_API_PYSIDE2:

0 commit comments

Comments
 (0)
0