#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：SlideOperationView.py\n
 @DateTime: 2025/7/26 11:32\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
from AppHeadEnd.Commons.SlideViews.SlidePositionView    import SlidePositionView
from AppHeadEnd.Commons.SlideViews.MotionChangedView    import MotionChangedView
from AppHeadEnd.Commons.SlideViews.SelectLocationView   import SelectLocationView
from AppHeadEnd.Commons.HitBotViews.SelectChamberView import SelectChamberView
class SlideOperationView(Qt.QWidget, UiInterface):
    InitMotButton               : Qt.QPushButton        #
    InitMicButton               : Qt.QPushButton        #
    LowScanButton               : Qt.QPushButton        #
    HigScanButton               : Qt.QPushButton        #
    CameraButton                : Qt.QPushButton        #
    SaveImageButton             : Qt.QPushButton        #
    Location                    : SelectLocationView    #
    Position                    : SlidePositionView     #
    ObjectiveModelButton        : Qt.QPushButton        # 物镜参数
    CameraModelModelButton      : Qt.QPushButton        # 相机参数
    TrayModelButton             : Qt.QPushButton        # 托盘参数
    AnointingModelButton        : Qt.QPushButton        # 加油参数
    FocusingModelButton         : Qt.QPushButton        # 定焦参数
    SlideCaseModelButton        : Qt.QPushButton        # 核型数据
    CellModelButton             : Qt.QPushButton        # 核型小图
    ChamberStatusModelButton    : Qt.QPushButton        # 片仓状态
    ImageModelButton            : Qt.QPushButton        # 图片参数
    DebugModeButton             : Qt.QPushButton        # 调试模式
    ObjectiveChangedButton      : MotionChangedView     #
    XChangedButton              : MotionChangedView     #
    YChangedButton              : MotionChangedView     #
    ZChangedButton              : MotionChangedView     #
    SelectChamber               : SelectChamberView     #
    ScanningChamberButton       : Qt.QPushButton        #
    ScanningSlideButton         : Qt.QPushButton        #
    def __init__(self, parent: Qt.QWidget = None):
        super(SlideOperationView, self).__init__(parent=parent)
        self.Initialization('SlideOperationView', self, parent)
        self.initWidgetStyle()


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

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

    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        layout.setSpacing(1)
        layout.setContentsMargins(5, 0, 5, 0)
        layouts: list[Qt.QHBoxLayout] = [
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
            Qt.QHBoxLayout(),
        ]
        for _layout in layouts:
            _layout.setSpacing(1)
            _layout.setContentsMargins(5, 0, 5, 0)
        layouts[0 ].addWidget(self.InitMotButton               )
        layouts[0 ].addWidget(self.InitMicButton               )
        layouts[0 ].addWidget(self.LowScanButton               )
        layouts[0 ].addWidget(self.HigScanButton               )
        layouts[0 ].addWidget(self.CameraButton                )
        layouts[0 ].addWidget(self.SaveImageButton             )

        layouts[1 ].addWidget(self.Location                    )
        layouts[2 ].addWidget(self.Position                    )
        layouts[3 ].addWidget(self.SelectChamber               )

        layouts[4 ].addWidget(self.ObjectiveModelButton        )
        layouts[4 ].addWidget(self.CameraModelModelButton      )
        layouts[4 ].addWidget(self.TrayModelButton             )
        layouts[4 ].addWidget(self.AnointingModelButton        )
        layouts[4 ].addWidget(self.FocusingModelButton          )

        layouts[5 ].addWidget(self.SlideCaseModelButton        )
        layouts[5 ].addWidget(self.CellModelButton             )
        layouts[5 ].addWidget(self.ChamberStatusModelButton    )
        layouts[5 ].addWidget(self.ImageModelButton            )
        layouts[5 ].addWidget(self.DebugModeButton             )

        layouts[7 ].addWidget(self.XChangedButton              )
        layouts[7 ].addWidget(self.YChangedButton              )
        layouts[8 ].addWidget(self.ObjectiveChangedButton      )
        layouts[8 ].addWidget(self.ZChangedButton              )
        for _layout in layouts:
            layout.addLayout(_layout)
        self.setLayout(layout)


    def initWindows(self):
        self.initInitMotButton               ()
        self.initInitMicButton               ()
        self.initLowScanButton               ()
        self.initHigScanButton               ()
        self.initCameraButton                ()
        self.initSaveImageButton             ()
        self.initLocation                    ()
        self.initPosition                    ()
        self.initObjectiveModelButton        ()
        self.initCameraModelModelButton      ()
        self.initTrayModelButton             ()
        self.initAnointingModelButton        ()
        self.initFocusingModelButton          ()
        self.initSlideCaseModelButton        ()
        self.initCellModelButton             ()
        self.initChamberStatusModelButton    ()
        self.initImageModelButton            ()
        self.initDebugModeButton             ()
        self.initObjectiveChangedButton      ()
        self.initXChangedButton              ()
        self.initYChangedButton              ()
        self.initZChangedButton              ()
        self.initSelectChamber               ()
        # self.initScanningChamberButton       ()
        # self.initScanningSlideButton         ()
    def initProperty(self):
        super(SlideOperationView, self).initProperty()
        self.SelectChamber.OtherFunctionButton.setVisible(True)
        self.SelectChamber.OtherFunctionButton.setText('定焦平扫玻片')
        self.InitMotButton               .setText('初始化载玻台')
        self.InitMicButton               .setText('初始化显微镜')
        self.LowScanButton               .setText('低倍物镜扫描')
        self.HigScanButton               .setText('高倍物镜扫描')
        self.CameraButton                .setText('　相机画面　')
        self.SaveImageButton             .setText('　保存图片　')
        self.ObjectiveModelButton        .setText('　物镜参数　')#
        self.CameraModelModelButton      .setText('　相机参数　')#
        self.TrayModelButton             .setText('　托盘参数　')#
        self.AnointingModelButton        .setText('　滴油参数　')#
        self.FocusingModelButton          .setText('　定焦参数　')#
        self.SlideCaseModelButton        .setText('细胞大图信息')#
        self.CellModelButton             .setText('细胞小图信息')#
        self.ChamberStatusModelButton    .setText('　片仓状态　')#
        self.ImageModelButton            .setText('　图片参数　')#
        self.DebugModeButton             .setText('　调试模式　')#
        # self.ScanningChamberButton       .setText('测试扫描托盘')#
        # self.ScanningSlideButton         .setText('测试扫描玻片')#

        self.Location                    .setStyleSheet(UiUtils.getButtonStyle())
        self.Position                    .setStyleSheet(UiUtils.getButtonStyle())
        self.InitMotButton               .setStyleSheet(UiUtils.getButtonStyle())
        self.InitMicButton               .setStyleSheet(UiUtils.getButtonStyle())
        self.LowScanButton               .setStyleSheet(UiUtils.getButtonStyle())
        self.HigScanButton               .setStyleSheet(UiUtils.getButtonStyle())
        self.CameraButton                .setStyleSheet(UiUtils.getButtonStyle())
        self.SaveImageButton             .setStyleSheet(UiUtils.getButtonStyle())
        self.ObjectiveModelButton        .setStyleSheet(UiUtils.getButtonStyle())
        self.CameraModelModelButton      .setStyleSheet(UiUtils.getButtonStyle())
        self.TrayModelButton             .setStyleSheet(UiUtils.getButtonStyle())
        self.AnointingModelButton        .setStyleSheet(UiUtils.getButtonStyle())
        self.FocusingModelButton          .setStyleSheet(UiUtils.getButtonStyle())
        self.SlideCaseModelButton        .setStyleSheet(UiUtils.getButtonStyle())
        self.CellModelButton             .setStyleSheet(UiUtils.getButtonStyle())
        self.ChamberStatusModelButton    .setStyleSheet(UiUtils.getButtonStyle())
        self.ImageModelButton            .setStyleSheet(UiUtils.getButtonStyle())
        self.DebugModeButton             .setStyleSheet(UiUtils.getButtonStyle())
        # self.ScanningChamberButton       .setStyleSheet(UiUtils.getButtonStyle())
        # self.ScanningSlideButton         .setStyleSheet(UiUtils.getButtonStyle())




    def initObjectiveChangedButton      (self):
        if not self.hasObjectiveChangedButton      :
            self.ObjectiveChangedButton       = MotionChangedView  ('物镜类型', '物镜变换-', '物镜变换+', [f'{number}' for number in range(1, 8)], self)
    def initXChangedButton              (self):
        if not self.hasXChangedButton              :
            self.XChangedButton               = MotionChangedView  ('移动步长', '前移', '后移', ['0.01mm','0.02mm','0.05mm','0.1mm','0.2mm','0.5mm','0.71mm','1.00mm', '1.21mm','2.00mm', '5.00mm'], self)
    def initYChangedButton              (self):
        if not self.hasYChangedButton              :
            self.YChangedButton               = MotionChangedView  ('移动步长', '左移', '右移', ['0.01mm','0.02mm','0.05mm','0.1mm','0.2mm','0.5mm','0.71mm','1.00mm', '1.21mm','2.00mm', '5.00mm'], self)
    def initZChangedButton              (self):
        if not self.hasZChangedButton              :
            self.ZChangedButton               = MotionChangedView  ('移动步长', '上移', '下移', ['50','100','500','1000','2000','5000','10000','20000','50000','100000','200000','500000', '1000000','2000000','5000000'], self)

    def initInitMotButton               (self):
        if not self.hasInitMotButton               :
            self.InitMotButton                = Qt.QPushButton       (self)

    def initInitMicButton               (self):
        if not self.hasInitMicButton               :
            self.InitMicButton                = Qt.QPushButton       (self)

    def initLowScanButton               (self):
        if not self.hasLowScanButton               :
            self.LowScanButton                = Qt.QPushButton       (self)

    def initHigScanButton               (self):
        if not self.hasHigScanButton               :
            self.HigScanButton                = Qt.QPushButton       (self)

    def initCameraButton                (self):
        if not self.hasCameraButton                :
            self.CameraButton                 = Qt.QPushButton       (self)

    def initSaveImageButton             (self):
        if not self.hasSaveImageButton             :
            self.SaveImageButton              = Qt.QPushButton       (self)

    def initLocation                    (self):
        if not self.hasLocation                    :
            self.Location                     = SelectLocationView   (self)

    def initPosition                    (self):
        if not self.hasPosition                    :
            self.Position                     = SlidePositionView    (self)

    def initObjectiveModelButton        (self):
        if not self.hasObjectiveModelButton        :
            self.ObjectiveModelButton         = Qt.QPushButton       (self)

    def initCameraModelModelButton      (self):
        if not self.hasCameraModelModelButton      :
            self.CameraModelModelButton       = Qt.QPushButton       (self)

    def initTrayModelButton             (self):
        if not self.hasTrayModelButton             :
            self.TrayModelButton              = Qt.QPushButton       (self)

    def initAnointingModelButton        (self):
        if not self.hasAnointingModelButton        :
            self.AnointingModelButton         = Qt.QPushButton       (self)

    def initFocusingModelButton          (self):
        if not self.hasFocusingModelButton          :
            self.FocusingModelButton           = Qt.QPushButton       (self)

    def initSlideCaseModelButton        (self):
        if not self.hasSlideCaseModelButton        :
            self.SlideCaseModelButton         = Qt.QPushButton       (self)

    def initCellModelButton             (self):
        if not self.hasCellModelButton             :
            self.CellModelButton              = Qt.QPushButton       (self)

    def initChamberStatusModelButton    (self):
        if not self.hasChamberStatusModelButton    :
            self.ChamberStatusModelButton     = Qt.QPushButton       (self)

    def initImageModelButton            (self):
        if not self.hasImageModelButton            :
            self.ImageModelButton             = Qt.QPushButton       (self)

    def initDebugModeButton             (self):
        if not self.hasDebugModeButton             :
            self.DebugModeButton              = Qt.QPushButton       (self)

    def initSelectChamber               (self):
        if not self.hasSelectChamber               :
            self.SelectChamber                = SelectChamberView    (self)

    def initScanningChamberButton       (self):
        if not self.hasScanningChamberButton       :
            self.ScanningChamberButton        = Qt.QPushButton       (self)

    def initScanningSlideButton         (self):
        if not self.hasScanningSlideButton         :
            self.ScanningSlideButton          = Qt.QPushButton       (self)























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

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

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

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

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

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

    @property
    def hasLocation                    (self) -> bool:
        return hasattr(self, 'Location'                 ) and isinstance(self.Location                    , SelectLocationView    )

    @property
    def hasPosition                    (self) -> bool:
        return hasattr(self, 'Position'                 ) and isinstance(self.Position                    , SlidePositionView     )

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

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

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

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

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

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

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

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

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

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

    @property
    def hasObjectiveChangedButton      (self) -> bool:
        return hasattr(self, 'ObjectiveChangedButton'   ) and isinstance(self.ObjectiveChangedButton      , MotionChangedView     )

    @property
    def hasXChangedButton              (self) -> bool:
        return hasattr(self, 'XChangedButton'           ) and isinstance(self.XChangedButton              , MotionChangedView     )

    @property
    def hasYChangedButton              (self) -> bool:
        return hasattr(self, 'YChangedButton'           ) and isinstance(self.YChangedButton              , MotionChangedView     )

    @property
    def hasZChangedButton              (self) -> bool:
        return hasattr(self, 'ZChangedButton'           ) and isinstance(self.ZChangedButton              , MotionChangedView     )

    @property
    def hasSelectChamber               (self) -> bool:
        return hasattr(self, 'SelectChamber'            ) and isinstance(self.SelectChamber               , SelectChamberView     )

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

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