From 2a23a6344a02768bca46e968534098e09a3b4cb7 Mon Sep 17 00:00:00 2001 From: JGoutin Date: Thu, 17 Sep 2015 15:50:23 +0200 Subject: [PATCH 1/4] Fix PyQt4/PyQt5 backend autodetection This fixes an error where PyQt4 would always be selected in the case where a Qt related file was imported, but not set as the current backend Change from jrevans commit : Check what PyQt version is actually used rather than try to force the use of PyQt5. --- lib/matplotlib/backends/qt_compat.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index f237d449eb20..71adbc76f15a 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -6,6 +6,7 @@ from matplotlib.externals import six import os +import sys from matplotlib import rcParams, verbose # Available APIs. @@ -26,8 +27,18 @@ if rcParams['backend'] == 'Qt5Agg': QT_RC_MAJOR_VERSION = 5 -else: +elif rcParams['backend'] == 'Qt4Agg': QT_RC_MAJOR_VERSION = 4 +else: + # A different backend was specified, but we still got here because a Qt + # related file was imported. This is allowed, so lets try and guess + # what we should be using. + if "PyQt5" in sys.modules: + # PyQt5 is actually used. + QT_RC_MAJOR_VERSION = 5 + else: + # This is a fallback + QT_RC_MAJOR_VERSION = 4 QT_API = None @@ -47,8 +58,18 @@ # No ETS environment or incompatible so use rcParams. if rcParams['backend'] == 'Qt5Agg': QT_API = rcParams['backend.qt5'] - else: + elif rcParams['backend'] == 'Qt4Agg': QT_API = rcParams['backend.qt4'] + else: + # A different backend was specified, but we still got here because a Qt + # related file was imported. This is allowed, so lets try and guess + # what we should be using. + if "PyQt5" in sys.modules: + # PyQt5 is actually used. + QT_API = rcParams['backend.qt5'] + else: + # This is a fallback + QT_API = rcParams['backend.qt4'] # We will define an appropriate wrapper for the differing versions # of file dialog. From f482f37df0f87608c2ea616bc8e8fb2480f4fbb9 Mon Sep 17 00:00:00 2001 From: JGoutin Date: Sat, 26 Sep 2015 21:04:29 +0200 Subject: [PATCH 2/4] Update qt_compat.py Pyqt5 by default. --- lib/matplotlib/backends/qt_compat.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index 71adbc76f15a..9e0b0519538e 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -31,14 +31,14 @@ QT_RC_MAJOR_VERSION = 4 else: # A different backend was specified, but we still got here because a Qt - # related file was imported. This is allowed, so lets try and guess + # related file was imported. This is allowed, so lets try and guess # what we should be using. - if "PyQt5" in sys.modules: + if "PyQt4" in sys.modules: # PyQt5 is actually used. - QT_RC_MAJOR_VERSION = 5 + QT_RC_MAJOR_VERSION = 4 else: # This is a fallback - QT_RC_MAJOR_VERSION = 4 + QT_RC_MAJOR_VERSION = 5 QT_API = None @@ -62,14 +62,14 @@ QT_API = rcParams['backend.qt4'] else: # A different backend was specified, but we still got here because a Qt - # related file was imported. This is allowed, so lets try and guess + # related file was imported. This is allowed, so lets try and guess # what we should be using. - if "PyQt5" in sys.modules: - # PyQt5 is actually used. - QT_API = rcParams['backend.qt5'] + if "PyQt4" in sys.modules: + # PyQt4 is actually used. + QT_API = rcParams['backend.qt4'] else: # This is a fallback - QT_API = rcParams['backend.qt4'] + QT_API = rcParams['backend.qt5'] # We will define an appropriate wrapper for the differing versions # of file dialog. From 9d5d8847616f32faa099b04c0b259851135a2396 Mon Sep 17 00:00:00 2001 From: JGoutin Date: Sat, 26 Sep 2015 21:08:30 +0200 Subject: [PATCH 3/4] Update qt_compat.py Fix comment --- lib/matplotlib/backends/qt_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index 9e0b0519538e..ca9493d0ae48 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -34,7 +34,7 @@ # related file was imported. This is allowed, so lets try and guess # what we should be using. if "PyQt4" in sys.modules: - # PyQt5 is actually used. + # PyQt4 is actually used. QT_RC_MAJOR_VERSION = 4 else: # This is a fallback From 4daacddbe6cb47790c3feaf62491e9387ff809e0 Mon Sep 17 00:00:00 2001 From: JGoutin Date: Sat, 26 Sep 2015 22:11:10 +0200 Subject: [PATCH 4/4] Update qt_compat.py Add PySide --- lib/matplotlib/backends/qt_compat.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index ca9493d0ae48..c564fd0c6c02 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -33,11 +33,11 @@ # A different backend was specified, but we still got here because a Qt # related file was imported. This is allowed, so lets try and guess # what we should be using. - if "PyQt4" in sys.modules: - # PyQt4 is actually used. + if "PyQt4" in sys.modules or "PySide" in sys.modules: + # PyQt4 or PySide is actually used. QT_RC_MAJOR_VERSION = 4 else: - # This is a fallback + # This is a fallback: PyQt5 QT_RC_MAJOR_VERSION = 5 QT_API = None @@ -64,11 +64,11 @@ # A different backend was specified, but we still got here because a Qt # related file was imported. This is allowed, so lets try and guess # what we should be using. - if "PyQt4" in sys.modules: - # PyQt4 is actually used. + if "PyQt4" in sys.modules or "PySide" in sys.modules: + # PyQt4 or PySide is actually used. QT_API = rcParams['backend.qt4'] else: - # This is a fallback + # This is a fallback: PyQt5 QT_API = rcParams['backend.qt5'] # We will define an appropriate wrapper for the differing versions