From 423f465988089d7bb92e43f1d3d28efbd54b3b44 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Fri, 11 Jun 2021 14:01:03 +0200 Subject: [PATCH 1/3] set settings window to non modal --- lib/matplotlib/backends/backend_qt5.py | 4 ++-- lib/matplotlib/backends/qt_editor/_formlayout.py | 4 ++-- lib/matplotlib/backends/qt_editor/figureoptions.py | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 823a50ddad6a..db3a941a85d4 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -716,7 +716,7 @@ 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_() + dia.show() def save_figure(self, *args): filetypes = self.canvas.get_supported_filetypes_grouped() @@ -820,7 +820,7 @@ def _export_values(self): QtGui.QFontMetrics(text.document().defaultFont()) .size(0, text.toPlainText()).height() + 20) text.setMaximumSize(size) - dialog.exec_() + 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..752360a735fb 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,7 @@ 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() + 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) From c9f5c3bebbe1753cce423006c358b3ae792f334a Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Wed, 16 Jun 2021 07:39:13 +0200 Subject: [PATCH 2/3] fix subplot dialog --- lib/matplotlib/backends/backend_qt5.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index db3a941a85d4..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.show() + 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.show() + self._export_values_dialog.show() def _on_value_changed(self): spinboxes = self._spinboxes From 68d86276060ee1976231a095beb2eb6df4656b28 Mon Sep 17 00:00:00 2001 From: Quentin Peter Date: Wed, 16 Jun 2021 07:48:19 +0200 Subject: [PATCH 3/3] only allow a single fedit --- lib/matplotlib/backends/qt_editor/_formlayout.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/matplotlib/backends/qt_editor/_formlayout.py b/lib/matplotlib/backends/qt_editor/_formlayout.py index 752360a735fb..4ccc368c25f4 100644 --- a/lib/matplotlib/backends/qt_editor/_formlayout.py +++ b/lib/matplotlib/backends/qt_editor/_formlayout.py @@ -527,6 +527,12 @@ 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 parent is not None: + if hasattr(parent, "_fedit_dialog"): + parent._fedit_dialog.close() + parent._fedit_dialog = dialog + dialog.show()