def OnSaveAs(self, event):
        """File save as event handler"""

        # Get filepath from user

        f2w = get_filetypes2wildcards(["pys", "pysu", "xls", "all"])
        filetypes = f2w.keys()
        wildcards = f2w.values()

        wildcard = "|".join(wildcards)

        message = _("Choose filename for saving.")
        style = wx.SAVE

        default_filetype = config["default_save_filetype"]
        try:
            default_filterindex = filetypes.index(default_filetype)
        except ValueError:
            # Be graceful if the user has entered an unkown filetype
            default_filterindex = 0

        get_fp_fidx = self.interfaces.get_filepath_findex_from_user
        filepath, filterindex = get_fp_fidx(wildcard, message, style,
                                            filterindex=default_filterindex)

        if filepath is None:
            return 0

        filetype = filetypes[filterindex]

        # Look if path is already present
        if os.path.exists(filepath):
            if not os.path.isfile(filepath):
                # There is a directory with the same path
                statustext = _("Directory present. Save aborted.")
                post_command_event(self.main_window,
                                   self.main_window.StatusBarMsg,
                                   text=statustext)
                return 0

            # There is a file with the same path
            message = \
                _("The file {filepath} is already present.\nOverwrite?")\
                .format(filepath=filepath)
            short_msg = _("File collision")

            if not self.main_window.interfaces.get_warning_choice(message,
                                                                  short_msg):

                statustext = _("File present. Save aborted by user.")
                post_command_event(self.main_window,
                                   self.main_window.StatusBarMsg,
                                   text=statustext)
                return 0

        # Put pys suffix if wildcard choice is 0
        if filterindex == 0 and filepath[-4:] != ".pys":
            filepath += ".pys"

        # Set the filepath state
        self.main_window.filepath = filepath

        # Set Window title to new filepath
        title_text = filepath.split("/")[-1] + " - pyspread"
        post_command_event(self.main_window, self.main_window.TitleMsg,
                           text=title_text)

        # Now jump to save
        post_command_event(self.main_window, self.main_window.SaveMsg,
                           attr={"filetype": filetype})
def OnSaveAs ( self , event ) : f2w = get_filetypes2wildcards ( [ "pys" , "pysu" , "xls" , "all" ] ) filetypes = f2w . keys ( ) wildcards = f2w . values ( ) wildcard = "|" . join ( wildcards ) message = _ ( "Choose filename for saving." ) style = wx . SAVE default_filetype = config [ "default_save_filetype" ] try : default_filterindex = filetypes . index ( default_filetype ) except ValueError : default_filterindex = 0 get_fp_fidx = self . interfaces . get_filepath_findex_from_user filepath , filterindex = get_fp_fidx ( wildcard , message , style , filterindex = default_filterindex ) if filepath is None : return 0 filetype = filetypes [ filterindex ] if os . path . exists ( filepath ) : if not os . path . isfile ( filepath ) : statustext = _ ( "Directory present. Save aborted." ) post_command_event ( self . main_window , self . main_window . StatusBarMsg , text = statustext ) return 0 message = _ ( "The file {filepath} is already present.\nOverwrite?" ) . format ( filepath = filepath ) short_msg = _ ( "File collision" ) if not self . main_window . interfaces . get_warning_choice ( message , short_msg ) : statustext = _ ( "File present. Save aborted by user." ) post_command_event ( self . main_window , self . main_window . StatusBarMsg , text = statustext ) return 0 if filterindex == 0 and filepath [ - 4 : ] != ".pys" : filepath += ".pys" self . main_window . filepath = filepath title_text = filepath . split ( "/" ) [ - 1 ] + " - pyspread" post_command_event ( self . main_window , self . main_window . TitleMsg , text = title_text ) post_command_event ( self . main_window , self . main_window . SaveMsg , attr = { "filetype" : filetype } )
File save as event handler