code: def OnClose(self, event):
          
  
          # If changes have taken place save of old grid
  
          if undo.stack().haschanged():
              save_choice = self.interfaces.get_save_request_from_user()
  
              if save_choice is None:
                  # Cancelled close operation
                  return
  
              elif save_choice:
                  # User wants to save content
                  post_command_event(self.main_window, self.main_window.SaveMsg)
  
          # Save the AUI state
  
          config["window_layout"] = repr(self.main_window._mgr.SavePerspective())
  
          # Uninit the AUI stuff
  
          self.main_window._mgr.UnInit()
  
          # Save config
          config.save()
  
          # Close main_window
  
          self.main_window.Destroy()
  
          # Set file mode to 600 to protect GPG passwd a bit
          sp = wx.StandardPaths.Get()
          pyspreadrc_path = sp.GetUserConfigDir() + "/." + config.config_filename
          try:
              os.chmod(pyspreadrc_path, 0600)
          except OSError:
              dummyfile = open(pyspreadrc_path, "w")
              dummyfile.close()
              os.chmod(pyspreadrc_path, 0600)
docs: Program exit event handler