#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ActionControllerWidget.py
@Description：
@Author：XSH
@Time：2025/11/17 19:43
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                              import Qt
from AppSettings.Settings               import *
from AppCore.Levels                     import *
from AppUtils.UiUtils                   import UiUtils
from AppUtils.utils                     import *
from AppInterfaces.UiInterface          import UiInterface
from AppInterfaces.Interfaces           import *
from AppBackEnd.AppBusinessInterface    import AppBusinessInterface
from AppHeadEnd.ControllerFrames.ControlFrameInterface  import ControlFrameInterface
from AppHeadEnd.ControllerFrames.ActionController import ActionController
class ActionControllerWidget(Qt.QScrollArea, ControlFrameInterface, SingletonInterface):
    AreaFrame: ActionController
    Locker: Qt.QMutex = Qt.QMutex()

    @classmethod
    def GetInstance(cls, business: AppBusinessInterface, parent: Qt.QObject = None, *args) -> 'ActionControllerWidget':
        return  super(ActionControllerWidget, cls).GetInstance(*args, **{'business': business, 'parent': parent})


    def closeEvent(self, ev: Qt.QCloseEvent) -> None:
        ev.ignore()
        self.hide()

    def __init__(self, business: AppBusinessInterface, parent: Qt.QObject = None):
        super(ActionControllerWidget, self).__init__(parent=parent)
        self.Business = business if isinstance(business, AppBusinessInterface) else None
        self.Initialization('扫描调试工具', self, parent)
        self.initWidgetStyle()
        self.initWindowIcon()


    def loadWindowIcon(self):
        if not self.has_WindowIcon:
            import sys
            info: Qt.QFileInfo = Qt.QFileInfo(f'{Qt.QFileInfo(sys.argv[0]).absolutePath()}/Resource/Icon/showUi.png')
            self.WindowIcon = Qt.QIcon(Qt.QPixmap(info.absoluteFilePath()))

    def initValue(self):
        super(ActionControllerWidget, self).initValue()
        self.initBusiness()
        self.initAreaFrame()

    def initProperty(self):
        super(ActionControllerWidget, self).initProperty()
        self.setFixedSize(1920, 1000)

    def initLayouts(self):
        if self.hasWindowLayouts:
            return

        main_layout: Qt.QGridLayout = Qt.QGridLayout()
        main_layout.setSpacing(1)
        main_layout.setContentsMargins(5, 5, 20, 20)
        main_layout.addWidget(self.AreaFrame)
        self.setLayout(main_layout)
        self.setWidget(self.AreaFrame)

    def initAreaFrame(self):
        self.initBusiness()
        if not self.hasAreaFrame:
            self.AreaFrame = ActionController(self.business)

    @property
    def hasAreaFrame(self) -> bool:
        return hasattr(self, 'AreaFrame') and isinstance(self.AreaFrame, ActionController)

    @property
    def area_frame(self) -> ActionController:
        return None if not self.hasAreaFrame else self.AreaFrame