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

Skip to content

Commit 5b31071

Browse files
authored
Merge pull request #18966 from impact27/non_modal_dialog
PR: Remove modality of figure options
2 parents 2a7d9bf + 68d8627 commit 5b31071

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ def __init__(self, canvas, parent, coordinates=True):
605605

606606
self.coordinates = coordinates
607607
self._actions = {} # mapping of toolitem method names to QActions.
608+
self._subplot_dialog = None
608609

609610
for text, tooltip_text, image_file, callback in self.toolitems:
610611
if text is None:
@@ -714,9 +715,10 @@ def remove_rubberband(self):
714715

715716
def configure_subplots(self):
716717
image = str(cbook._get_data_path('images/matplotlib.png'))
717-
dia = SubplotToolQt(self.canvas.figure, self.canvas.parent())
718-
dia.setWindowIcon(QtGui.QIcon(image))
719-
dia.exec_()
718+
self._subplot_dialog = SubplotToolQt(
719+
self.canvas.figure, self.canvas.parent())
720+
self._subplot_dialog.setWindowIcon(QtGui.QIcon(image))
721+
self._subplot_dialog.show()
720722

721723
def save_figure(self, *args):
722724
filetypes = self.canvas.get_supported_filetypes_grouped()
@@ -800,13 +802,14 @@ def __init__(self, targetfig, parent):
800802
self._figure = targetfig
801803
self._defaults = {spinbox: vars(self._figure.subplotpars)[attr]
802804
for attr, spinbox in self._spinboxes.items()}
805+
self._export_values_dialog = None
803806

804807
def _export_values(self):
805808
# Explicitly round to 3 decimals (which is also the spinbox precision)
806809
# to avoid numbers of the form 0.100...001.
807-
dialog = QtWidgets.QDialog()
810+
self._export_values_dialog = QtWidgets.QDialog()
808811
layout = QtWidgets.QVBoxLayout()
809-
dialog.setLayout(layout)
812+
self._export_values_dialog.setLayout(layout)
810813
text = QtWidgets.QPlainTextEdit()
811814
text.setReadOnly(True)
812815
layout.addWidget(text)
@@ -820,7 +823,7 @@ def _export_values(self):
820823
QtGui.QFontMetrics(text.document().defaultFont())
821824
.size(0, text.toPlainText()).height() + 20)
822825
text.setMaximumSize(size)
823-
dialog.exec_()
826+
self._export_values_dialog.show()
824827

825828
def _on_value_changed(self):
826829
spinboxes = self._spinboxes

lib/matplotlib/backends/qt_editor/_formlayout.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ def update_buttons(self):
478478

479479
def accept(self):
480480
self.data = self.formwidget.get()
481+
self.apply_callback(self.data)
481482
super().accept()
482483

483484
def reject(self):
@@ -526,8 +527,13 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
526527
if QtWidgets.QApplication.startingUp():
527528
_app = QtWidgets.QApplication([])
528529
dialog = FormDialog(data, title, comment, icon, parent, apply)
529-
if dialog.exec_():
530-
return dialog.get()
530+
531+
if parent is not None:
532+
if hasattr(parent, "_fedit_dialog"):
533+
parent._fedit_dialog.close()
534+
parent._fedit_dialog = dialog
535+
536+
dialog.show()
531537

532538

533539
if __name__ == "__main__":

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,8 @@ def apply_callback(data):
259259
if not (axes.get_xlim() == orig_xlim and axes.get_ylim() == orig_ylim):
260260
figure.canvas.toolbar.push_current()
261261

262-
data = _formlayout.fedit(
262+
_formlayout.fedit(
263263
datalist, title="Figure options", parent=parent,
264264
icon=QtGui.QIcon(
265265
str(cbook._get_data_path('images', 'qt4_editor_options.svg'))),
266266
apply=apply_callback)
267-
if data is not None:
268-
apply_callback(data)

0 commit comments

Comments
 (0)