import datetime
import sys
from PyQt6 import QtCore
from PyQt6.QtCore import Qt, QThread,QObject,QThreadPool, QTimer
from PyQt6.QtGui import QColor, QFont
from PyQt6.QtTextToSpeech import QTextToSpeech
from PyQt6.QtWidgets import QApplication, QWidget, QMessageBox, QTableWidgetItem, QAbstractItemView
from UI.main22 import Ui_Form
from Functions.QtFunctions.LogerinTxt import app_logger
from Functions.QtFunctions import findServerWidget as FindServerWidget
from Functions.QtFunctions import LoginWidget_display as loginWidget
from Functions.apiFunction import api_fc

headerlabel0= ["序号","数据序号","备","机号","航班信息","机型","机型信息","发动机","机位","航班号","备","计达","备","预达",
     "备","计飞","备","备","机位","类型","备","放行","备","工1","备","工2","备","工3","备","工4",
     "备","班组长","备","到位","备","放行","备","销夹","电签","随机","备","随机","备","保留","备","工作包",
     "备","进出港城市","备","维修人员","交班人员","放行","备","航班编号","备","任务编号","备","TATD","备","类型",
     "备","附加消息","备","备","备","备"]
headerlabel_B=["序号", "机号", "机型", "发动机", "航班号", "计达", "预达", "计飞", "机位", "类型", "工作单", "飞单", "客舱单",
             "临工单","AMRO记录", "电签复查", "接机电签", "任务电签", "二送电签", "备", "备", "备", "备", "备", "进出港城市",
             "维修人员", "二送人员","放行", "航班编号", "电签工卡", "备", "类型", "附加消息"]

versionNumb= "18.0.0"

