Skip to content

Backport PR #11500 on branch v2.2.x #11567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ def destroy(self, *args):
if self.window._destroying:
return
self.window._destroying = True
self.window.destroyed.connect(self._widgetclosed)
if self.toolbar:
self.toolbar.destroy()
self.window.close()
Expand Down
55 changes: 26 additions & 29 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
_sip_imported = False

# Now perform the imports.
if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYQT5):
if QT_API in (QT_API_PYQT, QT_API_PYQTv2):
try:
import sip
_sip_imported = True
Expand Down Expand Up @@ -135,18 +135,20 @@
except:
res = 'QVariant API v2 specification failed. Defaulting to v1.'
_log.info(cond + res)
if QT_API == QT_API_PYQT5:
try:
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
except ImportError:
if _fallback_to_qt4:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = QT_API_PYQT
QT_RC_MAJOR_VERSION = 4
else:
raise

if QT_API == QT_API_PYQT5:
try:
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
except ImportError:
if _fallback_to_qt4:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = QT_API_PYQT
QT_RC_MAJOR_VERSION = 4
else:
raise

if _sip_imported:
# needs to be if so we can re-test the value of QT_API which may
# have been changed in the above if block
if QT_API in [QT_API_PYQT, QT_API_PYQTv2]: # PyQt4 API
Expand All @@ -168,23 +170,6 @@ def _getSaveFileName(*args, **kwargs):
# call to getapi() can fail in older versions of sip
def _getSaveFileName(*args, **kwargs):
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None
try:
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
try:
QtCore.Slot = QtCore.pyqtSlot
except AttributeError:
# Not a perfect match but works in simple cases
QtCore.Slot = QtCore.pyqtSignature

QtCore.Property = QtCore.pyqtProperty
__version__ = QtCore.PYQT_VERSION_STR
except NameError:
# QtCore did not get imported, fall back to pyside
if QT_RC_MAJOR_VERSION == 5:
QT_API = QT_API_PYSIDE2
else:
QT_API = QT_API_PYSIDE


if QT_API == QT_API_PYSIDE2:
Expand All @@ -211,6 +196,18 @@ def _getSaveFileName(*args, **kwargs):
_getSaveFileName = QtGui.QFileDialog.getSaveFileName


if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYQT5):
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
try:
QtCore.Slot = QtCore.pyqtSlot
except AttributeError:
# Not a perfect match but works in simple cases
QtCore.Slot = QtCore.pyqtSignature

QtCore.Property = QtCore.pyqtProperty
__version__ = QtCore.PYQT_VERSION_STR

# Apply shim to Qt4 APIs to make them look like Qt5
if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYSIDE):
'''Import all used QtGui objects into QtWidgets
Expand Down