10000 Merge pull request #29784 from meeseeksmachine/auto-backport-of-pr-29… · matplotlib/matplotlib@2736c12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2736c12

Browse files
authored
Merge pull request #29784 from meeseeksmachine/auto-backport-of-pr-29781-on-v3.10.x
Backport PR #29781 on branch v3.10.x (Fix escaping of nulls and "0" in default filenames.)
2 parents d4820f3 + 2ddb364 commit 2736c12

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
@@ -2218,7 +2218,7 @@ def get_default_filename(self):
22182218
# Characters to be avoided in a NT path:
22192219
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
22202220
# plus ' '
2221-
removed_chars = r'<>:"/\|?*\0 '
2221+
removed_chars = '<>:"/\\|?*\0 '
22222222
default_basename = default_basename.translate(
22232223
{ord(c): "_" for c in removed_chars})
22242224
default_filetype = self.get_default_filetype()
@@ -2728,23 +2728,24 @@ def resize(self, w, h):
27282728
"""For GUI backends, resize the window (in physical pixels)."""
27292729

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

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

27492750

27502751
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)
0