Skip to content

Commit d281b94

Browse files
authored
Merge pull request #12091 from anntzer/qt_compat
FIX: Respect QT_API even when the backend is not Qt{4,5}{Agg,Cairo}.
2 parents 22906c2 + 418b9b5 commit d281b94

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
QT_API_PYQTv2 = "PyQt4v2"
2525
QT_API_PYSIDE = "PySide"
2626
QT_API_PYQT = "PyQt4" # Use the old sip v1 API (Py3 defaults to v2).
27-
QT_API_ENV = os.environ.get('QT_API')
27+
QT_API_ENV = os.environ.get("QT_API")
28+
# Mapping of QT_API_ENV to requested binding. ETS does not support PyQt4v1.
29+
# (https://github.com/enthought/pyface/blob/master/pyface/qt/__init__.py)
30+
_ETS = {"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
31+
"pyqt": QT_API_PYQTv2, "pyside": QT_API_PYSIDE,
32+
None: None}
2833
# First, check if anything is already imported.
2934
if "PyQt5" in sys.modules:
3035
QT_API = QT_API_PYQT5
@@ -41,13 +46,13 @@
4146
# Otherwise, check the QT_API environment variable (from Enthought). This can
4247
# only override the binding, not the backend (in other words, we check that the
4348
# requested backend actually matches).
44-
elif rcParams["backend"] == "Qt5Agg":
49+
elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
4550
if QT_API_ENV == "pyqt5":
4651
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYQT5)
4752
elif QT_API_ENV == "pyside2":
4853
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYSIDE2)
4954
QT_API = dict.__getitem__(rcParams, "backend.qt5")
50-
elif rcParams["backend"] == "Qt4Agg":
55+
elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
5156
if QT_API_ENV == "pyqt4":
5257
dict.__setitem__(rcParams, "backend.qt4", QT_API_PYQTv2)
5358
elif QT_API_ENV == "pyside":
@@ -56,7 +61,12 @@
5661
# A non-Qt backend was selected but we still got there (possible, e.g., when
5762
# fully manually embedding Matplotlib in a Qt app without using pyplot).
5863
else:
59-
QT_API = None
64+
try:
65+
QT_API = _ETS[QT_API_ENV]
66+
except KeyError:
67+
raise RuntimeError(
68+
"The environment variable QT_API has the unrecognized value {!r};"
69+
"valid values are 'pyqt5', 'pyside2', 'pyqt', and 'pyside'")
6070

6171

6272
def _setup_pyqt5():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy