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

Skip to content

MNT: more minor tweaks to qt_compat.py #5153

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 2 commits into from
Oct 2, 2015
Merged
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
18 changes: 14 additions & 4 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,18 @@
except:
res = 'QVariant API v2 specification failed. Defaulting to v1.'
verbose.report(cond + res, 'helpful')
if QT_API == QT_API_PYQT5:
try:
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
except ImportError:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = rcParams['backend.qt4']
Copy link
Member

Choose a reason for hiding this comment

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

I would raise a warning here

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, the logic has gotten crossed here. You can fall through this code path as the 'right' thing to do if we had to guess about qt4vqt5 above

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I misunderstand, but as far as I can see that will only happen if

  • You have specified rcParams['backend.qt4'] = PyQt5 which is clearly wrong.
  • Tried using the Qt5Agg backend without installing PyQt5
  • if if "PyQt4" in sys.modules or "PySide" in sys.modules: fails if which case this will fail any way.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can also get here if your rcparam is tkagg and you do not have qt5
installed (which is how I found this).

The (new) logic above says that if the rcparam is not set to a qt flavor,
it looks to see if qt4 or pyside is imported, then assumes it should be
using qt5.

On Mon, Sep 28, 2015, 04:30 Jens Hedegaard Nielsen [email protected]
wrote:

In lib/matplotlib/backends/qt_compat.py
#5153 (comment):

@@ -109,9 +109,18 @@
except:
res = 'QVariant API v2 specification failed. Defaulting to v1.'
verbose.report(cond + res, 'helpful')

  • if QT_API == QT_API_PYQT5:
  •    try:
    
  •        from PyQt5 import QtCore, QtGui, QtWidgets
    
  •        _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
    
  •    except ImportError:
    
  •        # fell through, tried PyQt5, failed fall back to PyQt4
    
  •        QT_API = rcParams['backend.qt4']
    

Perhaps I misunderstand, but as far as I can see that will only happen if

  • You have specified rcParams['backend.qt4'] = PyQt5 which is clearly
    wrong.
  • Tried using the Qt5Agg backend without installing PyQt5
  • if if "PyQt4" in sys.modules or "PySide" in sys.modules: fails if
    which case this will fail any way.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5153/files#r40527986.

Copy link
Member

Choose a reason for hiding this comment

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

Ok fair enough

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree this thing is a mess and needs a overhaul, but i want to get it
fixed enough for the next rc

On Mon, Sep 28, 2015, 06:59 Jens Hedegaard Nielsen [email protected]
wrote:

In lib/matplotlib/backends/qt_compat.py
#5153 (comment):

@@ -109,9 +109,18 @@
except:
res = 'QVariant API v2 specification failed. Defaulting to v1.'
verbose.report(cond + res, 'helpful')

  • if QT_API == QT_API_PYQT5:
  •    try:
    
  •        from PyQt5 import QtCore, QtGui, QtWidgets
    
  •        _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
    
  •    except ImportError:
    
  •        # fell through, tried PyQt5, failed fall back to PyQt4
    
  •        QT_API = rcParams['backend.qt4']
    

Ok fair enough


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5153/files#r40539934.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, part of the mess is my fault

QT_RC_MAJOR_VERSION = 4

# 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

from PyQt4 import QtCore, QtGui

try:
Expand All @@ -131,9 +140,10 @@ def _getSaveFileName(*args, **kwargs):
def _getSaveFileName(*args, **kwargs):
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None

else: # PyQt5 API
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
else:
raise RuntimeError("PyQt{4,5} bindings found despite sip importing\n"
"Please install PyQt4 or PyQt5, uninstall sip or "
"explicitly set the pyside backend.")

# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
Expand Down