#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ControllerOperation.py
@Description：
@Author：XSH
@Time：2025/11/17 18:32
@Department：研发部
@Copyright：©2025 乐辰生物
"""
import sys
import os
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 ControllerOperation(Qt.QWidget, UiInterface):
    InitButton              : Qt.QPushButton                #
    SafeButton              : Qt.QPushButton                #
    LowScanningSlide        : Qt.QPushButton                #
    HigScanningSlide        : Qt.QPushButton                #
    ScanningChamber         : Qt.QPushButton                #
    ScanningTray            : Qt.QPushButton                #
    CheckChamberButton      : Qt.QPushButton                #
    CheckTrayButton         : Qt.QPushButton                #
    PickChamberTrayButton   : Qt.QPushButton                #
    DropChamberTrayButton   : Qt.QPushButton                #
    EmptyHookReturnButton   : Qt.QPushButton                #
    QuitPLCLoopButton       : Qt.QPushButton                #


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

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

    def initValue(self):
        super(ControllerOperation, self).initValue()
        self.initInitButton              ()
        self.initSafeButton              ()
        self.initLowScanningSlide        ()
        self.initHigScanningSlide        ()
        self.initScanningChamber         ()
        self.initScanningTray            ()
        self.initCheckChamberButton      ()
        self.initCheckTrayButton         ()
        self.initPickChamberTrayButton   ()
        self.initDropChamberTrayButton   ()
        self.initEmptyHookReturnButton   ()
        self.initQuitPLCLoopButton       ()

    def initProperty(self):
        super(ControllerOperation, self).initProperty()
        self.InitButton              .setText('初始化仪器　　')
        self.SafeButton              .setText('移动到初始位置')
        self.LowScanningSlide        .setText('低倍物镜扫描　')
        self.HigScanningSlide        .setText('高倍物镜扫描　')
        self.ScanningChamber         .setText('扫描全部片仓　')
        self.ScanningTray            .setText('扫描指定托盘　')
        self.CheckChamberButton      .setText('　检测片仓　　')
        self.CheckTrayButton         .setText('检测指定托盘　')
        self.PickChamberTrayButton   .setText('　片仓取片　　')
        self.DropChamberTrayButton   .setText('　片仓放片　　')
        self.EmptyHookReturnButton   .setText('　空挂返回　　')
        self.QuitPLCLoopButton       .setText('结束取放片动作')

        self.InitButton              .setFixedHeight(40)
        self.SafeButton              .setFixedHeight(40)
        self.LowScanningSlide        .setFixedHeight(40)
        self.HigScanningSlide        .setFixedHeight(40)
        self.ScanningChamber         .setFixedHeight(40)
        self.ScanningTray            .setFixedHeight(40)
        self.CheckChamberButton      .setFixedHeight(40)
        self.CheckTrayButton         .setFixedHeight(40)
        self.PickChamberTrayButton   .setFixedHeight(40)
        self.DropChamberTrayButton   .setFixedHeight(40)
        self.EmptyHookReturnButton   .setFixedHeight(40)
        self.QuitPLCLoopButton       .setFixedHeight(40)


    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        m_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()

        m_layout.setSpacing(1)
        m_layout.setContentsMargins(10, 2, 10, 2)

        row1_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row2_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row3_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()

        row1_layout.setSpacing(1)
        row1_layout.setContentsMargins(10, 2, 10, 2)

        row2_layout.setSpacing(1)
        row2_layout.setContentsMargins(10, 2, 10, 2)

        row3_layout.setSpacing(1)
        row3_layout.setContentsMargins(10, 2, 10, 2)
        row1_layout.addWidget(self.InitButton              )
        row1_layout.addWidget(self.SafeButton              )
        row1_layout.addWidget(self.CheckChamberButton      )
        row1_layout.addWidget(self.CheckTrayButton         )

        row2_layout.addWidget(self.ScanningChamber         )
        row2_layout.addWidget(self.ScanningTray            )
        row2_layout.addWidget(self.LowScanningSlide        )
        row2_layout.addWidget(self.HigScanningSlide        )

        row3_layout.addWidget(self.PickChamberTrayButton   )
        row3_layout.addWidget(self.DropChamberTrayButton   )
        row3_layout.addWidget(self.EmptyHookReturnButton   )
        row3_layout.addWidget(self.QuitPLCLoopButton       )


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

    def initInitButton              (self):
        if not self.hasInitButton              :
            self.InitButton               = Qt.QPushButton()

    def initSafeButton              (self):
        if not self.hasSafeButton              :
            self.SafeButton               = Qt.QPushButton()

    def initLowScanningSlide        (self):
        if not self.hasLowScanningSlide        :
            self.LowScanningSlide         = Qt.QPushButton()

    def initHigScanningSlide        (self):
        if not self.hasHigScanningSlide        :
            self.HigScanningSlide         = Qt.QPushButton()

    def initScanningChamber         (self):
        if not self.hasScanningChamber         :
            self.ScanningChamber          = Qt.QPushButton()

    def initScanningTray            (self):
        if not self.hasScanningTray            :
            self.ScanningTray             = Qt.QPushButton()

    def initCheckChamberButton      (self):
        if not self.hasCheckChamberButton      :
            self.CheckChamberButton       = Qt.QPushButton()

    def initCheckTrayButton         (self):
        if not self.hasCheckTrayButton         :
            self.CheckTrayButton          = Qt.QPushButton()

    def initPickChamberTrayButton   (self):
        if not self.hasPickChamberTrayButton   :
            self.PickChamberTrayButton    = Qt.QPushButton()

    def initDropChamberTrayButton   (self):
        if not self.hasDropChamberTrayButton   :
            self.DropChamberTrayButton    = Qt.QPushButton()

    def initEmptyHookReturnButton   (self):
        if not self.hasEmptyHookReturnButton   :
            self.EmptyHookReturnButton    = Qt.QPushButton()

    def initQuitPLCLoopButton       (self):
        if not self.hasQuitPLCLoopButton       :
            self.QuitPLCLoopButton        = Qt.QPushButton()











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

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

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

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

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

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

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

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

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

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

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

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

