#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：SelectChamberView.py\n
 @DateTime: 2025/7/25 16:14\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 SelectChamberView(Qt.QWidget, UiInterface):
    InfoChamberNumber   : Qt.QLabel     #
    InfoRowNumber       : Qt.QLabel     #
    InfoTrayNumber      : Qt.QLabel     #
    EditTrayNumber      : Qt.QComboBox  #
    EditChamberNumber   : Qt.QComboBox  #
    EditRowNumber       : Qt.QComboBox  #
    CheckGroupButton    : Qt.QPushButton#
    CheckChamberButton  : Qt.QPushButton#
    OtherFunctionButton : Qt.QPushButton#
    def __init__(self, parent: Qt.QWidget = None):
        super(SelectChamberView, self).__init__(parent=parent)
        self.Initialization('SelectChamberView', self, parent)
        self.initWidgetStyle()

    def getChamberNumber(self) -> (int, int):
        chamber_number: int = AppConvert.ObjectConvert(self.EditChamberNumber.currentText(), int)
        row_number: int = AppConvert.ObjectConvert(self.EditRowNumber.currentText(), int)
        return chamber_number, row_number

    def setChamberNumber(self, chamber_number: int, row_number: int):
        self.EditChamberNumber .setCurrentText('{:^2d}'.format(chamber_number   ) )
        self.EditRowNumber     .setCurrentText('{:^2d}'.format(row_number       ) )


    def getTrayNumber(self) -> int:
        tray_number: int = ModuleLevel.ModuleTraySlide2 if self.EditTrayNumber.currentText() == '托盘2' else ModuleLevel.ModuleTraySlide1
        return tray_number

    def setTrayNumber(self, tray_number: int):
        text: str = '托盘2' if tray_number == ModuleLevel.ModuleTraySlide2 else '托盘1'
        self.EditTrayNumber.setCurrentText(text)

    def flushFrame(self):
        super(SelectChamberView, self).flushFrame()





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

    def initValue(self):
        super(SelectChamberView, self).initValue()
        self.initWindows()

    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        layout.setSpacing(1)
        layout.setContentsMargins(1, 0, 1, 0)
        layout.addWidget(self.InfoChamberNumber     )
        layout.addWidget(self.EditChamberNumber     )
        layout.addWidget(self.InfoRowNumber         )
        layout.addWidget(self.EditRowNumber         )
        layout.addWidget(self.InfoTrayNumber        )
        layout.addWidget(self.EditTrayNumber        )
        layout.addWidget(self.CheckGroupButton      )
        layout.addWidget(self.CheckChamberButton    )
        layout.addWidget(self.OtherFunctionButton   )
        self.setLayout(layout)

    def initWindows(self):
        self.initInfoChamberNumber      ()
        self.initInfoRowNumber          ()
        self.initEditChamberNumber      ()
        self.initEditRowNumber          ()
        self.initCheckGroupButton       ()
        self.initCheckChamberButton     ()
        self.initInfoTrayNumber         ()
        self.initEditTrayNumber         ()
        self.initOtherFunctionButton    ()

    def initProperty(self):
        super(SelectChamberView, self).initProperty()
        self.InfoChamberNumber  .setText('片仓号')
        self.InfoRowNumber      .setText('行号')
        self.InfoTrayNumber     .setText('托盘号')
        self.InfoChamberNumber  .setAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignVCenter)
        self.InfoRowNumber      .setAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignVCenter)
        self.EditChamberNumber  .addItems(['{:^2d}'.format(number) for number in range(1, 11)])
        self.EditRowNumber      .addItems(['{:^2d}'.format(number) for number in range(1, 21)])
        self.EditTrayNumber     .addItems(['托盘1', '托盘2'])
        self.CheckGroupButton   .setText('检测片仓')
        self.CheckChamberButton .setText('检测玻片')
        self.OtherFunctionButton.setVisible(False)

    def initInfoChamberNumber (self):
        if not self.hasInfoChamberNumber :
            self.InfoChamberNumber  = Qt.QLabel    (self)
    def initInfoRowNumber     (self):
        if not self.hasInfoRowNumber     :
            self.InfoRowNumber      = Qt.QLabel    (self)
    def initEditChamberNumber (self):
        if not self.hasEditChamberNumber :
            self.EditChamberNumber  = Qt.QComboBox (self)
    def initEditRowNumber     (self):
        if not self.hasEditRowNumber     :
            self.EditRowNumber      = Qt.QComboBox (self)

    def initInfoTrayNumber(self):
        if not self.hasInfoTrayNumber:
            self.InfoTrayNumber = Qt.QLabel(self)

    def initEditTrayNumber(self):
        if not self.hasEditTrayNumber:
            self.EditTrayNumber = Qt.QComboBox(self)

    def initCheckGroupButton   (self):
        if not self.hasCheckGroupButton   :
            self.CheckGroupButton    = Qt.QPushButton(self)
    def initCheckChamberButton (self):
        if not self.hasCheckChamberButton :
            self.CheckChamberButton  = Qt.QPushButton(self)
    def initOtherFunctionButton(self):
        if not self.hasOtherFunctionButton:
            self.OtherFunctionButton = Qt.QPushButton(self)

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

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

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

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

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

    @property
    def hasEditRowNumber     (self) -> bool:
        return hasattr(self, 'EditRowNumber'     ) and isinstance(self.EditRowNumber    , Qt.QComboBox)



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

    @property
    def hasEditTrayNumber(self) -> bool:
        return hasattr(self, 'EditTrayNumber') and isinstance(self.EditTrayNumber, Qt.QComboBox)

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