Skip to content

Commit 4cf0eef

Browse files
authored
Merge pull request #12101 from meeseeksmachine/auto-backport-of-pr-12091-on-v2.2.x
Backport PR #12091 on branch v2.2.x (Respect QT_API even when the backend is not Qt{4,5}{Agg,Cairo}.)
2 parents bec8457 + da2b5d0 commit 4cf0eef

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/matplotlib/backends/qt_compat.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
QT_API_PYQTv2 = "PyQt4v2"
2828
QT_API_PYSIDE = "PySide"
2929
QT_API_PYQT = "PyQt4" # Use the old sip v1 API (Py3 defaults to v2).
30-
QT_API_ENV = os.environ.get('QT_API')
30+
QT_API_ENV = os.environ.get("QT_API")
31+
# Mapping of QT_API_ENV to requested binding. ETS does not support PyQt4v1.
32+
# (https://github.com/enthought/pyface/blob/master/pyface/qt/__init__.py)
33+
_ETS = {"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
34+
"pyqt": QT_API_PYQTv2, "pyside": QT_API_PYSIDE,
35+
None: None}
3136
# First, check if anything is already imported.
3237
if "PyQt5" in sys.modules:
3338
QT_API = QT_API_PYQT5
@@ -44,13 +49,13 @@
4449
# Otherwise, check the QT_API environment variable (from Enthought). This can
4550
# only override the binding, not the backend (in other words, we check that the
4651
# requested backend actually matches).
47-
elif rcParams["backend"] == "Qt5Agg":
52+
elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
4853
if QT_API_ENV == "pyqt5":
4954
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYQT5)
5055
elif QT_API_ENV == "pyside2":
5156
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYSIDE2)
5257
QT_API = dict.__getitem__(rcParams, "backend.qt5")
53-
elif rcParams["backend"] == "Qt4Agg":
58+
elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
5459
if QT_API_ENV == "pyqt4":
5560
dict.__setitem__(rcParams, "backend.qt4", QT_API_PYQTv2)
5661
elif QT_API_ENV == "pyside":
@@ -59,7 +64,12 @@
5964
# A non-Qt backend was selected but we still got there (possible, e.g., when
6065
# fully manually embedding Matplotlib in a Qt app without using pyplot).
6166
else:
62-
QT_API = None
67+
try:
68+
QT_API = _ETS[QT_API_ENV]
69+
except KeyError:
70+
raise RuntimeError(
71+
"The environment variable QT_API has the unrecognized value {!r};"
72+
"valid values are 'pyqt5', 'pyside2', 'pyqt', and 'pyside'")
6373

6474

6575
def _setup_pyqt5():

0 commit comments

Comments
 (0)