Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cdc52bf

Browse files
committed
FIX: be more careful about pyside
If: 1. backend is not Qt{4,5}Agg 2. PyQt4 and PySide are installed, PyQt5 is not 3. backend.qt4 == 'PySide' The fall through will start trying to import PyQt5 (so sip will be imported as it is installed for PyQt4). It will then fall back to Qt4 using the binding specified in the rcparam ('PySide') which will then miss the qt4 import conditionals which means QtCore is never imported which means we get name errors from the pyqt / pyside patch up code. This catches those exceptions and gives pyside a chance to be imported.
1 parent f67ea3c commit cdc52bf

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/matplotlib/backends/qt_compat.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,22 @@ def _getSaveFileName(*args, **kwargs):
139139
# call to getapi() can fail in older versions of sip
140140
def _getSaveFileName(*args, **kwargs):
141141
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None
142-
143-
# Alias PyQt-specific functions for PySide compatibility.
144-
QtCore.Signal = QtCore.pyqtSignal
145142
try:
146-
QtCore.Slot = QtCore.pyqtSlot
147-
except AttributeError:
148-
# Not a perfect match but works in simple cases
149-
QtCore.Slot = QtCore.pyqtSignature
150-
151-
QtCore.Property = QtCore.pyqtProperty
152-
__version__ = QtCore.PYQT_VERSION_STR
143+
# Alias PyQt-specific functions for PySide compatibility.
144+
QtCore.Signal = QtCore.pyqtSignal
145+
try:
146+
QtCore.Slot = QtCore.pyqtSlot
147+
except AttributeError:
148+
# Not a perfect match but works in simple cases
149+
QtCore.Slot = QtCore.pyqtSignature
150+
151+
QtCore.Property = QtCore.pyqtProperty
152+
__version__ = QtCore.PYQT_VERSION_STR
153+
except NameError:
154+
# QtCore did not get imported, fall back to pyside
155+
QT_API = QT_API_PYSIDE
153156

154-
else: # try importing pyside
157+
if QT_API == QT_API_PYSIDE: # try importing pyside
155158
try:
156159
from PySide import QtCore, QtGui, __version__, __version_info__
157160
except ImportError:

0 commit comments

Comments
 (0)