Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0853446

Browse filesBrowse files
committed
Merge pull request #6174 from tacaswell/mnt_qt_imports
Mnt qt imports
2 parents 41007a5 + f43a30d commit 0853446
Copy full SHA for 0853446

File tree

Expand file treeCollapse file tree

1 file changed

+23
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-10
lines changed

‎lib/matplotlib/backends/qt_compat.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_compat.py
+23-10Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,23 @@
4242

4343
QT_API = None
4444

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:
4662
try:
4763
QT_ENV_MAJOR_VERSION = ETS[QT_API_ENV][1]
4864
except KeyError:
@@ -61,15 +77,12 @@
6177
elif rcParams['backend'] == 'Qt4Agg':
6278
QT_API = rcParams['backend.qt4']
6379
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']
7386

7487
# We will define an appropriate wrapper for the differing versions
7588
# of file dialog.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.