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


class MainOperationView(Qt.QWidget, UiInterface):
    InitButton          : Qt.QPushButton    # 初始仪器
    ClearErrorButton    : Qt.QPushButton    # 清空告警
    OilSwitchButton     : Qt.QPushButton    # 油泵开关
    OilSwitchStatus     : Qt.QLabel         # 油泵状态
    YouTubeButton       : Qt.QPushButton    # 油管状态
    YouTubeStatus       : Qt.QLabel         # 油管状态
    ChamberButton       : Qt.QPushButton    # 片仓序号
    EditChamberNumber   : Qt.QSpinBox       # 片仓序号
    PickTrayButton      : Qt.QPushButton    # 取片动作
    DropTrayButton      : Qt.QPushButton    # 放片动作
    ControllerButton    : Qt.QPushButton    # 调试界面
    StartButton         : Qt.QPushButton    # 开始扫描
    PauseButton         : Qt.QPushButton    # 暂停扫描
    JumpButton          : Qt.QPushButton    # 跳过扫描
    StopButton          : Qt.QPushButton    # 停止扫描

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



    def initValue(self):
        super(MainOperationView, self).initValue()
        self.initInitButton          ()
        self.initClearErrorButton    ()
        self.initOilSwitchButton     ()
        self.initOilSwitchStatus     ()
        self.initYouTubeButton       ()
        self.initYouTubeStatus       ()
        self.initChamberButton       ()
        self.initEditChamberNumber   ()
        self.initPickTrayButton      ()
        self.initDropTrayButton      ()
        self.initControllerButton    ()
        self.initStartButton         ()
        self.initPauseButton         ()
        self.initStopButton          ()
        self.initJumpButton          ()


    def setOilSwitchStatus(self, enable: (int, bool)):
        if not self.hasOilSwitchStatus:
            return
        UiUtils.setColorStyle(self.OilSwitchStatus, enable)

    def setYouTubeStatus(self, enable: (int, bool)):
        if not self.hasYouTubeStatus:
            return
        UiUtils.setColorStyle(self.YouTubeStatus, enable)


    def initProperty(self):
        super(MainOperationView, self).initProperty()
        self.InitButton          .setText('初始仪器')
        self.ClearErrorButton    .setText('清空告警')
        self.OilSwitchButton     .setText('油泵开关')
        self.ChamberButton       .setText('片仓序号')
        self.PickTrayButton      .setText('取片动作')
        self.DropTrayButton      .setText('放片动作')
        self.StartButton         .setText('开始扫描')
        self.PauseButton         .setText('暂停扫描')
        self.StopButton          .setText('停止扫描')
        self.YouTubeButton       .setText('油管状态')
        self.ControllerButton    .setText('调试界面')
        self.JumpButton          .setText('跳过扫描')
        self.InitButton          .setStyleSheet(UiUtils.getButtonStyle())
        self.ClearErrorButton    .setStyleSheet(UiUtils.getButtonStyle())
        self.OilSwitchButton     .setStyleSheet(UiUtils.getButtonStyle())
        self.ChamberButton       .setStyleSheet(UiUtils.getButtonStyle())
        self.EditChamberNumber   .setStyleSheet(UiUtils.getButtonStyle())
        self.PickTrayButton      .setStyleSheet(UiUtils.getButtonStyle())
        self.DropTrayButton      .setStyleSheet(UiUtils.getButtonStyle())
        self.StartButton         .setStyleSheet(UiUtils.getButtonStyle())
        self.PauseButton         .setStyleSheet(UiUtils.getButtonStyle())
        self.StopButton          .setStyleSheet(UiUtils.getButtonStyle())
        self.YouTubeButton       .setStyleSheet(UiUtils.getButtonStyle())
        self.ControllerButton    .setStyleSheet(UiUtils.getButtonStyle())
        self.JumpButton          .setStyleSheet(UiUtils.getButtonStyle())


        self.EditChamberNumber.setRange(1, 24)
        self.EditChamberNumber.setSingleStep(1)

        self.JumpButton          .setFixedHeight(40)
        self.InitButton          .setFixedHeight(40)
        self.ClearErrorButton    .setFixedHeight(40)
        self.OilSwitchButton     .setFixedHeight(40)
        self.OilSwitchStatus     .setFixedHeight(40)
        self.ChamberButton       .setFixedHeight(40)
        self.EditChamberNumber   .setFixedHeight(40)
        self.PickTrayButton      .setFixedHeight(40)
        self.DropTrayButton      .setFixedHeight(40)
        self.StartButton         .setFixedHeight(40)
        self.PauseButton         .setFixedHeight(40)
        self.StopButton          .setFixedHeight(40)
        self.YouTubeStatus       .setFixedHeight(40)
        self.YouTubeButton       .setFixedHeight(40)
        self.ControllerButton    .setFixedHeight(40)
        self.setOilSwitchStatus(False)
        self.setYouTubeStatus(False)
        self.setMinimumWidth(500)

    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        main_layout = Qt.QVBoxLayout()
        main_layout.setSpacing(5)
        main_layout.setContentsMargins(5, 5, 5, 5)
        main_layout.setAlignment(Qt.Qt.AlignTop)
        row1_layout = Qt.QHBoxLayout()
        row2_layout = Qt.QHBoxLayout()
        row3_layout = Qt.QHBoxLayout()
        row4_layout = Qt.QHBoxLayout()
        row5_layout = Qt.QHBoxLayout()
        row6_layout = Qt.QHBoxLayout()
        row7_layout = Qt.QHBoxLayout()
        row1_layout.setSpacing(2)
        row1_layout.setContentsMargins(1, 1, 1, 1)

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

        row3_layout.setSpacing(2)
        row3_layout.setContentsMargins(1, 1, 1, 1)

        row4_layout.setSpacing(2)
        row4_layout.setContentsMargins(1, 1, 1, 1)

        row5_layout.setSpacing(2)
        row5_layout.setContentsMargins(1, 1, 1, 1)

        row6_layout.setSpacing(2)
        row6_layout.setContentsMargins(1, 1, 1, 1)

        row7_layout.setSpacing(2)
        row7_layout.setContentsMargins(1, 1, 1, 1)

        row1_layout.addWidget(self.InitButton          , 4)
        row1_layout.addWidget(self.ControllerButton    , 2)
        row1_layout.addWidget(self.ClearErrorButton    , 2)
        row2_layout.addWidget(self.OilSwitchButton     , 3)
        row2_layout.addWidget(self.OilSwitchStatus     , 1)
        row2_layout.addWidget(self.YouTubeButton       , 3)
        row2_layout.addWidget(self.YouTubeStatus       , 1)

        row3_layout.addWidget(self.ChamberButton       , 3)
        row3_layout.addWidget(self.EditChamberNumber   , 3)
        row3_layout.addWidget(self.PickTrayButton      , 1)
        row3_layout.addWidget(self.DropTrayButton      , 1)

        row4_layout.addWidget(self.StartButton         )
        row5_layout.addWidget(self.PauseButton         )
        row6_layout.addWidget(self.JumpButton          )
        row7_layout.addWidget(self.StopButton          )

        main_layout.addLayout(row1_layout)
        main_layout.addLayout(row2_layout)
        main_layout.addLayout(row3_layout)
        main_layout.addLayout(row4_layout)
        main_layout.addLayout(row5_layout)
        main_layout.addLayout(row6_layout)
        main_layout.addLayout(row7_layout)
        self.setLayout(main_layout)

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

    def initClearErrorButton    (self):
        if not self.hasClearErrorButton    :
            self.ClearErrorButton     = Qt.QPushButton ()

    def initOilSwitchButton     (self):
        if not self.hasOilSwitchButton     :
            self.OilSwitchButton      = Qt.QPushButton ()

    def initOilSwitchStatus     (self):
        if not self.hasOilSwitchStatus     :
            self.OilSwitchStatus      = Qt.QLabel      ()

    def initChamberButton       (self):
        if not self.hasChamberButton       :
            self.ChamberButton        = Qt.QPushButton ()

    def initEditChamberNumber   (self):
        if not self.hasEditChamberNumber   :
            self.EditChamberNumber    = Qt.QSpinBox    ()

    def initPickTrayButton      (self):
        if not self.hasPickTrayButton      :
            self.PickTrayButton       = Qt.QPushButton ()

    def initDropTrayButton      (self):
        if not self.hasDropTrayButton      :
            self.DropTrayButton       = Qt.QPushButton ()

    def initControllerButton    (self):
        if not self.hasControllerButton    :
            self.ControllerButton     = Qt.QPushButton ()

    def initStartButton         (self):
        if not self.hasStartButton         :
            self.StartButton          = Qt.QPushButton ()

    def initPauseButton         (self):
        if not self.hasPauseButton         :
            self.PauseButton          = Qt.QPushButton ()

    def initStopButton          (self):
        if not self.hasStopButton          :
            self.StopButton           = Qt.QPushButton ()

    def initYouTubeStatus       (self):
        if not self.hasYouTubeStatus       :
            self.YouTubeStatus        = Qt.QLabel      ()

    def initYouTubeButton       (self):
        if not self.hasYouTubeButton       :
            self.YouTubeButton        = Qt.QPushButton ()

    def initJumpButton          (self):
        if not self.hasJumpButton          :
            self.JumpButton           = Qt.QPushButton ()

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

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

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

    @property
    def hasOilSwitchStatus     (self) -> bool:
        return hasattr(self, 'OilSwitchStatus'     ) and isinstance(self.OilSwitchStatus     , Qt.QLabel      )

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

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

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

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

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

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

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

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


    @property
    def hasYouTubeStatus      (self) -> bool:
        return hasattr(self, 'YouTubeStatus'      ) and isinstance(self.YouTubeStatus      , Qt.QLabel      )

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

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