#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：MicroscopeController.py
@Description：
@Author：XSH
@Time：2025/11/18 9:32
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                      import Qt
from AppSettings.Settings       import *
from AppInterfaces.utils        import *
from AppCore.Levels             import *
from AppUtils.UiUtils           import UiUtils
from AppUtils.utils                     import *
from AppInterfaces.UiInterface          import UiInterface


class MicroscopeController(Qt.QWidget, UiInterface):
    ReadObjective   : Qt.QPushButton       #            物镜类型
    EditObjective   : Qt.QSpinBox          #
    SendObjective   : Qt.QPushButton       #            设置物镜
    ReadPosition    : Qt.QPushButton       #            当前位置
    EditPosition    : Qt.QDoubleSpinBox    #
    SendPosition    : Qt.QPushButton       #            移动位置
    ReadLAMP        : Qt.QPushButton       #            光源强度
    EditLAMP        : Qt.QDoubleSpinBox    #
    SendLAMP        : Qt.QPushButton       #            设置光源
    ReadAPBL        : Qt.QPushButton       #            视场光阑
    EditAPBL        : Qt.QDoubleSpinBox    #
    SendAPBL        : Qt.QPushButton       #            设置光阑
    ReadLFBL        : Qt.QPushButton       #            孔径光阑
    EditLFBL        : Qt.QDoubleSpinBox    #
    SendLFBL        : Qt.QPushButton       #            设置光阑
    InitButton      : Qt.QPushButton       #            连接仪器
    UnInitButton    : Qt.QPushButton       #            断开仪器
    OriginButton    : Qt.QPushButton       #            仪器归零


    def __init__(self, parent: Qt.QWidget = None):
        super(MicroscopeController, self).__init__(parent=parent)
        self.Initialization('MicroscopeController', self, parent)
        self.initWidgetStyle()

    def initWidgetStyle(self):
        from AppUtils.UiUtils import UiUtils
        self.setStyleSheet(UiUtils.getTransparentStyle())

    def initValue(self):
        super(MicroscopeController, self).initValue()
        self.initReadObjective   ()
        self.initEditObjective   ()
        self.initSendObjective   ()
        self.initReadPosition    ()
        self.initEditPosition    ()
        self.initSendPosition    ()
        self.initReadLAMP        ()
        self.initEditLAMP        ()
        self.initSendLAMP        ()
        self.initReadAPBL        ()
        self.initEditAPBL        ()
        self.initSendAPBL        ()
        self.initInitButton      ()
        self.initUnInitButton    ()
        self.initOriginButton    ()

    def initProperty(self):
        super(MicroscopeController, self).initProperty()
        self.ReadObjective   .setText('物镜类型')
        self.SendObjective   .setText('转换物镜')
        self.ReadPosition    .setText('当前位置')
        self.SendPosition    .setText('移动位置')
        self.ReadLAMP        .setText('光源强度')
        self.SendLAMP        .setText('设置光源')
        self.ReadAPBL        .setText('视场光阑')
        self.SendAPBL        .setText('设置光阑')
        self.InitButton      .setText('连接显微镜')
        self.UnInitButton    .setText('断开显微镜')
        self.OriginButton    .setText('显微镜归零')
        self.EditObjective   .setRange(1, 7)
        self.EditPosition    .setRange(0.0, 25000000.0)
        self.EditLAMP        .setRange(0.0, 100.0)
        self.EditAPBL        .setRange(0.0, 100.0)

        self.ReadObjective   .setFixedHeight(40)
        self.SendObjective   .setFixedHeight(40)
        self.ReadPosition    .setFixedHeight(40)
        self.SendPosition    .setFixedHeight(40)
        self.ReadLAMP        .setFixedHeight(40)
        self.SendLAMP        .setFixedHeight(40)
        self.ReadAPBL        .setFixedHeight(40)
        self.SendAPBL        .setFixedHeight(40)
        self.InitButton      .setFixedHeight(40)
        self.UnInitButton    .setFixedHeight(40)
        self.OriginButton    .setFixedHeight(40)
        self.EditObjective   .setFixedHeight(40)
        self.EditPosition    .setFixedHeight(40)
        self.EditLAMP        .setFixedHeight(40)
        self.EditAPBL        .setFixedHeight(40)


    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        m_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        m_layout.setSpacing(1)
        m_layout.setContentsMargins(1, 1, 1, 1)

        row1_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row1_layout.setSpacing(1)
        row1_layout.setContentsMargins(1, 1, 1, 1)

        row2_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row2_layout.setSpacing(1)
        row2_layout.setContentsMargins(1, 1, 1, 1)

        row3_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row3_layout.setSpacing(1)
        row3_layout.setContentsMargins(1, 1, 1, 1)

        row1_layout.addWidget(self.ReadObjective   , 1)
        row1_layout.addWidget(self.EditObjective   , 1)
        row1_layout.addWidget(self.SendObjective   , 1)

        row1_layout.addWidget(self.ReadPosition    , 1)
        row1_layout.addWidget(self.EditPosition    , 1)
        row1_layout.addWidget(self.SendPosition    , 1)

        row2_layout.addWidget(self.ReadLAMP        , 1)
        row2_layout.addWidget(self.EditLAMP        , 1)
        row2_layout.addWidget(self.SendLAMP        , 1)

        row2_layout.addWidget(self.ReadAPBL        , 1)
        row2_layout.addWidget(self.EditAPBL        , 1)
        row2_layout.addWidget(self.SendAPBL        , 1)

        row3_layout.addWidget(self.InitButton      , 1)
        row3_layout.addWidget(self.UnInitButton    , 1)
        row3_layout.addWidget(self.OriginButton    , 1)

        m_layout.addLayout(row1_layout)
        m_layout.addLayout(row2_layout)
        m_layout.addLayout(row3_layout)
        self.setLayout(m_layout)





    def initReadObjective (self):
        if not self.hasReadObjective:
            self.ReadObjective = Qt.QPushButton       ()

    def initEditObjective (self):
        if not self.hasEditObjective:
            self.EditObjective = Qt.QSpinBox          ()

    def initSendObjective (self):
        if not self.hasSendObjective:
            self.SendObjective = Qt.QPushButton          ()

    def initReadPosition  (self):
        if not self.hasReadPosition :
            self.ReadPosition  = Qt.QPushButton       ()

    def initEditPosition  (self):
        if not self.hasEditPosition :
            self.EditPosition  = Qt.QDoubleSpinBox    ()

    def initSendPosition  (self):
        if not self.hasSendPosition :
            self.SendPosition  = Qt.QPushButton    ()

    def initReadLAMP      (self):
        if not self.hasReadLAMP     :
            self.ReadLAMP      = Qt.QPushButton       ()

    def initEditLAMP      (self):
        if not self.hasEditLAMP     :
            self.EditLAMP      = Qt.QDoubleSpinBox    ()

    def initSendLAMP      (self):
        if not self.hasSendLAMP     :
            self.SendLAMP      = Qt.QPushButton    ()

    def initReadAPBL      (self):
        if not self.hasReadAPBL     :
            self.ReadAPBL      = Qt.QPushButton       ()

    def initEditAPBL      (self):
        if not self.hasEditAPBL     :
            self.EditAPBL      = Qt.QDoubleSpinBox    ()

    def initSendAPBL      (self):
        if not self.hasSendAPBL     :
            self.SendAPBL      = Qt.QPushButton    ()

    def initReadLFBL      (self):
        if not self.hasReadLFBL     :
            self.ReadLFBL      = Qt.QPushButton       ()

    def initEditLFBL      (self):
        if not self.hasEditLFBL     :
            self.EditLFBL      = Qt.QDoubleSpinBox    ()

    def initSendLFBL      (self):
        if not self.hasSendLFBL     :
            self.SendLFBL      = Qt.QPushButton    ()

    def initInitButton      (self):
        if not self.hasInitButton      :
            self.InitButton       = Qt.QPushButton()
    def initUnInitButton    (self):
        if not self.hasUnInitButton    :
            self.UnInitButton     = Qt.QPushButton()
    def initOriginButton    (self):
        if not self.hasOriginButton    :
            self.OriginButton     = Qt.QPushButton()
    @property
    def hasReadObjective (self) -> bool:
        return hasattr(self, 'ReadObjective'  ) and isinstance(self.ReadObjective, Qt.QPushButton    )

    @property
    def hasEditObjective (self) -> bool:
        return hasattr(self, 'EditObjective'  ) and isinstance(self.EditObjective, Qt.QSpinBox       )

    @property
    def hasSendObjective (self) -> bool:
        return hasattr(self, 'SendObjective'  ) and isinstance(self.SendObjective, Qt.QSpinBox       )

    @property
    def hasReadPosition  (self) -> bool:
        return hasattr(self, 'ReadPosition'   ) and isinstance(self.ReadPosition , Qt.QPushButton    )

    @property
    def hasEditPosition  (self) -> bool:
        return hasattr(self, 'EditPosition'   ) and isinstance(self.EditPosition , Qt.QDoubleSpinBox )

    @property
    def hasSendPosition  (self) -> bool:
        return hasattr(self, 'SendPosition'   ) and isinstance(self.SendPosition , Qt.QDoubleSpinBox )

    @property
    def hasReadLAMP      (self) -> bool:
        return hasattr(self, 'ReadLAMP'       ) and isinstance(self.ReadLAMP     , Qt.QPushButton    )

    @property
    def hasEditLAMP      (self) -> bool:
        return hasattr(self, 'EditLAMP'       ) and isinstance(self.EditLAMP     , Qt.QDoubleSpinBox )

    @property
    def hasSendLAMP      (self) -> bool:
        return hasattr(self, 'SendLAMP'       ) and isinstance(self.SendLAMP     , Qt.QDoubleSpinBox )

    @property
    def hasReadAPBL      (self) -> bool:
        return hasattr(self, 'ReadAPBL'       ) and isinstance(self.ReadAPBL     , Qt.QPushButton    )

    @property
    def hasEditAPBL      (self) -> bool:
        return hasattr(self, 'EditAPBL'       ) and isinstance(self.EditAPBL     , Qt.QDoubleSpinBox )

    @property
    def hasSendAPBL      (self) -> bool:
        return hasattr(self, 'SendAPBL'       ) and isinstance(self.SendAPBL     , Qt.QDoubleSpinBox )

    @property
    def hasReadLFBL      (self) -> bool:
        return hasattr(self, 'ReadLFBL'       ) and isinstance(self.ReadLFBL     , Qt.QPushButton    )

    @property
    def hasEditLFBL      (self) -> bool:
        return hasattr(self, 'EditLFBL'       ) and isinstance(self.EditLFBL     , Qt.QDoubleSpinBox )

    @property
    def hasSendLFBL      (self) -> bool:
        return hasattr(self, 'SendLFBL'       ) and isinstance(self.SendLFBL     , Qt.QDoubleSpinBox )

    @property
    def hasInitButton      (self) -> bool:
        return hasattr(self, 'InitButton') and isinstance(self.InitButton      , Qt.QPushButton)

    @property
    def hasUnInitButton    (self) -> bool:
        return hasattr(self, 'UnInitButton') and isinstance(self.UnInitButton    , Qt.QPushButton)

    @property
    def hasOriginButton    (self) -> bool:
        return hasattr(self, 'OriginButton') and isinstance(self.OriginButton    , Qt.QPushButton)


