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

Skip to content

PR: Remove modality of figure options #18966

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 3 commits into from
Jul 7, 2021
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
15 changes: 9 additions & 6 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we leave this as modal, will it block the main window, or just the subplot tool? I think it would be best if it blocked the tool, but not the main window, if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, everything happens on a single thread, so it would not be possible as exec_ would block the thread.


def _on_value_changed(self):
spinboxes = self._spinboxes
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/backends/qt_editor/_formlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__":
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)