Skip to content

Commit 395acc1

Browse files
committed
in qt4 backend, define get_window_title and call it for default savefig filename
revert prior changes to qt backend, since I can't test them
1 parent 16dd729 commit 395acc1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,14 @@ def get_default_filetype(self):
20922092
"""
20932093
return rcParams['savefig.format']
20942094

2095+
def get_window_title(self):
2096+
"""
2097+
Get the title text of the window containing the figure.
2098+
Return None if there is no window (eg, a PS backend).
2099+
"""
2100+
if hasattr(self, "manager"):
2101+
return self.manager.get_window_title()
2102+
20952103
def set_window_title(self, title):
20962104
"""
20972105
Set the title text of the window containing the figure. Note that
@@ -2413,6 +2421,13 @@ def show_popup(self, msg):
24132421
"""
24142422
pass
24152423

2424+
def get_window_title(self):
2425+
"""
2426+
Get the title text of the window containing the figure.
2427+
Return None if there is no window (eg, a PS backend).
2428+
"""
2429+
pass
2430+
24162431
def set_window_title(self, title):
24172432
"""
24182433
Set the title text of the window containing the figure. Note that

lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,8 @@ def save_figure(self, *args):
419419
sorted_filetypes = filetypes.items()
420420
sorted_filetypes.sort()
421421
default_filetype = self.canvas.get_default_filetype()
422-
default_filename = str(self.canvas.window().windowTitle()) or 'image'
423-
default_filename = default_filename.replace(' ', '_')
424422

425-
start = default_filename + '.' + default_filetype
423+
start = 'image.' + default_filetype
426424
filters = []
427425
selectedFilter = None
428426
for name, exts in sorted_filetypes:

lib/matplotlib/backends/backend_qt4.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ def destroy( self, *args ):
481481
if DEBUG: print("destroy figure manager")
482482
self.window.close()
483483

484+
def get_window_title(self):
485+
return str(self.window.windowTitle())
486+
484487
def set_window_title(self, title):
485488
self.window.setWindowTitle(title)
486489

@@ -614,7 +617,7 @@ def save_figure(self, *args):
614617
sorted_filetypes = filetypes.items()
615618
sorted_filetypes.sort()
616619
default_filetype = self.canvas.get_default_filetype()
617-
default_filename = str(self.canvas.window().windowTitle()) or 'image'
620+
default_filename = self.canvas.get_window_title() or 'image'
618621
default_filename = default_filename.replace(' ', '_')
619622

620623
start = default_filename + '.' + default_filetype

0 commit comments

Comments
 (0)