Author: bugman Date: Tue Jan 26 14:00:17 2010 New Revision: 10379 URL: http://svn.gna.org/viewcvs/relax?rev=10379&view=rev Log: Modified savefile() to be up to relax' standards and to match the operation of openfile(). The current working directory is changed if the directory arg is not given. Modified: branches/bieri_gui/gui_bieri/filedialog.py Modified: branches/bieri_gui/gui_bieri/filedialog.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/filedialog.py?rev=10379&r1=10378&r2=10379&view=diff ============================================================================== --- branches/bieri_gui/gui_bieri/filedialog.py (original) +++ branches/bieri_gui/gui_bieri/filedialog.py Tue Jan 26 14:00:17 2010 @@ -92,20 +92,37 @@ return dialog.GetPath() -def savefile(msg, directory, filetype, default): # save a file +def savefile(msg=None, directory=None, filetype=None, default=None): + """Save a file. - #Input format: - #msg: message to display - #directory: directory, where dialog opens as default - #filetype: proposed file to save - #default: list of supported files, indicated as "(Label)|os command|... + For example to save /usr/save.relaxGUI, where the supported files to open are: *.relaxGUI, *.*: + savefile('select file to save', '/usr', 'save.relaxGUI', 'relaxGUI files (*.relaxGUI)|*.relaxGUI|all files (*.*)|*.*') - #command: - #savefile('select file to save', '/usr', 'save.relaxGUI', 'relaxGUI files (*.relaxGUI)|*.relaxGUI|all files (*.*)|*.*') - #suggests to save /usr/save.relaxGUI, supported files to save are: *.relaxGUI, *.* - newfile = None - dialog = wx.FileDialog ( None, message = msg, style = wx.SAVE, defaultDir= directory, defaultFile = filetype, wildcard = default) + @keyword msg: The message to display. + @type msg: str + @keyword directory: The directory to open in. + @type directory: str + @keyword filetype: The default file name to save to. + @type filetype: str + @keyword default: A list of supported files, indicated as "(Label)|os command|... + @type default: str + """ + + # The current working directory. + dir_switch = False + if directory == None: + directory = getcwd() + dir_switch = True + + # Open the dialog. + dialog = wx.FileDialog(None, message=msg, style=wx.SAVE, defaultDir=directory, defaultFile=filetype, wildcard=default) + + # A file was selected. if dialog.ShowModal() == wx.ID_OK: - newfile = dialog.GetPath() - return newfile + # Reset the current working directory if changed. + if dir_switch: + chdir(dialog.GetDirectory()) + + # Return the full file path. + return dialog.GetPath()