Skip to content
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

Fix for #3623 #3632

Merged
merged 1 commit into from Oct 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions lib/matplotlib/backends/qt_compat.py
Expand Up @@ -14,21 +14,37 @@
QT_API_PYSIDE = 'PySide' # only supports Version 2 API
QT_API_PYQT5 = 'PyQt5' # use PyQt5 API; Version 2 with module shim

ETS = dict(pyqt=QT_API_PYQTv2, pyside=QT_API_PYSIDE, pyqt5=QT_API_PYQT5)
# If the ETS QT_API environment variable is set, use it. Note that
ETS = dict(pyqt=(QT_API_PYQTv2, 4), pyside=(QT_API_PYSIDE, 4),
pyqt5=(QT_API_PYQT5, 5))
# ETS is a dict of env variable to (QT_API, QT_MAJOR_VERSION)
# If the ETS QT_API environment variable is set, use it, but only
# if the varible if of the same major QT version. Note that
# ETS requires the version 2 of PyQt4, which is not the platform
# default for Python 2.x.

QT_API_ENV = os.environ.get('QT_API')
if QT_API_ENV is not None:

if rcParams['backend'] == 'Qt5Agg':
QT_RC_MAJOR_VERSION = 5
else:
QT_RC_MAJOR_VERSION = 4

QT_API = None

if (QT_API_ENV is not None):
try:
QT_API = ETS[QT_API_ENV]
QT_ENV_MAJOR_VERSION = ETS[QT_API_ENV][1]
except KeyError:
raise RuntimeError(
'Unrecognized environment variable %r, valid values are: %r or %r' %
(QT_API_ENV, 'pyqt', 'pyside', 'pyqt5'))
else:
# No ETS environment, so use rcParams.
('Unrecognized environment variable %r, valid values are:'
' %r, %r or %r' % (QT_API_ENV, 'pyqt', 'pyside', 'pyqt5')))
if QT_ENV_MAJOR_VERSION == QT_RC_MAJOR_VERSION:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the rcparam take precedence over the ENV (if I am reading this correctly). My understanding of the convention is that the ENV should take precedence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if the env param tries to use a different backend from the one the user has selected.

Currently if the ENV is 'pyqt' (i.e. a qt4 backend) but the user has done ```matplotlib.use('Qt5Agg') then you get PyQT4 imported into the matplotlib qt5 backend which makes no sense and is just wrong. This means that if you have that variable defined (as I have to control what backend mayavi uses pyside or pyqt4 ) I can't run the qt5 backend but get a broken mixture of the matplotlib qt5 code and the pyqt4.

It makes no sense to use the env variable to determine what major Qt version should be imported since that is selected by the choice of backend.

# Only if backend and env qt major version are
# compatible use the env variable.
QT_API = ETS[QT_API_ENV][0]

if QT_API is None:
# No ETS environment or incompatible so use rcParams.
if rcParams['backend'] == 'Qt5Agg':
QT_API = rcParams['backend.qt5']
else:
Expand Down