import base64
import ctypes
import sys

from PyQt6.QtCore import QByteArray
from PyQt6.QtCore import QTimer
from PyQt6.QtGui import QIcon , QPixmap
from PyQt6.QtWidgets import *

from Functions.DisplayQTMain import MainWidget

ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
from Functions.apiFunction import api_fc
class MenuDemo(QMainWindow):
    def __init__(self, parent=None):
        super(MenuDemo, self).__init__(parent)
        # 从Base64创建图标
        icon_base64 = """
        [encoded data, 22612 characters]
        """
        icon_data = base64.b64decode(icon_base64)
        pixmap = QPixmap()
        pixmap.loadFromData(QByteArray(icon_data))
        icon = QIcon(pixmap)
        self.setWindowTitle('天府机务分部航班电子化平台')
        self.resize(1400, 900)  # 宽×高
        self.setMinimumSize(1400, 900)
        self.setWindowIcon(icon)
        # 最小窗口尺寸
        # self.setMaximumSize(2000, 1000)  # 最大窗口尺寸
        self.child = MainWidget()
        self.setCentralWidget(self.child)
        #print(self.child.loginSts)
        self.child.loginWidget.pushButton.clicked.connect(self.showChild)
    def remoteCheck(self):
        # ip = "http://" + str(self.child.ipinfo) + "/static/remoteCheck2/"+self.child.version
        # res = requests.get(url=ip, timeout=180).json()
        res = api_fc.request_post_without_token('/static/remoteCheck2', checknumber=self.child.version)
        if res["返回值"] != "ok":
            QMessageBox.warning(self, "提示", "有新版更新！请前往NAS共享平台[机务一队/天府机务分部/31准备组无纸化办公/1航班助手/软件]获取【最新版版本号:%s】！！"%res["返回值"])
            self.close()

    def showChild(self):
        if self.child.loginSts == True:
            self.show()
            self.serchTimer = QTimer()
            self.serchTimer.start(3600 * 1000)
            self.serchTimer.timeout.connect(self.remoteCheck)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = MenuDemo()
    #demo.show()
    sys.exit(app.exec())