class sortdisplaySever(QObject):
    sortupdate = QtCore.pyqtSignal(str, dict, list, str, str)
    def __init__(self, name, ip, selectedtime, text, displayMode, selectedbc, displayselect, thread):
        super().__init__()
        self.funcName = name
        self.ipinfo = ip
        self.selectedtime = selectedtime
        self.text = text
        self.displayMode = displayMode
        self.selectedbc = selectedbc
        self.displayselect_mode = displayselect
        self.thread = thread
        nowDay = datetime.datetime.now().strftime("%Y%m%d")
        tomorr =(datetime.date.today() + datetime.timedelta(days=1)).strftime("%Y%m%d")
        yester =(datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
        if self.selectedtime == nowDay:
            self.date = "2"
        elif self.selectedtime == tomorr:
            self.date = "3"
        elif self.selectedtime == yester:
            self.date = "1"
        else:
            self.date = "4"

    def run(self):
        try:
            list = []
            if self.funcName == "sortTableWidgetDispaly":
                #print("1")
                self.sortTableWidgetDispaly()
                self.sortupdate.emit("sortTableWidgetDispaly", self.sorttableWidgetDispalydata, list, self.seversts,self.displayMode)
                self.sortupdate.emit("sortTableWidgetDispalyALL", self.DispalydataAll, list, self.seversts,self.displayMode)
            if self.funcName == "sortTableWidgetDispalyALL":
                #print("2")
                self.sortTableWidgetDispalyALL()
                self.sortupdate.emit("sortTableWidgetDispalyALL", self.sorttableWidgetDispalydata, list, self.seversts,self.displayMode)
            elif self.funcName == "SearchsortTableWidgetDispaly":
                #print("3")
                self.SearchsortTableWidgetDispaly()
                self.sortupdate.emit("SearchsortTableWidgetDispaly", self.sorttableWidgetDispalydata, list,self.seversts,self.displayMode)
            elif self.funcName == "sorttableWidgetDisplayChange":
                #print("4")
                self.sorttableWidgetDisplayChange()
                self.sortupdate.emit("sorttableWidgetDisplayChange", self.sortlogchange, list, self.seversts,self.displayMode)
            elif self.funcName == "sorttableWidgetPeopleDisplay":
                self.sorttableWidgetPeopleDisplay()
                self.sortupdate.emit("sorttableWidgetPeopleDisplay", self.sortdiplaylist, self.peopleOnJob,self.seversts, self.displayMode)
            elif self.funcName == "sorttableWidgetLOGDispaly":
                self.sorttableWidgetLOGDispaly()
                self.sortupdate.emit("sorttableWidgetLOGDispaly", self.sortlog, list, self.seversts, self.displayMode)
            elif self.funcName == "sorttableWidgetPHONEDispaly":
                self.sorttableWidgetPHONEDispaly()
                self.sortupdate.emit("sorttableWidgetPHONEDispaly", self.sorttableWidgetPHONEDispalydata, list,self.seversts, "")
            self.thread.quit()
        except Exception as e:
            app_logger.log_error(e)
        finally:
            self.thread.quit()

    def severpost_nomeassge(self, postname, **kwargs):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname) + str(postdata) + str(postdata2) + str(postdata3)
            try:
                # res = requests.get(url=ip, timeout=30).json()
                if kwargs:
                    res = api_fc.request_post('/static/{}'.format(str(postname)), **kwargs)
                else:
                    res = api_fc.request_get('/static/{}'.format(str(postname)))
                self.seversts = "1"
                return res
            except Exception as e:
                app_logger.log_error(e)
                app_logger.log_error("重大bug")
                app_logger.log_error(postname, kwargs)
                self.seversts = "0"
                return []
        except Exception as e:
            app_logger.log_error(e)

    def sorttableWidgetPHONEDispaly(self):
        try:
            sorttableWidgetPHONEDispalydataall = self.severpost_nomeassge("getphonelist")
            self.sorttableWidgetPHONEDispalydata = {}
            num = 0
            if sorttableWidgetPHONEDispalydataall != None:
                if self.text != "":
                    for i in sorttableWidgetPHONEDispalydataall.keys():
                        if str.lower(str(self.text)) in str(sorttableWidgetPHONEDispalydataall[i]):
                            self.sorttableWidgetPHONEDispalydata[str(num)] = sorttableWidgetPHONEDispalydataall[i]
                            num += 1
                else:
                    self.sorttableWidgetPHONEDispalydata = sorttableWidgetPHONEDispalydataall
        except Exception as e:
            app_logger.log_error(e)

    def checkall(self, datas, text):
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if datas[i]["109"] != text:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res

    def checkStrsingle(self,datas, text, text2): #单一条件筛选
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if str(text) in str(datas[i]) and datas[i]["109"] != text2:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res
    def checkStrTerminalAll(self,datas, text1,text2,text3,text4): #筛选航站且显示全部
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if str(datas[i]["8"]) != "" and datas[i]["109"] != text1:
                    if str(datas[i]["8"])[0] == text2 and str(datas[i]["8"])[0] == text3:
                        res[str(num)] = datas[i]
                        num += 1
                elif str(datas[i]["8"]) == "" and str(datas[i]["109"]) == text4:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res
    def checkStrTerminalAll2(self,datas, text1,text2,text3,text4): #筛选航站且显示全部
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if str(datas[i]["8"]) != "" and datas[i]["109"] != text1:
                    if str(datas[i]["8"])[0] != text2 and str(datas[i]["8"])[0] != text3:
                        res[str(num)] = datas[i]
                        num += 1
                elif str(datas[i]["8"]) == "" and str(datas[i]["109"]) == text4:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res
    def checkStrTerminalAll3(self,datas, text1,text2,text3,text4): #筛选航站且显示全部
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if str(datas[i]["8"]) != "" and datas[i]["109"] == text1:
                    if str(datas[i]["8"])[0] == text2 and str(datas[i]["8"])[0] == text3:
                        res[str(num)] = datas[i]
                        num += 1
                elif str(datas[i]["8"]) == "" and str(datas[i]["109"]) == text4:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res
    def checkStrTerminalAll4(self,datas, text1,text2,text3,text4): #筛选航站且显示全部
        res = {}
        try:
            num = 0
            for i in datas.keys():
                if str(datas[i]["8"]) != "" and datas[i]["109"] == text1:
                    if str(datas[i]["8"])[0] != text2 and str(datas[i]["8"])[0] != text3:
                        res[str(num)] = datas[i]
                        num += 1
                elif str(datas[i]["8"]) == "" and str(datas[i]["109"]) == text4:
                    res[str(num)] = datas[i]
                    num += 1
        except Exception as e:
            app_logger.log_error(e)
        return res

    def sortTableWidgetDispaly(self):
        try:
            text = self.text
            Partdisplay = self.displayselect_mode  # 不显示起飞航班
            # print(Partdisplay)
            tableWidgetDispalydataAll = {}
            if self.displayMode == "A" and (self.selectedbc == "0" or self.date=="4"):
                tableWidgetDispalydataAll = self.severpost_nomeassge("tableWidgetDispaly",selectedtime="%s" % self.selectedtime,date="%s"%self.date)["data"]
            elif self.displayMode == "B"and (self.selectedbc == "0" or self.date=="4"):
                tableWidgetDispalydataAll = self.severpost_nomeassge("tableWidgetDispaly2",selectedtime="%s" % self.selectedtime,date="%s"%self.date)["data"]
            elif self.displayMode == "A" and self.selectedbc == "1":
                tableWidgetDispalydataAll = self.severpost_nomeassge("tableWidgetDispalyRead",date="%s"%self.date)["data"]
            elif self.displayMode == "B"and self.selectedbc == "1":
                tableWidgetDispalydataAll = self.severpost_nomeassge("tableWidgetDispalyRead2",date="%s"%self.date)["data"]
            self.DispalydataAll=tableWidgetDispalydataAll
            self.sorttableWidgetDispalydata = {}
            num = 0
            if tableWidgetDispalydataAll != None:
                if text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6" and text != "T1T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata=self.checkStrsingle(tableWidgetDispalydataAll, text, "")
                elif text == "T1" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "", "1", "1", "1")
                elif text == "T2" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "", "2", "2", "2")
                elif text == "T2T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "2", "2", "1")
                elif text == "T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "1", "2", "1")
                elif text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6"  and text != "T1T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrsingle(tableWidgetDispalydataAll, text, "4")
                elif text == "T1" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "4", "1", "1", "1")
                elif text == "T2" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "4", "2", "2", "1")
                elif text == "T2T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "2", "2", "1")
                elif text == "T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "1", "2", "1")
                elif text == "" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkall(tableWidgetDispalydataAll, "4")
                elif text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6" and text != "T1T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrsingle(tableWidgetDispalydataAll, text, "1")
                elif text == "T1" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll3(tableWidgetDispalydataAll, "1", "1", "1", "1")
                elif text == "T2" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll3(tableWidgetDispalydataAll, "1", "2", "2", "1")
                elif text == "T2T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "2", "2", "1")
                elif text == "T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "1", "2", "1")
                elif text == "" and Partdisplay == "3":
                    for i in tableWidgetDispalydataAll.keys():
                        if tableWidgetDispalydataAll[i]["109"] == '1':
                            self.sorttableWidgetDispalydata[str(num)] = tableWidgetDispalydataAll[i]
                            num += 1
                else:
                    self.sorttableWidgetDispalydata = tableWidgetDispalydataAll

        except Exception as e:
            app_logger.log_error(e)

    def sortTableWidgetDispalyALL(self):
        try:
            if self.displayMode == "A" and (self.selectedbc == "0" or self.date=="4"):
                self.sorttableWidgetDispalydata = self.severpost_nomeassge("tableWidgetDispaly",selectedtime="%s" % self.selectedtime,date="%s"%self.date)["data"]
            elif self.displayMode == "B"and (self.selectedbc == "0" or self.date=="4"):
                self.sorttableWidgetDispalydata = self.severpost_nomeassge("tableWidgetDispaly2",selectedtime="%s" % self.selectedtime,date="%s"%self.date)["data"]
            elif self.displayMode == "A" and self.selectedbc == "1":
                self.sorttableWidgetDispalydata = self.severpost_nomeassge("tableWidgetDispalyRead",date="%s"%self.date)["data"]
            elif self.displayMode == "B"and self.selectedbc == "1":
                self.sorttableWidgetDispalydata = self.severpost_nomeassge("tableWidgetDispalyRead2",date="%s"%self.date)["data"]
        except Exception as e:
            app_logger.log_error(e)



    def SearchsortTableWidgetDispaly(self):
        try:
            text = self.text
            self.seversts = "1"
            Partdisplay = self.displayselect_mode  # 不显示起飞航班
            # print(Partdisplay)
            tableWidgetDispalydataAll = self.selectedbc

            self.sorttableWidgetDispalydata = {}
            num = 0
            if tableWidgetDispalydataAll != None:
                if text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6" and text != "T1T6"and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrsingle(tableWidgetDispalydataAll, text, "")
                elif text == "T1" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "", "1", "1", "1")
                elif text == "T2" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "", "2", "2", "1")
                elif text == "T2T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "2", "2", "1")
                elif text == "T6" and Partdisplay == "0":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "", "1", "2", "1")
                elif text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6" and text != "T1T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrsingle(tableWidgetDispalydataAll, text, "4")
                elif text == "T1" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "4", "1", "1", "1")
                elif text == "T2" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll(tableWidgetDispalydataAll, "4", "2", "2", "1")
                elif text == "T2T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "2", "2", "1")
                elif text == "T6" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll2(tableWidgetDispalydataAll, "4", "1", "2", "1")
                elif text == "" and Partdisplay == "1":
                    self.sorttableWidgetDispalydata = self.checkall(tableWidgetDispalydataAll,  "4")

                elif text != "" and text != "T1" and text != "T2" and text != "T6" and text != "T2T6" and text != "T1T6" and Partdisplay == "3":
                    for i in tableWidgetDispalydataAll.keys():
                        if str(text) in str(tableWidgetDispalydataAll[i]) and tableWidgetDispalydataAll[i]["109"] == '1':
                            self.sorttableWidgetDispalydata[str(num)] = tableWidgetDispalydataAll[i]
                            num += 1
                elif text == "T1" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll3(tableWidgetDispalydataAll, "1", "1", "1", "1")
                elif text == "T2" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll3(tableWidgetDispalydataAll, "1", "2", "2", "1")
                elif text == "T2T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "1", "1", "1")
                elif text == "T1T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "2", "2", "1")
                elif text == "T6" and Partdisplay == "3":
                    self.sorttableWidgetDispalydata = self.checkStrTerminalAll4(tableWidgetDispalydataAll, "1", "1", "2", "1")
                elif text == "" and Partdisplay == "3":
                    for i in tableWidgetDispalydataAll.keys():
                        if tableWidgetDispalydataAll[i]["109"] == '1':
                            self.sorttableWidgetDispalydata[str(num)] = tableWidgetDispalydataAll[i]
                            num += 1
                else:
                    self.sorttableWidgetDispalydata = tableWidgetDispalydataAll
        except Exception as e:
            app_logger.log_error(e)


    def sorttableWidgetDisplayChange(self):
        try:
            text = self.text
            logall = self.severpost_nomeassge("tableWidgetDisplayChange",
                                              selectedtime="%s" % self.selectedtime)["data"]
            self.sortlogchange = {}
            num = 0
            if text != "":
                for i in logall.keys():
                    if str(text) in str(logall[i]):
                        self.sortlogchange[str(num)] = logall[i]
                        num += 1
            else:
                self.sortlogchange = logall
        except Exception as e:
            app_logger.log_error(e)

    def sorttableWidgetPeopleDisplay(self):
        try:
            if self.displayselect_mode == "" or self.displayselect_mode == []:
                text = self.text
                self.peopleOnJob = [""]
                bc = self.selectedbc
                nowDaystr = self.selectedtime  # 选择的日期
                diplaylistall = self.severpost_nomeassge("qtPeopleLoad",
                                                         selectedtime="%s" % nowDaystr,
                                                         bc="%s" % bc )["data"]
                self.sortdiplaylist = {}
                num = 0
                if text != "":
                    for i in diplaylistall.keys():
                        if str(text) in str(diplaylistall[i]):
                            self.sortdiplaylist[str(num)] = diplaylistall[i]
                            num += 1
                else:
                    self.sortdiplaylist = diplaylistall
                for i in self.sortdiplaylist.keys():
                    self.peopleOnJob.append(self.sortdiplaylist[i]["姓名"])
            else:
                names = self.displayselect_mode
                text = self.text
                self.peopleOnJob = [""]
                bc = self.selectedbc
                nowDaystr = self.selectedtime  # 选择的日期
                diplaylistall = self.severpost_nomeassge("qtPeopleLoad",
                                                         selectedtime="%s" % nowDaystr,
                                                         bc="%s" % bc )["data"]
                self.sortdiplaylist = {}
                num = 0
                if text != "":
                    for i in diplaylistall.keys():
                        if str(text) in str(diplaylistall[i]):
                            for name in names:
                                if str(name) in str(diplaylistall[i]):
                                    self.sortdiplaylist[str(num)] = diplaylistall[i]
                                    num += 1
                else:
                    for i in diplaylistall.keys():
                        for name in names:
                            if str(name) in str(diplaylistall[i]):
                                self.sortdiplaylist[str(num)] = diplaylistall[i]
                                num += 1
                for i in self.sortdiplaylist.keys():
                    self.peopleOnJob.append(self.sortdiplaylist[i]["姓名"])
        except Exception as e:
            app_logger.log_error(e)

    def sorttableWidgetLOGDispaly(self):
        try:
            text = self.text
            logall = self.severpost_nomeassge("tableWidgetLOGDispaly",
                                              selectedtime="%s" % self.selectedtime)["data"]
            self.sortlog = {}
            num = 0
            if text != "":
                for i in logall.keys():
                    if str(text) in str(logall[i]):
                        self.sortlog[str(num)] = logall[i]
                        num += 1
            else:
                self.sortlog = logall
        except Exception as e:
            app_logger.log_error(e)


