Permalink
Browse files

Supported & tested on wx, gtk, gtk3, qt3, tk.

  • Loading branch information...
1 parent 88dbef7 commit 41aa5052634ba305801d1f553b0348c6618942f6 pelson committed with May 31, 2012
@@ -2108,6 +2108,15 @@ def set_window_title(self, title):
if hasattr(self, "manager"):
self.manager.set_window_title(title)
+ def get_default_filename(self):
+ """
+ Return a string, which includes extension, suitable for use as
+ a default filename.
+ """
+ default_filename = self.get_window_title() or 'image'
+ default_filename = default_filename.lower().replace(' ', '_')
+ return default_filename + '.' + self.get_default_filetype()
+
def switch_backends(self, FigureCanvasClass):
"""
Instantiate an instance of FigureCanvasClass
@@ -529,7 +529,7 @@ def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
self.window = gtk.Window()
- self.window.set_title("Figure %d" % num)
+ self.set_window_title("Figure %d" % num)
if (window_icon):
try:
self.window.set_icon_from_file(window_icon)
@@ -620,6 +620,9 @@ def _get_toolbar(self, canvas):
toolbar = None
return toolbar
+ def get_window_title(self):
+ return self.window.get_title()
+
def set_window_title(self, title):
self.window.set_title(title)
@@ -725,11 +728,13 @@ def _init_toolbar2_4(self):
self.show_all()
def get_filechooser(self):
- return FileChooserDialog(
+ fc = FileChooserDialog(
title='Save the figure',
parent=self.win,
filetypes=self.canvas.get_supported_filetypes(),
default_filetype=self.canvas.get_default_filetype())
+ fc.set_current_name(self.canvas.get_default_filename())
+ return fc
def save_figure(self, *args):
fname, format = self.get_filechooser().get_filename_from_user()
@@ -358,7 +358,7 @@ def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
self.window = Gtk.Window()
- self.window.set_title("Figure %d" % num)
+ self.set_window_title("Figure %d" % num)
if (window_icon):
try:
self.window.set_icon_from_file(window_icon)
@@ -447,6 +447,9 @@ def _get_toolbar(self, canvas):
toolbar = None
return toolbar
+ def get_window_title(self):
+ return self.window.get_title()
+
def set_window_title(self, title):
self.window.set_title(title)
@@ -532,11 +535,13 @@ def _init_toolbar(self):
self.show_all()
def get_filechooser(self):
- return FileChooserDialog(
+ fc = FileChooserDialog(
title='Save the figure',
parent=self.win,
filetypes=self.canvas.get_supported_filetypes(),
default_filetype=self.canvas.get_default_filetype())
+ fc.set_current_name(self.canvas.get_default_filename())
+ return fc
def save_figure(self, *args):
fname, format = self.get_filechooser().get_filename_from_user()
@@ -219,7 +219,7 @@ def __init__( self, canvas, num ):
# Give the keyboard focus to the figure instead of the manager
self.canvas.setFocusPolicy( qt.QWidget.ClickFocus )
self.canvas.setFocus()
- self.window.setCaption( "Figure %d" % num )
+ self.set_window_title( "Figure %d" % num )
self.window._destroying = False
@@ -293,6 +293,9 @@ def destroy( self, *args ):
if DEBUG: print("destroy figure manager")
self.window.close(True)
+ def get_window_title(self):
+ return str(self.window.caption())
+
def set_window_title(self, title):
self.window.setCaption(title)
@@ -420,7 +423,7 @@ def save_figure(self, *args):
sorted_filetypes.sort()
default_filetype = self.canvas.get_default_filetype()
- start = 'image.' + default_filetype
+ start = self.canvas.get_default_filename()
filters = []
selectedFilter = None
for name, exts in sorted_filetypes:
@@ -494,7 +494,7 @@ def __init__(self, canvas, num, window):
FigureManagerBase.__init__(self, canvas, num)
self.window = window
self.window.withdraw()
- self.window.wm_title("Figure %d" % num)
+ self.set_window_title("Figure %d" % num)
self.canvas = canvas
self._num = num
_, _, w, h = canvas.figure.bbox.bounds
@@ -565,6 +565,9 @@ def destroy(self, *args):
self.window.quit()
self.window = None
+ def get_window_title(self):
+ return self.window.wm_title()
+
def set_window_title(self, title):
self.window.wm_title(title)
@@ -874,7 +877,8 @@ def save_figure(self, *args):
master=self.window,
title='Save the figure',
filetypes = tk_filetypes,
- defaultextension = defaultextension
+ defaultextension = defaultextension,
+ initialfile=self.canvas.get_default_filename(),
)
if fname == "" or fname == ():
@@ -1603,6 +1603,9 @@ def destroy(self, *args):
#wx.GetApp().ProcessIdle()
wx.WakeUpIdle()
+ def get_window_title(self):
+ return self.window.GetTitle()
+
def set_window_title(self, title):
self.window.SetTitle(title)
@@ -1840,7 +1843,7 @@ def configure_subplots(self, evt):
def save_figure(self, *args):
# Fetch the required filename and file type.
filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards()
- default_file = "image." + self.canvas.get_default_filetype()
+ default_file = self.canvas.get_default_filename()
dlg = wx.FileDialog(self._parent, "Save to file", "", default_file,
filetypes,
wx.SAVE|wx.OVERWRITE_PROMPT)

0 comments on commit 41aa505

Please sign in to comment.