#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：TrayOperation.py
@Description：
@Author：XSH
@Time：2025/11/26 19:50
@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 TrayOperation(Qt.QWidget, UiInterface):
    InfoChamberNumber   : Qt.QPushButton                #
    EditChamberNumber   : Qt.QSpinBox                   #
    InfoTrayNumber      : Qt.QPushButton                #
    EditTrayNumber      : Qt.QSpinBox                   #
    InfoObjective       : Qt.QPushButton                #
    EditObjective       : Qt.QSpinBox                   #
    InfoRowNumber       : Qt.QPushButton                #
    EditRowNumber       : Qt.QSpinBox                   #
    InfoColNumber       : Qt.QPushButton                #
    EditColNumber       : Qt.QSpinBox                   #
    MoveLocationButton  : Qt.QPushButton                #
    def __init__(self, parent: Qt.QWidget = None):
        super(TrayOperation, self).__init__(parent=parent)
        self.Initialization('TrayOperation', self, parent)
        self.initWidgetStyle()


    def getChamberNumber   (self) -> int    :
        if self.hasEditChamberNumber   :
            return int    (self.EditChamberNumber   .value())
        return int    (1)

    def getTrayNumber(self) -> int:
        if self.hasEditTrayNumber:
            return int(self.EditTrayNumber.value())
        return int (1)
    def getObjective       (self) -> int    :
        if self.hasEditObjective       :
            return int    (self.EditObjective       .value())
        return int    (0)

    def setChamberNumber   (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditChamberNumber   :
            self.EditChamberNumber   .setValue(int    (value))

    def setObjective       (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditObjective       :
            self.EditObjective       .setValue(int    (value))

    def setTrayNumber(self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditTrayNumber:
            self.EditTrayNumber.setValue(int(value))

    def getRowNumber(self) -> int:
        if self.hasEditRowNumber:
            return int(self.EditRowNumber.value())
        return 1
    def getColNumber(self) -> int:
        if self.hasEditColNumber:
            return int(self.EditColNumber.value())
        return 1
    def setRowNumber   (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditRowNumber   :
            self.EditRowNumber   .setValue(int    (value))

    def setColNumber   (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditColNumber   :
            self.EditColNumber   .setValue(int    (value))

    def initValue(self):
        super(TrayOperation, self).initValue()
        self.initInfoChamberNumber ()
        self.initEditChamberNumber ()
        self.initInfoTrayNumber    ()
        self.initEditTrayNumber    ()
        self.initInfoObjective     ()
        self.initEditObjective     ()
        self.initInfoRowNumber     ()
        self.initEditRowNumber     ()
        self.initInfoColNumber     ()
        self.initEditColNumber     ()
        self.initMoveLocationButton()

    def initProperty(self):
        super(TrayOperation, self).initProperty()
        self.InfoChamberNumber   .setText("片仓序号　")
        self.InfoObjective       .setText('物镜类型　')
        self.InfoTrayNumber      .setText('玻片序号　')
        self.InfoRowNumber       .setText('　行号　　')
        self.InfoColNumber       .setText('　列号　　')
        self.MoveLocationButton  .setText('移动位置　')
        self.EditColNumber       .setRange(-20  , 45)
        self.EditRowNumber       .setRange(1    , 23)
        self.EditColNumber       .setValue(1)
        self.EditChamberNumber   .setRange(1    , 24)

        self.EditObjective       .setRange(1, 7 )
        self.EditTrayNumber      .setRange(1, 5 )
        self.EditChamberNumber   .setSingleStep(1           )
        self.EditObjective       .setSingleStep(1           )
        self.EditTrayNumber      .setSingleStep(1           )
        self.EditColNumber       .setSingleStep(1           )
        self.EditRowNumber       .setSingleStep(1           )

        self.InfoChamberNumber   .setFixedHeight(40)
        self.EditChamberNumber   .setFixedHeight(40)
        self.InfoTrayNumber      .setFixedHeight(40)
        self.EditTrayNumber      .setFixedHeight(40)
        self.InfoObjective       .setFixedHeight(40)
        self.EditObjective       .setFixedHeight(40)
        self.InfoRowNumber       .setFixedHeight(40)
        self.EditRowNumber       .setFixedHeight(40)
        self.InfoColNumber       .setFixedHeight(40)
        self.EditColNumber       .setFixedHeight(40)
        self.MoveLocationButton  .setFixedHeight(40)

    def initLayouts(self):
        super(TrayOperation, self).initLayouts()
        if self.hasWindowLayouts:
            return
        main_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        main_layout.setSpacing(2)
        main_layout.setContentsMargins(10, 2, 10, 2)

        row1_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row1_layout.setSpacing(2)
        row1_layout.setContentsMargins(10, 2, 10, 2)

        row2_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row2_layout.setSpacing(2)
        row2_layout.setContentsMargins(10, 2, 10, 2)

        row1_layout.addWidget(self.InfoChamberNumber , 1)
        row1_layout.addWidget(self.EditChamberNumber , 1)
        row1_layout.addWidget(self.InfoTrayNumber    , 1)
        row1_layout.addWidget(self.EditTrayNumber    , 1)
        row1_layout.addWidget(self.InfoObjective     , 1)
        row1_layout.addWidget(self.EditObjective     , 1)

        row2_layout.addWidget(self.InfoRowNumber     , 1)
        row2_layout.addWidget(self.EditRowNumber     , 1)
        row2_layout.addWidget(self.InfoColNumber     , 1)
        row2_layout.addWidget(self.EditColNumber     , 1)
        row2_layout.addWidget(self.MoveLocationButton, 2)

        main_layout.addLayout(row1_layout)
        main_layout.addLayout(row2_layout)

        self.setLayout(main_layout)

    def initInfoChamberNumber (self):
        if not self.hasInfoChamberNumber :
            self.InfoChamberNumber  = Qt.QPushButton  (self)

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

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

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

    def initInfoObjective     (self):
        if not self.hasInfoObjective     :
            self.InfoObjective      = Qt.QPushButton  (self)

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

    def initInfoRowNumber(self):
        if not self.hasInfoRowNumber:
            self.InfoRowNumber = Qt.QPushButton (self)

    def initEditRowNumber(self):
        if not self.hasEditRowNumber:
            self.EditRowNumber = Qt.QSpinBox    (self)

    def initInfoColNumber(self):
        if not self.hasInfoColNumber:
            self.InfoColNumber = Qt.QPushButton (self)

    def initEditColNumber(self):
        if not self.hasEditColNumber:
            self.EditColNumber = Qt.QSpinBox    (self)

    def initMoveLocationButton(self):
        if not self.hasMoveLocationButton:
            self.MoveLocationButton = Qt.QPushButton(self)

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

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

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

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

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


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

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

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

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

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

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