|
6 | 6 | from matplotlib.externals import six |
7 | 7 |
|
8 | 8 | import os |
| 9 | +import sys |
9 | 10 | from matplotlib import rcParams, verbose |
10 | 11 |
|
11 | 12 | # Available APIs. |
|
26 | 27 |
|
27 | 28 | if rcParams['backend'] == 'Qt5Agg': |
28 | 29 | QT_RC_MAJOR_VERSION = 5 |
29 | | -else: |
| 30 | +elif rcParams['backend'] == 'Qt4Agg': |
30 | 31 | QT_RC_MAJOR_VERSION = 4 |
| 32 | +else: |
| 33 | + # A different backend was specified, but we still got here because a Qt |
| 34 | + # related file was imported. This is allowed, so lets try and guess |
| 35 | + # what we should be using. |
| 36 | + if "PyQt4" in sys.modules or "PySide" in sys.modules: |
| 37 | + # PyQt4 or PySide is actually used. |
| 38 | + QT_RC_MAJOR_VERSION = 4 |
| 39 | + else: |
| 40 | + # This is a fallback: PyQt5 |
| 41 | + QT_RC_MAJOR_VERSION = 5 |
31 | 42 |
|
32 | 43 | QT_API = None |
33 | 44 |
|
|
47 | 58 | # No ETS environment or incompatible so use rcParams. |
48 | 59 | if rcParams['backend'] == 'Qt5Agg': |
49 | 60 | QT_API = rcParams['backend.qt5'] |
50 | | - else: |
| 61 | + elif rcParams['backend'] == 'Qt4Agg': |
51 | 62 | QT_API = rcParams['backend.qt4'] |
| 63 | + 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'] |
52 | 73 |
|
53 | 74 | # We will define an appropriate wrapper for the differing versions |
54 | 75 | # of file dialog. |
|
0 commit comments