X Tutup
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
# user has imported PySide before importing mpl
QT_API = QT_API_PYSIDE

if 'PySide2' in sys.modules:
# user has imported PySide before importing mpl
QT_API = QT_API_PYSIDE2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use if elif checks instead of consecutive if statements?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things are going to be mutually exclusive due to restrictions from the libraries.

This could be cleaned up, but I think is out of scope of this PR.

if 'PyQt4' in sys.modules:
# user has imported PyQt4 before importing mpl
# this case also handles the PyQt4v2 case as once sip is imported
Expand All @@ -65,7 +69,8 @@
except KeyError:
raise RuntimeError(
('Unrecognized environment variable %r, valid values are:'
' %r, %r or %r' % (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5')))
' %r, %r, %r or %r'
% (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5', 'pyside2')))
if QT_ENV_MAJOR_VERSION == QT_RC_MAJOR_VERSION:
# Only if backend and env qt major version are
# compatible use the env variable.
Expand Down Expand Up @@ -99,7 +104,10 @@
_sip_imported = True
except ImportError:
# Try using PySide
QT_API = QT_API_PYSIDE
if QT_RC_MAJOR_VERSION == 5:
QT_API = QT_API_PYSIDE2
else:
QT_API = QT_API_PYSIDE
cond = ("Could not import sip; falling back on PySide\n"
"in place of PyQt4 or PyQt5.\n")
verbose.report(cond, 'helpful')
Expand Down Expand Up @@ -166,7 +174,10 @@ def _getSaveFileName(*args, **kwargs):
__version__ = QtCore.PYQT_VERSION_STR
except NameError:
# QtCore did not get imported, fall back to pyside
QT_API = QT_API_PYSIDE
if QT_RC_MAJOR_VERSION == 5:
QT_API = QT_API_PYSIDE2
else:
QT_API = QT_API_PYSIDE


if QT_API == QT_API_PYSIDE2:
Expand Down
X Tutup