Skip to content

Respect QT_API even when the backend is not Qt{4,5}{Agg,Cairo}. #12091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2018
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
18 changes: 14 additions & 4 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
QT_API_PYQTv2 = "PyQt4v2"
QT_API_PYSIDE = "PySide"
QT_API_PYQT = "PyQt4" # Use the old sip v1 API (Py3 defaults to v2).
QT_API_ENV = os.environ.get('QT_API')
QT_API_ENV = os.environ.get("QT_API")
# Mapping of QT_API_ENV to requested binding. ETS does not support PyQt4v1.
# (https://github.com/enthought/pyface/blob/master/pyface/qt/__init__.py)
_ETS = {"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
"pyqt": QT_API_PYQTv2, "pyside": QT_API_PYSIDE,
None: None}
# First, check if anything is already imported.
if "PyQt5" in sys.modules:
QT_API = QT_API_PYQT5
Expand All @@ -41,13 +46,13 @@
# Otherwise, check the QT_API environment variable (from Enthought). This can
# only override the binding, not the backend (in other words, we check that the
# requested backend actually matches).
elif rcParams["backend"] == "Qt5Agg":
elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
Copy link
Member

Choose a reason for hiding this comment

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

would .startswith("Qt5") be better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't really help with mplcairo... and I think we can revisit this if a third rendering backend ever show up :)
(In a sense the whole Qt4/5 setup is a bit weird, basically what we really have is just a Qt{Agg,Cair} backend and the 4/5 part just sets the default for QT_API.)
Anyways I don't feel strongly either way.

if QT_API_ENV == "pyqt5":
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYQT5)
elif QT_API_ENV == "pyside2":
dict.__setitem__(rcParams, "backend.qt5", QT_API_PYSIDE2)
QT_API = dict.__getitem__(rcParams, "backend.qt5")
elif rcParams["backend"] == "Qt4Agg":
elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
if QT_API_ENV == "pyqt4":
dict.__setitem__(rcParams, "backend.qt4", QT_API_PYQTv2)
elif QT_API_ENV == "pyside":
Expand All @@ -56,7 +61,12 @@
# A non-Qt backend was selected but we still got there (possible, e.g., when
# fully manually embedding Matplotlib in a Qt app without using pyplot).
else:
QT_API = None
try:
QT_API = _ETS[QT_API_ENV]
except KeyError:
raise RuntimeError(
"The environment variable QT_API has the unrecognized value {!r};"
"valid values are 'pyqt5', 'pyside2', 'pyqt', and 'pyside'")


def _setup_pyqt5():
Expand Down