|
42 | 42 |
|
43 | 43 | QT_API = None
|
44 | 44 |
|
45 |
| -if (QT_API_ENV is not None): |
| 45 | +# check if any binding is already imported, if so silently ignore the |
| 46 | +# rcparams/ENV settings and use what ever is already imported. |
| 47 | +if 'PySide' in sys.modules: |
| 48 | + # user has imported PySide before importing mpl |
| 49 | + QT_API = QT_API_PYSIDE |
| 50 | + |
| 51 | +if 'PyQt4' in sys.modules: |
| 52 | + # user has imported PyQt4 before importing mpl |
| 53 | + # this case also handles the PyQt4v2 case as once sip is imported |
| 54 | + # the API versions can not be changed so do not try |
| 55 | + QT_API = QT_API_PYQT |
| 56 | + |
| 57 | +if 'PyQt5' in sys.modules: |
| 58 | + # the user has imported PyQt5 before importing mpl |
| 59 | + QT_API = QT_API_PYQT5 |
| 60 | + |
| 61 | +if (QT_API_ENV is not None) and QT_API is None: |
46 | 62 | try:
|
47 | 63 | QT_ENV_MAJOR_VERSION = ETS[QT_API_ENV][1]
|
48 | 64 | except KeyError:
|
|
61 | 77 | elif rcParams['backend'] == 'Qt4Agg':
|
62 | 78 | QT_API = rcParams['backend.qt4']
|
63 | 79 | else:
|
64 |
| - # A different backend was specified, but we still got here because a Qt |
65 |
| - # related file was imported. This is allowed, so lets try and guess |
66 |
| - # what we should be using. |
67 |
| - if "PyQt4" in sys.modules or "PySide" in sys.modules: |
68 |
| - # PyQt4 or PySide is actually used. |
69 |
| - QT_API = rcParams['backend.qt4'] |
70 |
| - else: |
71 |
| - # This is a fallback: PyQt5 |
72 |
| - QT_API = rcParams['backend.qt5'] |
| 80 | + # A non-Qt backend was specified, no version of the Qt |
| 81 | + # bindings is imported, but we still got here because a Qt |
| 82 | + # related file was imported. This is allowed, fall back to Qt5 |
| 83 | + # using which ever binding the rparams ask for. |
| 84 | + |
| 85 | + QT_API = rcParams['backend.qt5'] |
73 | 86 |
|
74 | 87 | # We will define an appropriate wrapper for the differing versions
|
75 | 88 | # of file dialog.
|
|
0 commit comments