#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ObjectiveOperation.py
@Description：
@Author：XSH
@Time：2025/12/18 13:49
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from abc                        import abstractmethod                     #
from PyQt5                      import Qt                                 #
from AppInterfaces.UiInterface  import UiInterface                        #
from AppInterfaces.globalSlot   import globalSlot, AppSlot                #
from AppCore.Contexts           import *                                  #
from AppCore.DBModels           import *                                  #
from AppCore.Levels             import *                                  #
from AppUtils.utils             import *                                  #

class ObjectiveOperation(Qt.QWidget, UiInterface):
    ObjectiveChangedSignal  : Qt.pyqtSignal = Qt.pyqtSignal(object)
    TrayNumberChangedSignal : Qt.pyqtSignal = Qt.pyqtSignal(object)
    ObjectiveGroup          : Qt.QGroupBox                  #
    ButtonObjective1        : Qt.QPushButton                #
    ButtonObjective10       : Qt.QPushButton                #
    ButtonObjective40       : Qt.QPushButton                #
    ButtonObjective20       : Qt.QPushButton                #
    ButtonObjective63       : Qt.QPushButton                #
    ButtonObjective100      : Qt.QPushButton                #
    ButtonObjectiveNone     : Qt.QPushButton                #
    ButtonSlide1            : Qt.QPushButton                #
    ButtonSlide2            : Qt.QPushButton                #
    ButtonSlide3            : Qt.QPushButton                #
    ButtonSlide4            : Qt.QPushButton                #
    ButtonSlide5            : Qt.QPushButton                #
    ButtonNextButton        : Qt.QPushButton                #
    TrayNumber              : int                           #
    Level                   : int                           #
    Objective               : ObjectiveModel                #
    Tray                    : TrayModel                     #


    def __init__(self, parent: Qt.QWidget = None):
        super(ObjectiveOperation, self).__init__(parent)
        self.Initialization('ObjectiveOperation', self, parent)


    def initValue(self):
        super(ObjectiveOperation, self).initValue()
        self.initObjectiveGroup          ()
        self.initButtonObjective1        ()
        self.initButtonObjective10       ()
        self.initButtonObjective40       ()
        self.initButtonObjective20       ()
        self.initButtonObjective63       ()
        self.initButtonObjective100      ()
        self.initButtonObjectiveNone     ()
        self.initLevel                   ()
        self.initObjective               ()
        self.initButtonSlide1            ()
        self.initButtonSlide2            ()
        self.initButtonSlide3            ()
        self.initButtonSlide4            ()
        self.initButtonSlide5            ()
        self.initButtonNextButton        ()
        self.initTray                    ()

    def initProperty(self):
        super(ObjectiveOperation, self).initProperty()
        self.ButtonObjective1        .setText("１倍物镜　　")
        self.ButtonObjective10       .setText("１０倍物镜　")
        self.ButtonObjective40       .setText("４０倍物镜　")
        self.ButtonObjective20       .setText("２０倍物镜　")
        self.ButtonObjective63       .setText("６３倍物镜　")
        self.ButtonObjective100      .setText("１００倍物镜")
        self.ButtonObjectiveNone     .setText("　空的物镜　")
        self.ButtonSlide1            .setText('１号载玻片　')
        self.ButtonSlide2            .setText('２号载玻片　')
        self.ButtonSlide3            .setText('３号载玻片　')
        self.ButtonSlide4            .setText('４号载玻片　')
        self.ButtonSlide5            .setText('５号载玻片　')
        self.ButtonNextButton        .setText('下一个玻片　')

        self.ButtonObjective1        .setFixedHeight(35)
        self.ButtonObjective10       .setFixedHeight(35)
        self.ButtonObjective40       .setFixedHeight(35)
        self.ButtonObjective20       .setFixedHeight(35)
        self.ButtonObjective63       .setFixedHeight(35)
        self.ButtonObjective100      .setFixedHeight(35)
        self.ButtonObjectiveNone     .setFixedHeight(35)
        self.ButtonSlide1            .setFixedHeight(35)
        self.ButtonSlide2            .setFixedHeight(35)
        self.ButtonSlide3            .setFixedHeight(35)
        self.ButtonSlide4            .setFixedHeight(35)
        self.ButtonSlide5            .setFixedHeight(35)
        self.ButtonNextButton        .setFixedHeight(35)

        self.ObjectiveGroup.setTitle("物镜/玻片号选择")


    def initConnect(self):
        super(ObjectiveOperation, self).initConnect()
        TYPE: Qt.Qt.ConnectionType = Qt.Qt.ConnectionType(Qt.Qt.AutoConnection | Qt.Qt.UniqueConnection)
        self.ButtonObjective1   .clicked.connect(self.SlotButtonObjective1   , TYPE)
        self.ButtonObjective10  .clicked.connect(self.SlotButtonObjective10  , TYPE)
        self.ButtonObjective40  .clicked.connect(self.SlotButtonObjective40  , TYPE)
        self.ButtonObjective20  .clicked.connect(self.SlotButtonObjective20  , TYPE)
        self.ButtonObjective63  .clicked.connect(self.SlotButtonObjective63  , TYPE)
        self.ButtonObjective100 .clicked.connect(self.SlotButtonObjective100 , TYPE)
        self.ButtonObjectiveNone.clicked.connect(self.SlotButtonObjectiveNone, TYPE)
        self.ButtonSlide1       .clicked.connect(self.SlotButtonSlide1       , TYPE)
        self.ButtonSlide2       .clicked.connect(self.SlotButtonSlide2       , TYPE)
        self.ButtonSlide3       .clicked.connect(self.SlotButtonSlide3       , TYPE)
        self.ButtonSlide4       .clicked.connect(self.SlotButtonSlide4       , TYPE)
        self.ButtonSlide5       .clicked.connect(self.SlotButtonSlide5       , TYPE)
        self.ButtonNextButton   .clicked.connect(self.SlotButtonNextButton   , TYPE)

    def setLevel(self, level):
        self.Level = level
        if self.hasLevel:
            self.Objective = ObjectiveModel.getConfig(self.Level)

    def setTrayNumber(self, number: (int, float)):
        self.TrayNumber = number
        if self.hasTrayNumber:
            self.Tray = TrayModel.getConfig(self.TrayNumber)

    def SlotButtonSlide1     (self):
        self.TrayNumber = TrayLevel.TraySlide1
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonSlide2     (self):
        self.TrayNumber = TrayLevel.TraySlide2
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonSlide3     (self):
        self.TrayNumber = TrayLevel.TraySlide3
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonSlide4     (self):
        self.TrayNumber = TrayLevel.TraySlide4
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonSlide5     (self):
        self.TrayNumber = TrayLevel.TraySlide5
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonNextButton (self):
        self.TrayNumber = TrayLevel.TraySlide1
        self.Tray = TrayModel.getConfig(self.TrayNumber)
        self.TrayNumberChangedSignal.emit(self.TrayNumber)

    def SlotButtonObjective1    (self):
        objective = ObjectiveLevel.Objective1
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjective10   (self):
        objective = ObjectiveLevel.Objective10
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjective40   (self):
        objective = ObjectiveLevel.Objective40
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjective20   (self):
        objective = ObjectiveLevel.Objective20
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjective63   (self):
        objective = ObjectiveLevel.Objective63
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjective100  (self):
        objective = ObjectiveLevel.Objective100
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def SlotButtonObjectiveNone (self):
        objective = ObjectiveLevel.ObjectiveNone
        self.setLevel(objective)
        self.ObjectiveChangedSignal.emit(objective)

    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        main_layout: Qt.QGridLayout = Qt.QGridLayout()
        main_layout.setSpacing(1)
        main_layout.setContentsMargins(5, 5, 5, 5)

        group_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        group_layout.setSpacing(1)
        group_layout.setContentsMargins(10, 10, 10, 10)
        group_layout.setAlignment(Qt.Qt.AlignTop)
        group_layout.addWidget(self.ButtonObjective1        )
        group_layout.addWidget(self.ButtonObjective10       )
        group_layout.addWidget(self.ButtonObjective20       )
        group_layout.addWidget(self.ButtonObjective40       )
        group_layout.addWidget(self.ButtonObjective63       )
        group_layout.addWidget(self.ButtonObjective100      )
        group_layout.addWidget(self.ButtonObjectiveNone     )
        group_layout.addWidget(self.ButtonSlide1            )
        group_layout.addWidget(self.ButtonSlide2            )
        group_layout.addWidget(self.ButtonSlide3            )
        group_layout.addWidget(self.ButtonSlide4            )
        group_layout.addWidget(self.ButtonSlide5            )
        group_layout.addWidget(self.ButtonNextButton        )
        self.ObjectiveGroup.setLayout(group_layout)

        main_layout.addWidget(self.ObjectiveGroup          , 0, 0, -1, -1)

        self.setLayout(main_layout)


    def initObjectiveGroup          (self):
        if not self.hasObjectiveGroup          :
            self.ObjectiveGroup          = Qt.QGroupBox  ()

    def initButtonObjective1        (self):
        if not self.hasButtonObjective1        :
            self.ButtonObjective1        = Qt.QPushButton()

    def initButtonObjective10       (self):
        if not self.hasButtonObjective10       :
            self.ButtonObjective10       = Qt.QPushButton()

    def initButtonObjective40       (self):
        if not self.hasButtonObjective40       :
            self.ButtonObjective40       = Qt.QPushButton()

    def initButtonObjective20       (self):
        if not self.hasButtonObjective20       :
            self.ButtonObjective20       = Qt.QPushButton()

    def initButtonObjective63       (self):
        if not self.hasButtonObjective63       :
            self.ButtonObjective63       = Qt.QPushButton()

    def initButtonObjective100      (self):
        if not self.hasButtonObjective100      :
            self.ButtonObjective100      = Qt.QPushButton()

    def initButtonObjectiveNone     (self):
        if not self.hasButtonObjectiveNone     :
            self.ButtonObjectiveNone     = Qt.QPushButton()

    def initLevel                   (self):
        if not self.hasLevel                   :
            self.Level                   = int           (ObjectiveLevel.Objective1)

    def initObjective               (self):
        if not self.hasObjective               :
            self.Objective               = ObjectiveModel.getConfig(self.Level)

    def initButtonSlide1            (self):
        if not self.hasButtonSlide1            :
            self.ButtonSlide1             = Qt.QPushButton()

    def initButtonSlide2            (self):
        if not self.hasButtonSlide2            :
            self.ButtonSlide2             = Qt.QPushButton()

    def initButtonSlide3            (self):
        if not self.hasButtonSlide3            :
            self.ButtonSlide3             = Qt.QPushButton()

    def initButtonSlide4            (self):
        if not self.hasButtonSlide4            :
            self.ButtonSlide4             = Qt.QPushButton()

    def initButtonSlide5            (self):
        if not self.hasButtonSlide5            :
            self.ButtonSlide5             = Qt.QPushButton()

    def initButtonNextButton        (self):
        if not self.hasButtonNextButton        :
            self.ButtonNextButton         = Qt.QPushButton()

    def initTrayNumber              (self):
        if not self.hasTrayNumber              :
            self.TrayNumber               = TrayLevel.TraySlide1

    def initTray(self):
        if not self.hasTray:
            self.Tray = TrayModel.getConfig(self.traynumber)


    @property
    def objective(self) -> ObjectiveModel:
        self.initObjective()
        return self.Objective

    @property
    def level(self) -> int:
        self.initLevel()
        return self.Level

    @property
    def traynumber(self) -> int:
        self.initTrayNumber()
        return self.TrayNumber

    @property
    def tray(self) -> TrayModel:
        self.initTray()
        return self.Tray





    @property
    def hasObjectiveGroup          (self) -> bool:
        return self.has_field('ObjectiveGroup'      , Qt.QGroupBox  )

    @property
    def hasButtonObjective1        (self) -> bool:
        return self.has_field('ButtonObjective1'    , Qt.QPushButton)

    @property
    def hasButtonObjective10       (self) -> bool:
        return self.has_field('ButtonObjective10'   , Qt.QPushButton)

    @property
    def hasButtonObjective40       (self) -> bool:
        return self.has_field('ButtonObjective40'   , Qt.QPushButton)

    @property
    def hasButtonObjective20       (self) -> bool:
        return self.has_field('ButtonObjective20'   , Qt.QPushButton)

    @property
    def hasButtonObjective63       (self) -> bool:
        return self.has_field('ButtonObjective63'   , Qt.QPushButton)

    @property
    def hasButtonObjective100      (self) -> bool:
        return self.has_field('ButtonObjective100'  , Qt.QPushButton)

    @property
    def hasButtonObjectiveNone     (self) -> bool:
        return self.has_field('ButtonObjectiveNone' , Qt.QPushButton)

    @property
    def hasLevel                   (self) -> bool:
        return self.has_field('Level'               , int           )

    @property
    def hasObjective               (self) -> bool:
        return self.has_field('Objective'           , ObjectiveModel)









    @property
    def hasButtonSlide1            (self) -> bool:
        return self.has_field('ButtonSlide1'     , Qt.QPushButton  )

    @property
    def hasButtonSlide2            (self) -> bool:
        return self.has_field('ButtonSlide2'     , Qt.QPushButton  )

    @property
    def hasButtonSlide3            (self) -> bool:
        return self.has_field('ButtonSlide3'     , Qt.QPushButton  )

    @property
    def hasButtonSlide4            (self) -> bool:
        return self.has_field('ButtonSlide4'     , Qt.QPushButton  )

    @property
    def hasButtonSlide5            (self) -> bool:
        return self.has_field('ButtonSlide5'     , Qt.QPushButton  )

    @property
    def hasButtonNextButton        (self) -> bool:
        return self.has_field('ButtonNextButton' , Qt.QPushButton  )

    @property
    def hasTrayNumber              (self) -> bool:
        return self.has_field('TrayNumber'       , int             )

    @property
    def hasTray(self) -> bool:
        return self.has_field('Tray', TrayModel)