Skip to content

Commit 3460977

Browse files
committed
Fix escaping of nulls and "0" in default filenames.
Adding a test for this required tweaking a bit the behavior of non-GUI managers (so that they also store the window title); note that the comment of non-GUIs returning None was clearly wrong.
1 parent 9f7b3dd commit 3460977

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ def get_default_filename(self):
22202220
# Characters to be avoided in a NT path:
22212221
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
22222222
# plus ' '
2223-
removed_chars = r'<>:"/\|?*\0 '
2223+
removed_chars = r'<>:"/\|?*''\0 '
22242224
default_basename = default_basename.translate(
22252225
{ord(c): "_" for c in removed_chars})
22262226
default_filetype = self.get_default_filetype()
@@ -2730,23 +2730,24 @@ def resize(self, w, h):
27302730
"""For GUI backends, resize the window (in physical pixels)."""
27312731

27322732
def get_window_title(self):
2733-
"""
2734-
Return the title text of the window containing the figure, or None
2735-
if there is no window (e.g., a PS backend).
2736-
"""
2737-
return 'image'
2733+
"""Return the title text of the window containing the figure."""
2734+
return self._window_title
27382735

27392736
def set_window_title(self, title):
27402737
"""
27412738
Set the title text of the window containing the figure.
27422739
2743-
This has no effect for non-GUI (e.g., PS) backends.
2744-
27452740
Examples
27462741
--------
27472742
>>> fig = plt.figure()
27482743
>>> fig.canvas.manager.set_window_title('My figure')
27492744
"""
2745+
# This attribute is not defined in __init__ (but __init__ calls this
2746+
# setter), as derived classes (real GUI managers) will store this
2747+
# information directly on the widget; only the base (non-GUI) manager
2748+
# class needs a specific attribute for it (so that filename escaping
2749+
# can be checked in the test suite).
2750+
self._window_title = title
27502751

27512752

27522753
cursors = tools.cursors

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def test_canvas_ctor():
6464

6565

6666
def test_get_default_filename():
67-
assert plt.figure().canvas.get_default_filename() == 'image.png'
67+
fig = plt.figure()
68+
assert fig.canvas.get_default_filename() == "Figure_1.png"
69+
fig.canvas.manager.set_window_title("0:1/2<3")
70+
assert fig.canvas.get_default_filename() == "0_1_2_3.png"
6871

6972

7073
def test_canvas_change():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy