|
4 | 4 | The selection logic is as follows: |
5 | 5 | - if any of PyQt5, PySide2, PyQt4 or PySide have already been imported |
6 | 6 | (checked in that order), use it; |
7 | | -- otherwise, if the QT_API environment variable (used by Enthought) is |
8 | | - set, use it to determine which binding to use (but do not change the |
9 | | - backend based on it; i.e. if the Qt4Agg backend is requested but QT_API |
10 | | - is set to "pyqt5", then actually use Qt4 with the binding specified by |
11 | | - ``rcParams["backend.qt4"]``; |
| 7 | +- otherwise, if the QT_API environment variable (used by Enthought) is set, use |
| 8 | + it to determine which binding to use (but do not change the backend based on |
| 9 | + it; i.e. if the Qt5Agg backend is requested but QT_API is set to "pyqt4", |
| 10 | + then actually use Qt5 with PyQt5 or PySide2 (whichever can be imported); |
12 | 11 | - otherwise, use whatever the rcParams indicate. |
13 | 12 | """ |
14 | 13 |
|
|
33 | 32 | # First, check if anything is already imported. |
34 | 33 | if "PyQt5" in sys.modules: |
35 | 34 | QT_API = QT_API_PYQT5 |
36 | | - dict.__setitem__(rcParams, "backend.qt5", QT_API) |
37 | 35 | elif "PySide2" in sys.modules: |
38 | 36 | QT_API = QT_API_PYSIDE2 |
39 | | - dict.__setitem__(rcParams, "backend.qt5", QT_API) |
40 | 37 | elif "PyQt4" in sys.modules: |
41 | 38 | QT_API = QT_API_PYQTv2 |
42 | | - dict.__setitem__(rcParams, "backend.qt4", QT_API) |
43 | 39 | elif "PySide" in sys.modules: |
44 | 40 | QT_API = QT_API_PYSIDE |
45 | | - dict.__setitem__(rcParams, "backend.qt4", QT_API) |
46 | 41 | # Otherwise, check the QT_API environment variable (from Enthought). This can |
47 | 42 | # only override the binding, not the backend (in other words, we check that the |
48 | 43 | # requested backend actually matches). |
49 | 44 | elif rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]: |
50 | | - if QT_API_ENV == "pyqt5": |
51 | | - dict.__setitem__(rcParams, "backend.qt5", QT_API_PYQT5) |
52 | | - elif QT_API_ENV == "pyside2": |
53 | | - dict.__setitem__(rcParams, "backend.qt5", QT_API_PYSIDE2) |
54 | | - QT_API = dict.__getitem__(rcParams, "backend.qt5") |
| 45 | + if QT_API_ENV in ["pyqt5", "pyside2"]: |
| 46 | + QT_API = _ETS[QT_API_ENV] |
| 47 | + else: |
| 48 | + QT_API = None |
55 | 49 | elif rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]: |
56 | | - if QT_API_ENV == "pyqt4": |
57 | | - dict.__setitem__(rcParams, "backend.qt4", QT_API_PYQTv2) |
58 | | - elif QT_API_ENV == "pyside": |
59 | | - dict.__setitem__(rcParams, "backend.qt4", QT_API_PYSIDE) |
60 | | - QT_API = dict.__getitem__(rcParams, "backend.qt4") |
| 50 | + if QT_API_ENV in ["pyqt4", "pyside"]: |
| 51 | + QT_API = _ETS[QT_API_ENV] |
| 52 | + else: |
| 53 | + QT_API = None |
61 | 54 | # A non-Qt backend was selected but we still got there (possible, e.g., when |
62 | 55 | # fully manually embedding Matplotlib in a Qt app without using pyplot). |
63 | 56 | else: |
|
0 commit comments