Skip to content

Fix handling of getSaveFileName to be consistent [backport to 1.4.x] #3469

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
Sep 6, 2014
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
17 changes: 8 additions & 9 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from matplotlib._pylab_helpers import Gcf
from matplotlib.figure import Figure


from matplotlib.widgets import SubplotTool
try:
import matplotlib.backends.qt_editor.figureoptions as figureoptions
Expand Down Expand Up @@ -184,6 +183,7 @@ class TimerQT(TimerBase):
upon timer events. This list can be manipulated directly, or the
functions add_callback and remove_callback can be used.
'''

def __init__(self, *args, **kwargs):
TimerBase.__init__(self, *args, **kwargs)

Expand Down Expand Up @@ -331,8 +331,8 @@ def resizeEvent(self, event):
print('resize (%d x %d)' % (w, h))
print("FigureCanvasQt.resizeEvent(%d, %d)" % (w, h))
dpival = self.figure.dpi
winch = w/dpival
hinch = h/dpival
winch = w / dpival
hinch = h / dpival
self.figure.set_size_inches(winch, hinch)
FigureCanvasBase.resize_event(self)
self.draw()
Expand Down Expand Up @@ -551,9 +551,9 @@ def destroy(self, *args):
self.window.destroyed.connect(self._widgetclosed)

if self.toolbar:
self.toolbar.destroy()
self.toolbar.destroy()
if DEBUG:
print("destroy figure manager")
print("destroy figure manager")
self.window.close()

def get_window_title(self):
Expand Down Expand Up @@ -715,7 +715,7 @@ def save_figure(self, *args):
filters.append(filter)
filters = ';;'.join(filters)

fname = _getSaveFileName(self.parent, "Choose a filename to save to",
fname, filter = _getSaveFileName(self.parent, "Choose a filename to save to",
start, filters, selectedFilter)
if fname:
if startpath == '':
Expand Down Expand Up @@ -750,7 +750,7 @@ def __init__(self, targetfig, parent):
self.slidertop.valueChanged.connect(self.sliderbottom.setMaximum)

self.defaults = {}
for attr in ('left', 'bottom', 'right', 'top', 'wspace', 'hspace',):
for attr in ('left', 'bottom', 'right', 'top', 'wspace', 'hspace', ):
self.defaults[attr] = getattr(self.targetfig.subplotpars, attr)
slider = getattr(self, 'slider' + attr)
slider.setMinimum(0)
Expand All @@ -761,7 +761,7 @@ def __init__(self, targetfig, parent):
self._setSliderPositions()

def _setSliderPositions(self):
for attr in ('left', 'bottom', 'right', 'top', 'wspace', 'hspace',):
for attr in ('left', 'bottom', 'right', 'top', 'wspace', 'hspace', ):
slider = getattr(self, 'slider' + attr)
slider.setSliderPosition(int(self.defaults[attr] * 1000))

Expand Down Expand Up @@ -850,6 +850,5 @@ def exception_handler(type, value, tb):
if len(msg):
error_msg_qt(msg)


FigureCanvas = FigureCanvasQT
FigureManager = FigureManagerQT
28 changes: 13 additions & 15 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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 requires the version 2 of PyQt4, which is not the platform
# default for Python 2.x.
Expand Down Expand Up @@ -62,14 +61,14 @@
sip.setapi('QString', 2)
except:
res = 'QString API v2 specification failed. Defaulting to v1.'
verbose.report(cond+res, 'helpful')
verbose.report(cond + res, 'helpful')
# condition has now been reported, no need to repeat it:
cond = ""
try:
sip.setapi('QVariant', 2)
except:
res = 'QVariant API v2 specification failed. Defaulting to v1.'
verbose.report(cond+res, 'helpful')
verbose.report(cond + res, 'helpful')

if QT_API in [QT_API_PYQT, QT_API_PYQTv2]: # PyQt4 API

Expand All @@ -78,21 +77,23 @@
try:
if sip.getapi("QString") > 1:
# Use new getSaveFileNameAndFilter()
_get_save = QtGui.QFileDialog.getSaveFileNameAndFilter
_getSaveFileName = QtGui.QFileDialog.getSaveFileNameAndFilter
else:


# Use old getSaveFileName()
_getSaveFileName = QtGui.QFileDialog.getSaveFileName
def _getSaveFileName(*args, **kwargs):
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None

except (AttributeError, KeyError):


# call to getapi() can fail in older versions of sip
_getSaveFileName = QtGui.QFileDialog.getSaveFileName
def _getSaveFileName(*args, **kwargs):
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None

else: # PyQt5 API

from PyQt5 import QtCore, QtGui, QtWidgets

# Additional PyQt5 shimming to make it appear as for PyQt4

_get_save = QtWidgets.QFileDialog.getSaveFileName
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName

# Alias PyQt-specific functions for PySide compatibility.
Expand All @@ -112,11 +113,8 @@
raise ImportError(
"Matplotlib backend_qt4 and backend_qt4agg require PySide >=1.0.3")

_get_save = QtGui.QFileDialog.getSaveFileName
_getSaveFileName = QtGui.QFileDialog.getSaveFileName

if _getSaveFileName is None:
def _getSaveFileName(self, msg, start, filters, selectedFilter):
return _get_save(self, msg, start, filters, selectedFilter)[0]

# Apply shim to Qt4 APIs to make them look like Qt5
if QT_API in (QT_API_PYQT, QT_API_PYQTv2, QT_API_PYSIDE):
Expand Down