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

Skip to content

qt imports do not pick defaults properly #4912

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

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 24 additions & 2 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@

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.
try:
# if the newest API is available, lets assume that is being used.
import PyQt5
QT_RC_MAJOR_VERSION = 5
except ImportError:
# This is a fallback
QT_RC_MAJOR_VERSION = 4

QT_API = None

Expand All @@ -47,8 +58,19 @@
# No ETS environment or incompatible so use rcParams.
if rcParams['backend'] == 'Qt5Agg':
Copy link
Member

Choose a reason for hiding this comment

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

By this point I think we are gaurenteed that QT_RC_MAJOR_VERSION is defined, we should switch on that instead of having the conditional import logic again.

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.
try:
# if the newest API is available, lets assume that is being used.
import PyQt5
QT_API = rcParams['backend.qt5']
except ImportError:
# This is a fallback
QT_API = rcParams['backend.qt4']

# We will define an appropriate wrapper for the differing versions
# of file dialog.
Expand Down