code: def save_macros(self, filepath, macros):
          
  
          io_error_text = _("Error writing to file {filepath}.")
          io_error_text = io_error_text.format(filepath=filepath)
  
          # Make sure that old macro file does not get lost on abort save
          tmpfile = filepath + "~"
  
          try:
              wx.BeginBusyCursor()
              self.main_window.grid.Disable()
              with open(tmpfile, "w") as macro_outfile:
                  macro_outfile.write(macros)
  
              # Move save file from temp file to filepath
              try:
                  os.rename(tmpfile, filepath)
  
              except OSError:
                  # No tmp file present
                  pass
  
          except IOError:
              try:
                  post_command_event(self.main_window, self.StatusBarMsg,
                                     text=io_error_text)
              except TypeError:
                  # The main window does not exist any more
                  pass
  
              return False
  
          finally:
              self.main_window.grid.Enable()
              wx.EndBusyCursor()
docs: Saves macros to file
  
          Parameters
          ----------
          filepath: String
          \tPath to macro file
          macros: String
          \tMacro code