#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：AppEventBusPool.py
@Description：
@Author：XSH
@Time：2025/11/15 11:54
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from AppInterfaces.utils                            import *
from AppUtils.utils                                 import *
from AppCore.Requests                               import *
from AppCore.Levels                                 import *
from AppInterfaces.EventInterfaces                  import AppEventInterface    #
from AppInterfaces.EventInterfaces                  import EventBusInterface    #



class AppEventBusPool(Qt.QObject, EventBusInterface, SingletonInterface):
    Locker: Qt.QMutex = Qt.QMutex()

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

    def __init__(self, parent: Qt.QObject = None):
        super(AppEventBusPool, self).__init__(parent=parent)
        self.Initialization('DataOnlyDrawPool', self, parent)
        self.Mode = EventLevel.OnlyDrawMode


    def initValue(self):
        super(AppEventBusPool, self).initValue()
        self.initPools          ()


    def initConnect(self):
        super(AppEventBusPool, self).initConnect()
        TYPE: Qt.Qt.ConnectionType  = Qt.Qt.ConnectionType(Qt.Qt.UniqueConnection | Qt.Qt.AutoConnection)
        AppSlot.ApplicationSignal.connect(slot=self.SlotApplicationSignal, type=TYPE)

    def StartFocusing(self, isShowFocusing: bool = True, **args):
        self.initPools()
        self.Start()


    def StopFocusing(self, isShowFocusing: bool = True, **args):
        self.delePools      ()

    def initUiEvent                         (self):
        if not self.hasUiEvent:
            from AppBackEnd.BackEndEventBus.OnlyDrawPool import OnlyDrawPool  #
            self.UiEvent = OnlyDrawPool.GetInstance()


    def initWebEvent                        (self):
        if not self.hasWebEvent:
            from AppBackEnd.BackEndEventBus.WebSocketPool import WebSocketPool  #
            self.WebEvent = WebSocketPool.GetInstance()


    def initFocusing                        (self):
        if not self.hasFocusing:
            from AppBackEnd.BackEndEventBus.SlideFocusingPool import SlideFocusingPool  #
            self.Focusing = SlideFocusingPool.GetInstance()


    def initScanning                        (self):
        if not self.hasScanning:
            from AppBackEnd.BackEndEventBus.SlideScanningPool import SlideScanningPool  #
            self.Scanning = SlideScanningPool.GetInstance()


    def initCameraScanning                  (self):
        if not self.hasCameraScanning:
            from AppBackEnd.BackEndEventBus.CameraScanningPool import CameraScanningPool  #
            self.CameraScanning = CameraScanningPool.GetInstance()


    def initCameraFocusing                  (self):
        if not self.hasCameraFocusing:
            from AppBackEnd.BackEndEventBus.CameraFocusingPool import CameraFocusingPool  #
            self.CameraFocusing = CameraFocusingPool.GetInstance()


    def initWebServerEvent                  (self):
        if not self.hasWebServerEvent:
            from AppBackEnd.BackEndEventBus.WebServerPool import WebServerPool  #
            self.WebServerEvent = WebServerPool.GetInstance()


    def initCellFocusing                    (self):
        if not self.hasCellFocusing:
            from AppBackEnd.BackEndEventBus.CellFocusingPool import CellFocusingPool  #
            self.CellFocusing = CellFocusingPool.GetInstance()