#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：ScanOperationView.py\n
 @DateTime: 2025/7/25 11:51\n
 @Author  ：xsh
"""
from abc import abstractmethod
from PyQt5 import Qt
from AppInterfaces.UiInterface import UiInterface, AppConvert, AppUtils
from AppCore.Contexts import *
from AppCore.DBModels import *
from AppCore.Levels import *
from AppUtils.UiUtils import UiUtils

class ScanOperationView(Qt.QWidget, UiInterface):
    InitHardWareButton                  : Qt.QPushButton
    StatusOperationFrameButton          : Qt.QPushButton
    BuzzerSwitchButton                  : Qt.QPushButton
    OilSwitchButton                     : Qt.QPushButton
    HitBotOperationFrameButton          : Qt.QPushButton
    ManipulatorOperationFrameButton     : Qt.QPushButton
    ScanningOperationButton             : Qt.QPushButton
    PauseScanOperationButton            : Qt.QPushButton
    StopScanOperationButton             : Qt.QPushButton
    ClearWarningButton                  : Qt.QPushButton
    def __init__(self, parent: Qt.QWidget = None):
        super(ScanOperationView, self).__init__(parent=parent)
        self.Initialization('ScanOperationView', self, parent)
        # self.initWidgetStyle()

    def initWidgetStyle(self):
        self.setStyleSheet(UiUtils.getWidgetStyle())

    def initValue(self):
        super(ScanOperationView, self).initValue()
        self.initInitHardWareButton                  ()
        self.initStatusOperationFrameButton          ()
        self.initBuzzerSwitchButton                  ()
        self.initOilSwitchButton                     ()
        self.initHitBotOperationFrameButton          ()
        self.initManipulatorOperationFrameButton     ()
        self.initScanningOperationButton             ()
        self.initPauseScanOperationButton            ()
        self.initStopScanOperationButton             ()
        self.initClearWarningButton                  ()

    def initProperty(self):
        super(ScanOperationView, self).initProperty()
        self.InitHardWareButton                  .setStyleSheet(UiUtils.getBigButtonStyle())
        self.StatusOperationFrameButton          .setStyleSheet(UiUtils.getBigButtonStyle())
        self.BuzzerSwitchButton                  .setStyleSheet(UiUtils.getBigButtonStyle())
        self.OilSwitchButton                     .setStyleSheet(UiUtils.getBigButtonStyle())
        self.HitBotOperationFrameButton          .setStyleSheet(UiUtils.getBigButtonStyle())
        self.ManipulatorOperationFrameButton     .setStyleSheet(UiUtils.getBigButtonStyle())
        self.ScanningOperationButton             .setStyleSheet(UiUtils.getBigButtonStyle())
        self.PauseScanOperationButton            .setStyleSheet(UiUtils.getBigButtonStyle())
        self.StopScanOperationButton             .setStyleSheet(UiUtils.getBigButtonStyle())
        self.ClearWarningButton                  .setStyleSheet(UiUtils.getBigButtonStyle())

        self.InitHardWareButton                  .setText('初始化仪器　')
        self.StatusOperationFrameButton          .setText('玻片状态　　')
        self.BuzzerSwitchButton                  .setText('蜂鸣器开关　')
        self.OilSwitchButton                     .setText('油泵开关　　')
        self.HitBotOperationFrameButton          .setText('机械臂调试　')
        self.ManipulatorOperationFrameButton     .setText('载玻台调试　')
        self.ScanningOperationButton             .setText('开始扫描　　')
        self.PauseScanOperationButton            .setText('暂停扫描　　')
        self.StopScanOperationButton             .setText('停止扫描　　')
        self.ClearWarningButton                  .setText('清除告警　　')
    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        # layout.setAlignment(Qt.Qt.AlignTop)
        layouts: list[Qt.QHBoxLayout] = [
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout()
        ]
        layout.setSpacing(1)
        layout.setContentsMargins(1, 1, 1, 1)

        layouts[0].setSpacing(1)
        layouts[0].setContentsMargins(0, 0, 0, 0)

        layouts[1].setSpacing(1)
        layouts[1].setContentsMargins(0, 0, 0, 0)

        layouts[2].setSpacing(1)
        layouts[2].setContentsMargins(0, 0, 0, 0)

        layouts[3].setSpacing(1)
        layouts[3].setContentsMargins(0, 0, 0, 0)

        layouts[4].setSpacing(1)
        layouts[4].setContentsMargins(0, 0, 0, 0)

        layouts[5].setSpacing(1)
        layouts[5].setContentsMargins(0, 0, 0, 0)

        layouts[0].addWidget(self.InitHardWareButton                  )
        layouts[0].addWidget(self.StatusOperationFrameButton          )
        layouts[1].addWidget(self.BuzzerSwitchButton                  )
        layouts[1].addWidget(self.OilSwitchButton                     )
        layouts[2].addWidget(self.HitBotOperationFrameButton          )
        layouts[2].addWidget(self.ManipulatorOperationFrameButton     )
        layouts[3].addWidget(self.ScanningOperationButton             )
        layouts[4].addWidget(self.StopScanOperationButton             )
        layouts[5].addWidget(self.PauseScanOperationButton            )
        layouts[5].addWidget(self.ClearWarningButton                  )


        layout.addLayout(layouts[0])
        layout.addLayout(layouts[1])
        layout.addLayout(layouts[2])
        layout.addLayout(layouts[3])
        layout.addLayout(layouts[4])
        layout.addLayout(layouts[5])
        self.setLayout(layout)

    def initInitHardWareButton                  (self):
        if not self.hasInitHardWareButton                  :
            self.InitHardWareButton                   = Qt.QPushButton(self)

    def initStatusOperationFrameButton          (self):
        if not self.hasStatusOperationFrameButton          :
            self.StatusOperationFrameButton           = Qt.QPushButton(self)

    def initBuzzerSwitchButton                  (self):
        if not self.hasBuzzerSwitchButton                  :
            self.BuzzerSwitchButton                   = Qt.QPushButton(self)

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

    def initHitBotOperationFrameButton          (self):
        if not self.hasHitBotOperationFrameButton          :
            self.HitBotOperationFrameButton           = Qt.QPushButton(self)

    def initManipulatorOperationFrameButton     (self):
        if not self.hasManipulatorOperationFrameButton     :
            self.ManipulatorOperationFrameButton      = Qt.QPushButton(self)

    def initScanningOperationButton             (self):
        if not self.hasScanningOperationButton             :
            self.ScanningOperationButton              = Qt.QPushButton(self)

    def initPauseScanOperationButton            (self):
        if not self.hasPauseScanOperationButton            :
            self.PauseScanOperationButton             = Qt.QPushButton(self)

    def initStopScanOperationButton             (self):
        if not self.hasStopScanOperationButton             :
            self.StopScanOperationButton              = Qt.QPushButton(self)

    def initClearWarningButton(self):
        if not self.hasClearWarningButton:
            self.ClearWarningButton = Qt.QPushButton(self)

    @property
    def hasInitHardWareButton                  (self) -> bool:
        return hasattr(self, "InitHardWareButton"               ) and isinstance(self.InitHardWareButton                  , Qt.QPushButton)

    @property
    def hasStatusOperationFrameButton          (self) -> bool:
        return hasattr(self, "StatusOperationFrameButton"       ) and isinstance(self.StatusOperationFrameButton          , Qt.QPushButton)

    @property
    def hasBuzzerSwitchButton                  (self) -> bool:
        return hasattr(self, "BuzzerSwitchButton"               ) and isinstance(self.BuzzerSwitchButton                  , Qt.QPushButton)

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

    @property
    def hasHitBotOperationFrameButton          (self) -> bool:
        return hasattr(self, "HitBotOperationFrameButton"       ) and isinstance(self.HitBotOperationFrameButton          , Qt.QPushButton)

    @property
    def hasManipulatorOperationFrameButton     (self) -> bool:
        return hasattr(self, "ManipulatorOperationFrameButton"  ) and isinstance(self.ManipulatorOperationFrameButton     , Qt.QPushButton)

    @property
    def hasScanningOperationButton             (self) -> bool:
        return hasattr(self, "ScanningOperationButton"          ) and isinstance(self.ScanningOperationButton             , Qt.QPushButton)

    @property
    def hasPauseScanOperationButton            (self) -> bool:
        return hasattr(self, "PauseScanOperationButton"         ) and isinstance(self.PauseScanOperationButton            , Qt.QPushButton)

    @property
    def hasStopScanOperationButton             (self) -> bool:
        return hasattr(self, "StopScanOperationButton"          ) and isinstance(self.StopScanOperationButton             , Qt.QPushButton)

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