#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: globalSlot.py
 @DateTime: 2025/4/8 10:25
 @SoftWare: PyCharm
 @Author  ：xsh
"""
from PyQt5 import Qt
from AppInterfaces.SingletonInterface import SingletonInterface
from AppInterfaces.GlobalInterface import GlobalInterface
from AppSettings.Settings import SIGNAL_CONNECTION_TYPE

class globalSlot(Qt.QObject, GlobalInterface, SingletonInterface):
    Locker: Qt.QMutex = Qt.QMutex()
    Application                 : (Qt.QApplication, Qt.QCoreApplication)
    StartScanningSignal         : Qt.pyqtSignal = Qt.pyqtSignal(object)
    WebServerReceivedSignal     : Qt.pyqtSignal = Qt.pyqtSignal(object)
    ClearWarningSignal          : Qt.pyqtSignal = Qt.pyqtSignal(object)
    DropSlideTableTraySignal    : Qt.pyqtSignal = Qt.pyqtSignal(object)
    TransmitSignal              : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ReceivedSignal              : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    StatusSignal                : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    WarningSignal               : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    MessageSignal               : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    LoggerSignal                : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    RequestSignal               : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    AppSignal                   : Qt.pyqtSignal = Qt.pyqtSignal(object, object, object)
    ApplicationSignal           : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraSignal                : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    WebServerReadSignal         : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    WebServerSendSignal         : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraUiSignal              : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CellImageSignal             : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ProcessSignal               : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ProcessFocusSignal          : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ImageSaveSignal             : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CallBackThreadSignal        : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraSlideAreaImageSignal  : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraPreviewImageSignal    : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraVideoStreamSignal     : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    CameraImageListSignal       : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    currentHitBotDataChanged    : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ClearImageListSignal        : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    ChangedScanningSlideSignal  : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    currentSlideStateChanged    : Qt.pyqtSignal = Qt.pyqtSignal(object, object, object)
    currentSlideLStateChanged   : Qt.pyqtSignal = Qt.pyqtSignal(object, object, object)
    currentSlideRStateChanged   : Qt.pyqtSignal = Qt.pyqtSignal(object, object, object)
    currentSlideCodeChanged     : Qt.pyqtSignal = Qt.pyqtSignal(object, object, object)
    InitCheckStatusSignal       : Qt.pyqtSignal = Qt.pyqtSignal(object, object)
    DropCurrentTraySignal       : Qt.pyqtSignal = Qt.pyqtSignal(object)
    SlideTableNotEmptySignal    : Qt.pyqtSignal = Qt.pyqtSignal()
    UiDropTrayCompleteSignal    : Qt.pyqtSignal = Qt.pyqtSignal(object)
    def __init__(self, parent: Qt.QObject = None):
        super(globalSlot, self).__init__(parent=parent)
        self.Initialization("globalSlot", self, parent)


    @classmethod
    def GetInstance(cls, *args, **kwargs) -> 'globalSlot':
        return super(globalSlot, cls).GetInstance(*args, **kwargs)


    def initValue(self):
        super(globalSlot, self).initValue()
        if not self.hasApplication():
            self.Application = None


    def initApplicationConnect(self, app: Qt.QApplication):
        self.Application = app
        if self.hasApplication():
            CONNECTION_TYPE: Qt.Qt.ConnectionType = Qt.Qt.ConnectionType(Qt.Qt.AutoConnection | Qt.Qt.UniqueConnection)
            self.Application.aboutToQuit.connect(slot=self.slot_ApplicationSignal, type=CONNECTION_TYPE)
        pass

    def slot_ApplicationSignal(self):

        import sys
        self.ApplicationSignal.emit("aboutToQuit", "aboutToQuit")
        Qt.QCoreApplication.processEvents(Qt.QEventLoop.AllEvents, 1000)
        # Qt.QCoreApplication.quit()
        # self.Application.quit()


    def hasApplication(self) -> bool:
        return hasattr(self, 'Application') and isinstance(self.Application, (Qt.QApplication, Qt.QCoreApplication))


AppSlot: globalSlot = globalSlot.GetInstance()