8000 None is for no file saved · matplotlib/matplotlib@1e278ec · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e278ec

Browse files
committed
None is for no file saved
1 parent 2799190 commit 1e278ec

File tree

10 files changed

+16
-19
lines changed

10 files changed

+16
-19
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
``NavigationToolbar2.save_figure`` now returns filepath of saved figure
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

4-
``NavigationToolbar2.save_figure`` function may return the filename of the saved figure.
4+
``NavigationToolbar2.save_figure`` function may return the filename of the saved figure.
55

6-
If a backend implements this functionality it should return ``NavigationToolbar2.NO_FILE_SAVED``
6+
If a backend implements this functionality it should return `None`
77
in the case where no figure is actually saved (because the user closed the dialog without saving).
88

99
If the backend does not or can not implement this functionality (currently the Gtk4 backends
10-
and webagg backends do not) this this method will return `None`.
10+
and webagg backends do not) this method will return ``NavigationToolbar2.UNKNOWN_SAVED_STATUS``.

lib/matplotlib/backend_bases.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,7 @@ class NavigationToolbar2:
28582858
('Save', 'Save the figure', 'filesave', 'save_figure'),
28592859
)
28602860

2861-
NO_FILE_SAVED = object()
2861+
UNKNOWN_SAVED_STATUS = object()
28622862

28632863
def __init__(self, canvas):
28642864
self.canvas = canvas
@@ -3276,23 +3276,22 @@ def on_tool_fig_close(e):
32763276
def save_figure(self, *args):
32773277
"""
32783278
Save the current figure.
3279-
3279+
32803280
Backend implementations may choose to return
32813281
the absolute path of the saved file, if any, as
32823282
a string.
32833283
3284-
If no file is created then `NavigationToolbar2.NO_FILE_SAVED`
3285-
is returned.
3284+
If no file is created then `None` is returned.
32863285
32873286
If the backend does not implement this functionality
3288-
then `None` is returned.
3287+
then `NavigationToolbar2.UNKNOWN_SAVED_STATUS` is returned.
32893288
32903289
Returns
32913290
-------
3292-
str or `NavigationToolbar2.NO_FILE_SAVED` or `None`
3291+
str or `NavigationToolbar2.UNKNOWN_SAVED_STATUS` or `None`
32933292
The filepath of the saved figure.
3294-
Returns `NavigationToolbar2.NO_FILE_SAVED` if figure is not saved.
3295-
Returns `None` when the backend does not provide the information.
3293+
Returns `None` if figure is not saved.
3294+
Returns `NavigationToolbar2.UNKNOWN_SAVED_STATUS` when the backend does not provide the information.
32963295
"""
32973296
raise NotImplementedError
32983297

lib/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class _Mode(str, Enum):
406406

407407
class NavigationToolbar2:
408408
toolitems: tuple[tuple[str, ...] | tuple[None, ...], ...]
409-
NO_FILE_SAVED: object
409+
UNKNOWN_SAVED_STATUS: object
410410
canvas: FigureCanvasBase
411411
mode: _Mode
412412
def __init__(self, canvas: FigureCanvasBase) -> None: ...

lib/matplotlib/backends/_backend_tk.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ def save_figure(self, *args):
885885
return fname
886886
except Exception as e:
887887
tkinter.messagebox.showerror("Error saving file", str(e))
888-
return self.FILE_NOT_SAVED
889888

890889
def set_history_buttons(self):
891890
state_map = {True: tk.NORMAL, False: tk.DISABLED}

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def on_notify_filter(*args):
371371
fmt = self.canvas.get_supported_filetypes_grouped()[ff.get_name()][0]
372372
dialog.destroy()
373373
if response != Gtk.ResponseType.OK:
374-
return self.NO_FILE_SAVED
374+
return None
375375
# Save dir for next time, unless empty str (which means use cwd).
376376
if mpl.rcParams['savefig.directory']:
377377
mpl.rcParams['savefig.directory'] = os.path.dirname(fname)
@@ -384,7 +384,6 @@ def on_notify_filter(*args):
384384
type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK)
385385
dialog.run()
386386
dialog.destroy()
387-
return self.NO_FILE_SAVED
388387

389388

390389
class ToolbarGTK3(ToolContainerBase, Gtk.Box):

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def on_response(dialog, response):
391391
msg.show()
392392

393393
dialog.show()
394+
return self.UNKNOWN_SAVED_STATUS
394395

395396

396397
class ToolbarGTK4(ToolContainerBase, Gtk.Box):

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def save_figure(self, *args):
137137
directory,
138138
self.canvas.get_default_filename())
139139
if filename is None: # Cancel
140-
return self.NO_FILE_SAVED
140+
return
141141
# Save dir for next time, unless empty str (which means use cwd).
142142
if mpl.rcParams['savefig.directory']:
143143
mpl.rcParams['savefig.directory'] = os.path.dirname(filename)

lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,13 +834,12 @@ def save_figure(self, *args):
834< F438 /td>834
mpl.rcParams['savefig.directory'] = os.path.dirname(fname)
835835
try:
836836
self.canvas.figure.savefig(fname)
837-
return fname
838837
except Exception as e:
839838
QtWidgets.QMessageBox.critical(
840839
self, "Error saving file", str(e),
841840
QtWidgets.QMessageBox.StandardButton.Ok,
842841
QtWidgets.QMessageBox.StandardButton.NoButton)
843-
return self.NO_FILE_SAVED
842+
return fname
844843

845844
def set_history_buttons(self):
846845
can_backward = self._nav_stack._pos > 0

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ def remove_rubberband(self):
405405
def save_figure(self, *args):
406406
"""Save the current figure."""
407407
self.canvas.send_event('save')
408+
return self.UNKNOWN_SAVED_STATUS
408409

409410
def pan(self):
410411
super().pan()

lib/matplotlib/backends/backend_wx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,6 @@ def save_figure(self, *args):
11501150
caption='Matplotlib error')
11511151
dialog.ShowModal()
11521152
dialog.Destroy()
1153-
return self.NO_FILE_SAVED
11541153

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

0 commit comments

Comments
 (0)
0