class MainWidget(QWidget, Ui_Form):
    LoginWidget_signal = QtCore.pyqtSignal(str)

    def __init__(self):
        super().__init__()
        try:
            # 新增：防抖定时器
            self.debounce_timer = QtCore.QTimer(self)
            self.debounce_timer.setSingleShot(True)
            self.debounce_timer.timeout.connect(self.debounced_search)
            self.debounce_delay = 300  # 防抖延迟时间（毫秒）

            self.displaySelectstr3 = "0"
            self.displaySelect_mode = "1"
            self.localip = None
            self.severupdatests = "0"
            self.localtoken = None
            self.searchpeoplestr = []
            self.sorttableWidgetDispalydata = {}
            self.sorttableWidgetDispalydataALL = {}
            self.sortdiplaylist = {}
            self.peopleOnJob = [""]
            self.loginSts = False
            self.amroLoginSts = False
            self.findSever = False
            self.FLIGHTonChange_text = ""
            self.threadpool = QThreadPool()
            self.setupUi(self)
            # self.show()
            self.loginWidget = loginWidget.LoginWidget()
            self.findServerWidget = FindServerWidget.findServerWidget()

            # self.amroLoginWidget = amroLoginWidget()
            if self.findSever:
                pass
                # if self.loginSts:
                #     self.show()
                # else:
                #     self.loginWidget.show()
            else:
                self.findServerWidget.show()

            self.findServerWidget.selectServer_signal.connect(self.setServer)

            # self.amroLoginWidget.amroLogin_signal.connect(self.displayMain)
            # data
        except Exception:
            pass

    def setServer(self, *args):
        try:
            self.ipinfo = args[0] + ':7162'
            self.clickrow = ""
            self.clickcolumn = ""
            # print(self.ipinfo)
            self.version = versionNumb
            self.findServerWidget.close()
            self.loginWidget.ipinfo = self.ipinfo
            self.loginWidget.login_signal.connect(self.displayMain)
            self.loginWidget.login_user.connect(self.setUser)
            checksts = 0
            # ip = "http://" + str(self.ipinfo) + "/static/remoteCheck2/"+self.version
            # res = requests.get(url=ip, timeout=180).json()
            res = api_fc.request_post_without_token('/static/remoteCheck2', checknumber=self.version )
            if res["返回值"] == "ok":
                checksts = 1
            if checksts == 1:
                if self.loginSts:
                    self.initDisplay()
                    self.show()
                else:
                    self.loginWidget.show()
            else:
                QMessageBox.warning(self, "提示", "有新版更新！请前往NAS共享平台[机务一队/天府机务分部/31准备组无纸化办公/1航班助手/软件]获取电子白板最新版本！！")
                self.close()
        except Exception:
            pass

    def judge_bc(self):
        try:
            nowDay = datetime.date.today().strftime("%Y%m%d")
            nowDay_1 = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
            nowDay_str2 = datetime.date.today().strftime("%Y-%m-%d")
            a_str = nowDay_str2 + " 04:30:00"
            b_str = nowDay_str2 + " 20:30:00"
            a = datetime.datetime.strptime(a_str, "%Y-%m-%d %H:%M:%S")
            b = datetime.datetime.strptime(b_str, "%Y-%m-%d %H:%M:%S")
            nowtime = datetime.datetime.now()
            if a < nowtime < b:
                self.selectedtime = nowDay
                self.selectedtime_bc = "A"
            elif b < nowtime:
                self.selectedtime = nowDay
                self.selectedtime_bc = "B"
            elif nowtime < a:
                self.selectedtime = nowDay_1
                self.selectedtime_bc = "B"
        except Exception:
            pass

    def initDisplay(self):
        try:
            self.oldjsondata = None
            self.cookie = None
            self.fl = None
            self.tts = QTextToSpeech()
            self.tts.setEngine('sapi')
            self.judge_bc()
            self.displayMode = "A"
            self.displayLabel = headerlabel0
            self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
            self.tableWidgetFlight.verticalHeader().setVisible(False)
            self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
            self.tableWidgetFlight.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
            self.tableWidgetFlight.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
            # self.lineEdit_phonenum.setText("")
            #self.checkBox.stateChanged.connect(self.displayChange)
            self.checkBox.setChecked(True)
            self.checkBox_2.stateChanged.connect(self.displaySelect2)
            self.checkBox_2.setChecked(True)
            self.checkBox_3.stateChanged.connect(self.displaySelect3)
            self.checkBox_3.setChecked(False)
            self.pushbutton_searchflight.clicked.connect(self.FLIGHTonChangeman)
            self.lineEdit_flight.textEdited[str].connect(lambda: self.changebackground())
            #self.lineEdit_flight.textChanged.connect(self.FLIGHTonChange)
            self.lineEdit_flight.textChanged.connect(self.on_search_text_changed)
            self.serchTimer = QTimer()
            self.serchTimer.start(150 * 1000)
            self.serchTimer.timeout.connect(self.QThreadSortTimer)
            self.updatecheck()
        except Exception:
            pass
    def on_search_text_changed(self):
        """文本变化时重置定时器"""
        self.debounce_timer.start(self.debounce_delay)

    def debounced_search(self):
        """实际触发搜索的方法"""
        self.FLIGHTonChange_text = self.lineEdit_flight.text()
        self.QThreadSortNow("search")

    def changebackground(self):
        try:
            FLIGHTonChange_text = self.lineEdit_flight.text()
            if FLIGHTonChange_text != "":
                self.lineEdit_flight.setStyleSheet("background-color:yellow;color:red;font-weight:bold")
            else:
                self.lineEdit_flight.setStyleSheet("background-color:white")
        except Exception:
            pass
    def FLIGHTonChange(self):
        try:
            self.FLIGHTonChange_text = self.lineEdit_flight.text()
            # print(self.FLIGHTonChange_text)
            self.QThreadSortNow("search")
        except Exception:
            pass
    def FLIGHTonChangeman(self):
        try:
            self.FLIGHTonChange_text = self.lineEdit_flight.text()
            # print(self.FLIGHTonChange_text)
            self.QThreadSortNow("main")
        except Exception:
            pass

    def updatecheck(self):
        try:
            # ip = "http://" + str(self.ipinfo) + "/static/updatecheck"
            # res = requests.get(url=ip, timeout=30).json()
            res = api_fc.request_get('/static/updatecheck')
            if res["返回值"] == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
                if self.severupdatests != "1":
                    self.severupdatests = "1"

            elif res["返回值"] == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet("background-color:yellow;red:white;border-radius:5px;padding:2px;font-weight:bold")

        except Exception:
            self.label_11.setText("已断开")
            self.label_11.setStyleSheet("background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")

    def displaySelect2(self):
        try:
            displaySelect = self.sender()
            if displaySelect.isChecked():
                self.displaySelectstr2 = "1"
                if self.loginSts == True:
                    if self.displaySelectstr3 == "1":
                        self.displaySelect_mode = "3"
                    else:
                        self.displaySelect_mode = "1"
                    self.QThreadSortNow("main")
            else:
                self.displaySelectstr2 = "0"
                self.displaySelect_mode = "0"
                if self.loginSts == True:
                    if self.displaySelectstr3 == "1":
                        self.checkBox_3.setChecked(False)
                    else:
                        self.QThreadSortNow("main")
        except Exception:
            pass

    def displaySelect3(self):
        try:
            displaySelect = self.sender()
            if displaySelect.isChecked():
                self.displaySelectstr3 = "1"
                self.displaySelect_mode = "3"
                if self.loginSts == True:
                    if self.displaySelectstr2 == "0":
                        self.checkBox_2.setChecked(True)
                    else:
                        self.QThreadSortNow("main")
            else:
                self.displaySelectstr3 = "0"
                if self.loginSts == True:
                    if self.displaySelectstr2 == "0":
                        self.displaySelect_mode = "0"
                    else:
                        self.displaySelect_mode = "1"
                    self.QThreadSortNow("main")
        except Exception:
            pass


    def displayMain(self, *args):
        try:
            if args[0]:
                self.initDisplay()
                self.loginSts = True
                self.loginWidget.close()
                self.show()
                self.QThreadSortNow("main")
        except Exception:
            pass

    def setUser(self, args):
        try:
            self.user = args[1]
            self.authority = args[3]
            self.label_username.setText(self.user)
        except Exception:
            pass


    def QThreadSortDispalyTimer(self, name, dict, dict2, seversts, displayMode):
        try:
            if name == "sortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel = headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                elif displayMode == "B":
                    self.displayLabel = headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                self.sorttableWidgetDispalydataALL={}
                self.sorttableWidgetDispalydataALL = dict
                self.tableWidgetDispaly()
                # print(self.sorttableWidgetDispalydata)

            if seversts == "0":
                self.severupdatests = "-"
                self.label_11.setText("已断开")
                self.label_11.setStyleSheet(
                    "background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet(
                    "background-color:yellow;color:red;border-radius:5px;padding:2px;font-weight:bold")
        except Exception:
            pass

    def QThreadSortDispalyNow(self, name, dict, dict2, seversts, displayMode):
        try:
            if name == "sortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel = headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                else:
                    self.displayLabel = headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                self.sorttableWidgetDispalydataALL = {}
                self.sorttableWidgetDispalydataALL = dict
                # print(self.sorttableWidgetDispalydata)
                self.tableWidgetDispaly()
            elif name == "SearchsortTableWidgetDispaly":
                if displayMode == "A":
                    self.displayLabel = headerlabel0
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)

                elif displayMode == "B":
                    self.displayLabel = headerlabel_B
                    self.tableWidgetFlight.setColumnCount(len(self.displayLabel))
                    self.tableWidgetFlight.verticalHeader().setVisible(False)
                    self.tableWidgetFlight.setHorizontalHeaderLabels(self.displayLabel)
                self.sorttableWidgetDispalydata = {}
                self.sorttableWidgetDispalydata = dict
                self.tableWidgetDispaly()
                # print(self.sorttableWidgetDispalydata)

            if seversts == "0":
                self.severupdatests = "-"
                self.label_11.setText("已断开")
                self.label_11.setStyleSheet(
                    "background-color:red;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "1":
                self.label_11.setText("正 常")
                self.label_11.setStyleSheet(
                    "background-color:green;color:white;border-radius:5px;padding:2px;font-weight:bold")
            elif seversts == "1" and self.severupdatests == "0":
                self.label_11.setText("未更新")
                self.label_11.setStyleSheet(
                    "background-color:yellow;color:red;border-radius:5px;padding:2px;font-weight:bold")
        except Exception:
            pass


    def QThreadSortTimer(self):
        try:

            if self.loginSts == True:
                # print("多线程刷新1")
                self.judge_bc()
                self.FLIGHTonChange_text = self.lineEdit_flight.text()
                th1 = QThread()
                self.sortTableWidgetDispalyThread1 = sortdisplaySever("sortTableWidgetDispaly", self.ipinfo,
                                                                      self.selectedtime, self.FLIGHTonChange_text,
                                                                      self.displayMode, "1", self.displaySelect_mode,
                                                                      th1)
                self.sortTableWidgetDispalyThread1.sortupdate.connect(self.QThreadSortDispalyTimer)
                self.sortTableWidgetDispalyThread1.moveToThread(th1)
                th1.started.connect(self.sortTableWidgetDispalyThread1.run)
                th1.start()
                self.updatecheck()
        except Exception:
            pass

    def QThreadSortNow(self, name):
        try:
            if "main" in str(name):
                # print(datetime.datetime.now())
                th11 = QThread()
                self.sortTableWidgetDispalyThread11 = sortdisplaySever("sortTableWidgetDispaly", self.ipinfo,
                                                                       self.selectedtime, self.FLIGHTonChange_text,
                                                                       self.displayMode, "1", self.displaySelect_mode,
                                                                       th11)
                try:
                    self.sortTableWidgetDispalyThread11.sortupdate.disconnect()
                except TypeError:
                    pass
                self.sortTableWidgetDispalyThread11.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sortTableWidgetDispalyThread11.moveToThread(th11)
                th11.started.connect(self.sortTableWidgetDispalyThread11.run)
                th11.start()
            elif "search" in str(name):
                # print(datetime.datetime.now())
                th111 = QThread()
                self.sortTableWidgetDispalyThread111 = sortdisplaySever("SearchsortTableWidgetDispaly", self.ipinfo,
                                                                        self.selectedtime, self.FLIGHTonChange_text,
                                                                        self.displayMode, self.sorttableWidgetDispalydataALL, self.displaySelect_mode,
                                                                        th111)
                self.sortTableWidgetDispalyThread111.sortupdate.connect(self.QThreadSortDispalyNow)
                self.sortTableWidgetDispalyThread111.moveToThread(th111)
                th111.started.connect(self.sortTableWidgetDispalyThread111.run)
                th111.start()

        except Exception:
            pass

    def enter_item_slot(self, item):
        try:
            self.tool_tip = item.text()
            # print("self.tool_tip:", self.tool_tip)
        except Exception:
            pass

    def tableWidgetDispaly(self):
        try:
            selftaxi = ["166", "166L", "166R", "167", "167L", "167R", "168", "169", "170", "171", "172", "173", "174",
                        "269", "270", "271", "272", "273", "274", "275", "287", "288", "601", "602", "603", "604",
                        "605", "606", "607", "607L", "607R"]  # 自滑位
            if self.sorttableWidgetDispalydata != "":
                # print("刷新开始")
                # dateNow=datetime.datetime.now()
                tableWidgetDispalydata = self.sorttableWidgetDispalydata
                col = len(self.displayLabel)
                self.tableWidgetFlight.setRowCount(len(tableWidgetDispalydata.keys()))
                for row in tableWidgetDispalydata.keys():
                    for colNum in range(0, col):
                        if colNum == 13:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                        elif colNum == 15:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                        elif colNum == 18:
                            if tableWidgetDispalydata[row][str(colNum)] in selftaxi and tableWidgetDispalydata[row][str(colNum)] != "":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("lightgreen"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))

                            elif tableWidgetDispalydata[row][str(colNum)] not in selftaxi or tableWidgetDispalydata[row][str(colNum)] == "":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                            font = QFont()
                            # font.setFamily("SimHei")
                            font.setFamily("Microsoft YaHei")
                            font.setBold(True)

                            self.tableWidgetFlight.item(int(row), colNum).setFont(font)
                        elif colNum == 19:
                            if tableWidgetDispalydata[row][str(colNum)] == "短停送" or tableWidgetDispalydata[row][str(colNum)] == "特后前送":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str("blue")))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)

                            else:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))

                        elif 19 < colNum < 31:
                            if "√" in tableWidgetDispalydata[row][str(colNum)] or tableWidgetDispalydata[row][str(colNum)] == "":
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)]).replace("*","")))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                            if tableWidgetDispalydata[row][str(colNum)] != "" and "√" not in tableWidgetDispalydata[row][str(colNum)]:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)]).replace("*","")))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                        elif colNum == 61:
                            if str(tableWidgetDispalydata[row][str(colNum)]) != "" and str(tableWidgetDispalydata[row][str(colNum)]) != None:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("red"))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)
                            else:
                                self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                                font = QFont()
                                font.setFamily("Microsoft YaHei")
                                font.setBold(True)
                                self.tableWidgetFlight.item(int(row), colNum).setFont(font)
                        elif colNum == 49:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                            if tableWidgetDispalydata[row][str(colNum)] != "":
                                for i in tableWidgetDispalydata[row][str(colNum)].split(","):
                                    if "√" not in i:
                                        self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                        self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                                        break
                                    else:
                                        self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                        self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                            else:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))
                        elif colNum == 51:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))
                            if tableWidgetDispalydata[row][str(colNum)] != "" and "√" not in tableWidgetDispalydata[row][str(colNum)]:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor("yellow"))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor("black"))
                            else:
                                self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                                self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))


                        elif 0 < colNum < 11:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(tableWidgetDispalydata[row][str(colNum)])))

                        elif colNum == 0:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem(str(int(row)+1)))

                        else:
                            self.tableWidgetFlight.setItem(int(row), colNum, QTableWidgetItem( str(tableWidgetDispalydata[row][str(colNum)])))

                        if colNum not in [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,49,51, 61]:
                            self.tableWidgetFlight.item(int(row), colNum).setBackground(QColor(str(tableWidgetDispalydata[row]["99"])))
                            self.tableWidgetFlight.item(int(row), colNum).setForeground(QColor(str(tableWidgetDispalydata[row]["101"])))

                        if colNum not in [4 , 6]:
                            self.tableWidgetFlight.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignCenter)
                        else:
                            self.tableWidgetFlight.item(int(row), colNum).setTextAlignment(Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignCenter)
                            self.tableWidgetFlight.setRowHeight(int(row), 35)

                        if self.displayMode == "A":
                            settips={0:"53",4:"62",49:"50",19:"47",11:"57",13:"57",15:"57",45:"45",61:"61",6:"17",38:"40",}
                            for key,value in settips.items():
                                if self.tableWidgetFlight.item(int(row), key):
                                    self.tableWidgetFlight.item(int(row), key).setToolTip("%s" % (str(tableWidgetDispalydata[row][str(value)])))
                        else:
                            self.tableWidgetFlight.item(int(row), 0).setToolTip("[%s，%s]" % ( str(tableWidgetDispalydata[row][str(col - 5)]),str(tableWidgetDispalydata[row][str(col - 4)])))
                            for ii in range (1,4):
                                self.tableWidgetFlight.item(int(row), ii).setToolTip("%s" % str(tableWidgetDispalydata[row][str(24)]))

                if self.displayMode == "A":
                    self.tableWidgetFlight.resizeColumnsToContents()
                    self.tableWidgetFlight.setWordWrap(True)
                    for i in range(col):
                        if i in [1,2,3,5,7,8,9,10,12,14,16,17,20,22,24,26,28,30,32,34,36,39,40,42,43,44,46,47,48,50,52,53,54,55,56,57,58,59,60,62,63,64,65]:
                            self.tableWidgetFlight.setColumnHidden(i, True)
                        else:
                            self.tableWidgetFlight.setColumnHidden(i, False)
                        if i in [21, 23, 25, 27, 29, 31]:
                            self.tableWidgetFlight.setColumnWidth(i, 70)
                        elif i in [45]:
                            self.tableWidgetFlight.setColumnWidth(i, 45)
                else:
                    for i in range(col):
                        if i in [col - 9, col - 11, col - 12,19,20,21,22,23,28,29,30,31]:
                            self.tableWidgetFlight.setColumnHidden(i, True)
                        else:
                            self.tableWidgetFlight.setColumnHidden(i, False)
                    self.tableWidgetFlight.resizeColumnsToContents()
                    self.tableWidgetFlight.setColumnWidth(10, 70)
                    self.tableWidgetFlight.setColumnWidth(11, 70)
                    self.tableWidgetFlight.setColumnWidth(12, 70)
                    self.tableWidgetFlight.setColumnWidth(13, 70)
                    self.tableWidgetFlight.setColumnWidth(14, 70)
                    self.tableWidgetFlight.setColumnWidth(15, 70)
                    self.tableWidgetFlight.setColumnWidth(22, 45)
        except Exception as e:
            app_logger.log_error(e)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mw = MainWidget()

    sys.exit(app.exec())
