'When the user clicks on the X button'

def closeEvent(self, event):

    if self.form_widget.THReactor.isRunning():
        self.form_widget.THReactor.stop()
    if (not self.form_widget.FSettings.Settings.get_setting('accesspoint', 'persistNetwokManager', format=bool)):
        if (self.networkcontrol != None):
            self.networkcontrol.remove_settingsNM()
    iwconfig = Popen(['iwconfig'], stdout=PIPE, shell=False, stderr=PIPE)
    for i in iwconfig.stdout.readlines():
        if search('Mode:Monitor', i):
            self.reply = QMessageBox.question(self, 'About    Exit', 'Are    you    sure    to    quit?', (QMessageBox.Yes | QMessageBox.No), QMessageBox.No)
            if (self.reply == QMessageBox.Yes):
                set_monitor_mode(i.split()[0]).setDisable()
                return event.accept()
            return event.ignore()
    if (self.form_widget.Apthreads['RougeAP'] != []):
        self.reply = QMessageBox.question(self, 'About    Access    Point', 'Are    you    sure    to    stop    all    threads    AP    ?', (QMessageBox.Yes | QMessageBox.No), QMessageBox.No)
        if (self.reply == QMessageBox.Yes):
            print 'killing    all    threads...'
            self.form_widget.Stop_PumpAP()
            return event.accept()
        return event.ignore()
    return event.accept()
