#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ChamberDropTrayDialog.py
@Description：
@Author：XSH
@Time：2025/12/8 10:56
@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 ChamberDropTrayDialog(Qt.QDialog, UiInterface):
    InfoChamber: Qt.QLabel           #
    EditChamber: Qt.QSpinBox         #
    DropButton : Qt.QPushButton      #



    def __init__(self, parent: Qt.QWidget = None):
        super(ChamberDropTrayDialog, self).__init__(parent)
        self.Initialization('片仓放片', self, parent)
        self.initWidgetStyle()
        self.initWindowIcon()

    def initValue(self):
        super(ChamberDropTrayDialog, self).initValue()
        self.initInfoChamber ()
        self.initEditChamber ()
        self.initDropButton  ()


    def initConnect(self):
        super(ChamberDropTrayDialog, self).initConnect()
        TYPE: Qt.Qt.ConnectionType = Qt.Qt.ConnectionType(Qt.Qt.AutoConnection | Qt.Qt.UniqueConnection)
        self.DropButton.clicked.connect(slot=self.SlotDropButtonClicked, type=TYPE)
        AppSlot.UiDropTrayCompleteSignal.connect(slot=self.SlotDropTrayCompleteSignal, type=TYPE)
    def SlotDropButtonClicked(self):
        chamber_number: int = self.EditChamber.value()
        flag: int = Qt.QDialog.Rejected
        if 1 <= chamber_number <= 24:
            AppSlot.DropCurrentTraySignal.emit(chamber_number)
            flag = Qt.QDialog.Accepted
        else:
            flag = Qt.QDialog.Rejected
        self.done(flag)

    def SlotDropTrayCompleteSignal(self, flag: int):
        _flag: int = flag if isinstance(flag, int) else Qt.QDialog.Rejected
        if _flag == Qt.QDialog.Accepted:
            self.done(Qt.QDialog.Accepted)

    def initProperty(self):
        super(ChamberDropTrayDialog, self).initProperty()
        self.InfoChamber.setText("请选择要下放的片仓通道号:")
        self.EditChamber.setRange(1, 24)
        self.DropButton.setText("片仓放片")
        self.InfoChamber.setFixedHeight(40)
        self.EditChamber.setFixedHeight(40)
        self.DropButton .setFixedHeight(40)

        self.setMinimumHeight(200)
        self.setMinimumWidth(500)
        UiUtils.center_on_screen( self)



    def initLayouts(self):
        super(ChamberDropTrayDialog, self).initLayouts()
        if self.hasWindowLayouts:
            return
        main_layout: Qt.QHBoxLayout = Qt.QHBoxLayout()
        main_layout.setSpacing(2)
        main_layout.setContentsMargins(10, 10, 10, 10)
        main_layout.addWidget(self.InfoChamber  )
        main_layout.addWidget(self.EditChamber  )
        main_layout.addWidget(self.DropButton   )
        self.setLayout(main_layout)

    def initInfoChamber (self):
        if not self.hasInfoChamber:
            self.InfoChamber = Qt.QPushButton ()

    def initEditChamber (self):
        if not self.hasEditChamber:
            self.EditChamber = Qt.QSpinBox    ()

    def initDropButton  (self):
        if not self.hasDropButton :
            self.DropButton  = Qt.QPushButton ()

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

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

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