#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ManipulatorWidget.py
@Description：
@Author：XSH
@Time：2025/11/17 10:30
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                              import Qt
from AppSettings.Settings               import *
from AppCore.Levels                     import *
from AppUtils.UiUtils                   import UiUtils
from AppInterfaces.UiInterface          import UiInterface, AppUiProperty, AppUtils, AppConvert
from AppInterfaces.ReaderInterfaces     import *
from AppInterfaces.ImplInterfaces       import *
from AppBackEnd.AppBusinessInterface    import AppBusinessInterface
from AppHeadEnd.ControllerViews.ManipulatorController   import ManipulatorController   #
from AppHeadEnd.ControllerViews.HookController          import HookController          #
from AppHeadEnd.ControllerViews.CameraController        import CameraController        #
from AppHeadEnd.ControllerFrames.ManipulatorFrame       import ManipulatorFrame
from AppHeadEnd.ControllerFrames.ControlFrameInterface  import ControlFrameInterface

class ManipulatorWidget(Qt.QScrollArea, ControlFrameInterface):
    Manipulator: ManipulatorFrame

    def __init__(self, business: AppBusinessInterface, parent: Qt.QObject = None):
        super(ManipulatorWidget, self).__init__(parent=parent)
        self.Business = business if isinstance(business, AppBusinessInterface) else None
        self.Initialization('ManipulatorWidget', self, parent)
        self.initWidgetStyle()

    def initValue(self):
        super(ManipulatorWidget, self).initValue()
        self.initManipulatorFrame()

    def initProperty(self):
        super(ManipulatorWidget, self).initProperty()
        self.setFixedSize(1440, 900)

    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.Manipulator)
        self.setLayout(main_layout)
        self.setWidget(self.Manipulator)


    def initManipulatorFrame(self):
        if not self.hasManipulator:
            self.initBusiness()
            self.Manipulator = ManipulatorFrame(self.business, self)

    @property
    def hasManipulator(self) -> bool:
        return hasattr(self, 'Manipulator') and isinstance(self.Manipulator, ManipulatorFrame)

    @property
    def manipulator(self) -> ManipulatorFrame:
        return None if not self.hasManipulator else self.Manipulator


