Hi, I am embeding a matplotlib FigureCanvasWxAgg in a
> wxPython program.
> When i press the save botton the directory is that of
> the executable of the program. I want to change this to
> a certain directory. How can i do that?
There may be an intelligent way to set the default dir globally for file
dialogs in wx, but I don't know what it is. So I'll suggest a workaround.
You can create a custom toolbar and override save
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
class MyToolbar(class NavigationToolbar2Wx):
def save(self, evt):
# Fetch the required filename and file type.
filetypes = self.canvas._get_imagesave_wildcards()
# insert your default dir here
dlg =wx.FileDialog(self._parent, "Save to file", "", "", filetypes,
wx.SAVE|wx.OVERWRITE_PROMPT|wx.CHANGE_DIR)
if dlg.ShowModal() == wx.ID_OK:
dirname = dlg.GetDirectory()
filename = dlg.GetFilename()
DEBUG_MSG('Save file dir:%s name:%s' % (dirname, filename), 3, self)
self.canvas.print_figure(os.path.join(dirname, filename))
and then use this toolbar rather than the default one. See
examples/embedding_in_wx4.py for an example of how to use a custom
toolbar in a wx app.
JDH