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

Skip to content

Commit 1b908e3

Browse files
committed
Deprecate error_msg_foo helpers.
They are clearly intended for Matplotlib's internal use (e.g. error_msg_wx sets the title of the message dialog to "Matplotlib backend error"), and similar helpers have already been removed from other backends. Also correctly set the parents on the message dialogs, don't bother setting the button on wx.MessageDialog (which already defaults to CENTRE|OK), make the wx title also apply to other wxfoo backends, and rename a variable in backend_wx for consistency.
1 parent 7c2a3c4 commit 1b908e3

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``backend_gtk3.error_msg_gtk`` and ``backend_wx.error_msg_wx``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated.

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ def on_notify_filter(*args):
526526
try:
527527
self.canvas.figure.savefig(fname, format=fmt)
528528
except Exception as e:
529-
error_msg_gtk(str(e), parent=self)
529+
dialog = Gtk.MessageDialog(
530+
parent=self.canvas.get_toplevel(), message_format=str(e),
531+
type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK)
532+
dialog.run()
533+
dialog.destroy()
530534

531535

532536
class ToolbarGTK3(ToolContainerBase, Gtk.Box):
@@ -722,6 +726,7 @@ def trigger(self, *args, **kwargs):
722726
clipboard.set_image(pb)
723727

724728

729+
@_api.deprecated("3.6")
725730
def error_msg_gtk(msg, parent=None):
726731
if parent is not None: # find the toplevel Gtk.Window
727732
parent = parent.get_toplevel()

lib/matplotlib/backends/backend_wx.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class __getattr__:
5656
}))
5757

5858

59+
@_api.deprecated("3.6")
5960
def error_msg_wx(msg, parent=None):
6061
"""Signal an error condition with a popup error dialog."""
6162
dialog = wx.MessageDialog(parent=parent,
@@ -1153,15 +1154,15 @@ def save_figure(self, *args):
11531154
# Fetch the required filename and file type.
11541155
filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards()
11551156
default_file = self.canvas.get_default_filename()
1156-
dlg = wx.FileDialog(
1157+
dialog = wx.FileDialog(
11571158
self.canvas.GetParent(), "Save to file",
11581159
mpl.rcParams["savefig.directory"], default_file, filetypes,
11591160
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
1160-
dlg.SetFilterIndex(filter_index)
1161-
if dlg.ShowModal() == wx.ID_OK:
1162-
path = pathlib.Path(dlg.GetPath())
1161+
dialog.SetFilterIndex(filter_index)
1162+
if dialog.ShowModal() == wx.ID_OK:
1163+
path = pathlib.Path(dialog.GetPath())
11631164
_log.debug('%s - Save file path: %s', type(self), path)
1164-
fmt = exts[dlg.GetFilterIndex()]
1165+
fmt = exts[dialog.GetFilterIndex()]
11651166
ext = path.suffix[1:]
11661167
if ext in self.canvas.get_supported_filetypes() and fmt != ext:
11671168
# looks like they forgot to set the image type drop
@@ -1176,7 +1177,11 @@ def save_figure(self, *args):
11761177
try:
11771178
self.canvas.figure.savefig(str(path), format=fmt)
11781179
except Exception as e:
1179-
error_msg_wx(str(e))
1180+
dialog = wx.MessageDialog(
1181+
parent=self.canvas.GetParent(), message=str(e),
1182+
caption='Matplotlib error')
1183+
dialog.ShowModal()
1184+
dialog.Destroy()
11801185

11811186
def draw_rubberband(self, event, x0, y0, x1, y1):
11821187
height = self.canvas.figure.bbox.height

0 commit comments

Comments
 (0)