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

Skip to content

Commit 7991829

Browse files
committed
add modality
1 parent 1cf8786 commit 7991829

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Modality of _formlayout
2+
~~~~~~~~~~~~~~~~~~~~~~~
3+
The `fedit` function and the `FormDialog` class in the private
4+
`matplotlib\backends\qt_editor\_formlayout`
5+
gains a new option: `modal`. The current behaviour (modal window) is the default.
6+
If modal is set to false, the dialog is shown without returning anything.
7+
This allows e.g. using the figures with the options open.

lib/matplotlib/backends/backend_qt5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def configure_subplots(self):
781781
image = str(cbook._get_data_path('images/matplotlib.png'))
782782
dia = SubplotToolQt(self.canvas.figure, self.canvas.parent())
783783
dia.setWindowIcon(QtGui.QIcon(image))
784-
dia.exec_()
784+
dia.show()
785785

786786
def save_figure(self, *args):
787787
filetypes = self.canvas.get_supported_filetypes_grouped()
@@ -870,7 +870,7 @@ def _export_values(self):
870870
QtGui.QFontMetrics(text.document().defaultFont())
871871
.size(0, text.toPlainText()).height() + 20)
872872
text.setMaximumSize(size)
873-
dialog.exec_()
873+
dialog.show()
874874

875875
def _on_value_changed(self):
876876
self._figure.subplots_adjust(**{attr: self._widgets[attr].value()

lib/matplotlib/backends/qt_editor/_formlayout.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,11 @@ def get(self):
413413
class FormDialog(QtWidgets.QDialog):
414414
"""Form Dialog"""
415415
def __init__(self, data, title="", comment="",
416-
icon=None, parent=None, apply=None):
416+
icon=None, parent=None, apply=None, modal=True):
417417
super().__init__(parent)
418418

419419
self.apply_callback = apply
420+
self.modal = modal
420421

421422
# Form
422423
if isinstance(data[0][0], (list, tuple)):
@@ -469,6 +470,8 @@ def update_buttons(self):
469470
btn.setEnabled(valid)
470471

471472
def accept(self):
473+
if not self.modal:
474+
self.apply_callback(self.formwidget.get())
472475
self.data = self.formwidget.get()
473476
super().accept()
474477

@@ -484,7 +487,8 @@ def get(self):
484487
return self.data
485488

486489

487-
def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
490+
def fedit(data, title="", comment="", icon=None, parent=None, apply=None,
491+
modal=True):
488492
"""
489493
Create form dialog and return result
490494
(if Cancel button is pressed, return None)
@@ -495,6 +499,7 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
495499
icon: QIcon instance
496500
parent: parent QWidget
497501
apply: apply callback (function)
502+
modal: modality of dialog
498503
499504
datalist: list/tuple of (field_name, field_value)
500505
datagroup: list/tuple of (datalist *or* datagroup, title, comment)
@@ -511,13 +516,19 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
511516
- list/tuple:
512517
* the first element will be the selected index (or value)
513518
* the other elements can be couples (key, value) or only values
519+
520+
If modal is True, the application will block until the result is selected.
521+
If modal is false, the dialog will be shown and the function returns None.
514522
"""
515523

516524
# Create a QApplication instance if no instance currently exists
517525
# (e.g., if the module is used directly from the interpreter)
518526
if QtWidgets.QApplication.startingUp():
519527
_app = QtWidgets.QApplication([])
520-
dialog = FormDialog(data, title, comment, icon, parent, apply)
528+
dialog = FormDialog(data, title, comment, icon, parent, apply, modal)
529+
if not modal:
530+
dialog.show()
531+
return
521532
if dialog.exec_():
522533
return dialog.get()
523534

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,8 @@ def apply_callback(data):
251251
if not (axes.get_xlim() == orig_xlim and axes.get_ylim() == orig_ylim):
252252
figure.canvas.toolbar.push_current()
253253

254-
data = _formlayout.fedit(
254+
_formlayout.fedit(
255255
datalist, title="Figure options", parent=parent,
256256
icon=QtGui.QIcon(
257257
str(cbook._get_data_path('images', 'qt4_editor_options.svg'))),
258-
apply=apply_callback)
259-
if data is not None:
260-
apply_callback(data)
258+
apply=apply_callback, modal=False)

0 commit comments

Comments
 (0)