|
24 | 24 | QT_API_PYQTv2 = "PyQt4v2"
|
25 | 25 | QT_API_PYSIDE = "PySide"
|
26 | 26 | 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} |
28 | 33 | # First, check if anything is already imported.
|
29 | 34 | if "PyQt5" in sys.modules:
|
30 | 35 | QT_API = QT_API_PYQT5
|
|
41 | 46 | # Otherwise, check the QT_API environment variable (from Enthought). This can
|
42 | 47 | # only override the binding, not the backend (in other words, we check that the
|
43 | 48 | # requested backend actually matches).
|
44 |
| -elif rcParams["backend"] == "Qt5Agg": |
| 49 | +elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]: |
45 | 50 | if QT_API_ENV == "pyqt5":
|
46 | 51 | dict.__setitem__(rcParams, "backend.qt5", QT_API_PYQT5)
|
47 | 52 | elif QT_API_ENV == "pyside2":
|
48 | 53 | dict.__setitem__(rcParams, "backend.qt5", QT_API_PYSIDE2)
|
49 | 54 | QT_API = dict.__getitem__(rcParams, "backend.qt5")
|
50 |
| -elif rcParams["backend"] == "Qt4Agg": |
| 55 | +elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]: |
51 | 56 | if QT_API_ENV == "pyqt4":
|
52 | 57 | dict.__setitem__(rcParams, "backend.qt4", QT_API_PYQTv2)
|
53 | 58 | elif QT_API_ENV == "pyside":
|
|
56 | 61 | # A non-Qt backend was selected but we still got there (possible, e.g., when
|
57 | 62 | # fully manually embedding Matplotlib in a Qt app without using pyplot).
|
58 | 63 | 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'") |
60 | 70 |
|
61 | 71 |
|
62 | 72 | def _setup_pyqt5():
|
|
0 commit comments