diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 823a50ddad6a..ca6c5ac64287 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -605,6 +605,7 @@ def __init__(self, canvas, parent, coordinates=True): self.coordinates = coordinates self._actions = {} # mapping of toolitem method names to QActions. + self._subplot_dialog = None for text, tooltip_text, image_file, callback in self.toolitems: if text is None: @@ -714,9 +715,10 @@ def remove_rubberband(self): def configure_subplots(self): image = str(cbook._get_data_path('images/matplotlib.png')) - dia = SubplotToolQt(self.canvas.figure, self.canvas.parent()) - dia.setWindowIcon(QtGui.QIcon(image)) - dia.exec_() + self._subplot_dialog = SubplotToolQt( + self.canvas.figure, self.canvas.parent()) + self._subplot_dialog.setWindowIcon(QtGui.QIcon(image)) + self._subplot_dialog.show() def save_figure(self, *args): filetypes = self.canvas.get_supported_filetypes_grouped() @@ -800,13 +802,14 @@ def __init__(self, targetfig, parent): self._figure = targetfig self._defaults = {spinbox: vars(self._figure.subplotpars)[attr] for attr, spinbox in self._spinboxes.items()} + self._export_values_dialog = None def _export_values(self): # Explicitly round to 3 decimals (which is also the spinbox precision) # to avoid numbers of the form 0.100...001. - dialog = QtWidgets.QDialog() + self._export_values_dialog = QtWidgets.QDialog() layout = QtWidgets.QVBoxLayout() - dialog.setLayout(layout) + self._export_values_dialog.setLayout(layout) text = QtWidgets.QPlainTextEdit() text.setReadOnly(True) layout.addWidget(text) @@ -820,7 +823,7 @@ def _export_values(self): QtGui.QFontMetrics(text.document().defaultFont()) .size(0, text.toPlainText()).height() + 20) text.setMaximumSize(size) - dialog.exec_() + self._export_values_dialog.show() def _on_value_changed(self): spinboxes = self._spinboxes diff --git a/lib/matplotlib/backends/qt_editor/_formlayout.py b/lib/matplotlib/backends/qt_editor/_formlayout.py index 8aed078c0ddf..4ccc368c25f4 100644 --- a/lib/matplotlib/backends/qt_editor/_formlayout.py +++ b/lib/matplotlib/backends/qt_editor/_formlayout.py @@ -478,6 +478,7 @@ def update_buttons(self): def accept(self): self.data = self.formwidget.get() + self.apply_callback(self.data) super().accept() def reject(self): @@ -526,8 +527,13 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None): if QtWidgets.QApplication.startingUp(): _app = QtWidgets.QApplication([]) dialog = FormDialog(data, title, comment, icon, parent, apply) - if dialog.exec_(): - return dialog.get() + + if parent is not None: + if hasattr(parent, "_fedit_dialog"): + parent._fedit_dialog.close() + parent._fedit_dialog = dialog + + dialog.show() if __name__ == "__main__": diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index 8fc02f4b141b..8b5295f1d7df 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -259,10 +259,8 @@ def apply_callback(data): if not (axes.get_xlim() == orig_xlim and axes.get_ylim() == orig_ylim): figure.canvas.toolbar.push_current() - data = _formlayout.fedit( + _formlayout.fedit( datalist, title="Figure options", parent=parent, icon=QtGui.QIcon( str(cbook._get_data_path('images', 'qt4_editor_options.svg'))), apply=apply_callback) - if data is not None: - apply_callback(data)