code: def closeEvent(self, event):
          
  
          # Make it snappy, but take care to clean it all up.
          # TODO(marcus): Enable GUI to return on problem, such
          # as asking whether or not the user really wants to quit
          # given there are things currently running.
          self.hide()
  
          if self.data["state"]["is_closing"]:
  
              # Explicitly clear potentially referenced data
              self.info(self.tr("Cleaning up models.."))
              for v in self.data["views"].values():
                  v.model().deleteLater()
                  v.setModel(None)
  
              self.info(self.tr("Cleaning up terminal.."))
              for item in self.data["models"]["terminal"].items:
                  del(item)
  
              self.info(self.tr("Cleaning up controller.."))
              self.controller.cleanup()
  
              self.info(self.tr("All clean!"))
              self.info(self.tr("Good bye"))
              return super(Window, self).closeEvent(event)
  
          self.info(self.tr("Closing.."))
  
          def on_problem():
              self.heads_up("Warning", "Had trouble closing down. "
                            "Please tell someone and try again.")
              self.show()
  
          if self.controller.is_running:
              self.info(self.tr("..as soon as processing is finished.."))
              self.controller.is_running = False
              self.finished.connect(self.close)
              util.defer(2000, on_problem)
              return event.ignore()
  
          self.data["state"]["is_closing"] = True
  
          util.defer(200, self.close)
          return event.ignore()
docs: Perform post-flight checks before closing
  
          Make sure processing of any kind is wrapped up before closing