def METHOD_NAME(self, event):
    """
    Handling saving state before application when application is
    being closed.
    """
    settings = QtCore.QSettings()
    settings.setValue("main_WindowGeometry", self.saveGeometry())
    settings.setValue("mainWindowState", self.saveState())
    self.settings.save(settings)
    #screen_shape = QtGui.QDesktopWidget().screenGeometry()
    main_window = self.window()
    width = main_window.frameGeometry().width()
    height = main_window.frameGeometry().height()
    settings.setValue('screen_shape', (width, height))
    qpos = self.pos()
    pos = qpos.x(), qpos.y()
    settings.setValue('pos', pos)
    q_app = QApplication.instance()
    if q_app is None:
        sys.exit()
    q_app.quit()