#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：PositionOperation.py
@Description：
@Author：XSH
@Time：2025/11/26 19:36
@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 PositionOperation(Qt.QWidget, UiInterface):
    InfoXPosition       : Qt.QPushButton                #
    EditXPosition       : Qt.QDoubleSpinBox             #
    InfoYPosition       : Qt.QPushButton                #
    EditYPosition       : Qt.QDoubleSpinBox             #
    InfoMPosition       : Qt.QPushButton                #
    EditMPosition       : Qt.QDoubleSpinBox             #
    ReadButton          : Qt.QPushButton                #
    MoveButton          : Qt.QPushButton                #

    def __init__(self, parent: Qt.QObject = None):
        super(PositionOperation, self).__init__(parent=parent)
        self.Initialization('PositionOperation', self, parent)
        self.initWidgetStyle()

    def setMPosition       (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditMPosition       :
            self.EditMPosition       .setValue(float  (value))

    def setXPosition       (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditXPosition       :
            self.EditXPosition       .setValue(float  (value))

    def setYPosition       (self, value: (int, float)):
        if isinstance(value, (int, float)) and self.hasEditYPosition       :
            self.EditYPosition       .setValue(float  (value))

    def getXPosition       (self) -> float  :
        if self.hasEditXPosition       :
            return float  (self.EditXPosition       .value())
        return float  (0)

    def getYPosition       (self) -> float  :
        if self.hasEditYPosition       :
            return float  (self.EditYPosition       .value())
        return float  (0)

    def getMPosition       (self) -> float  :
        if self.hasEditMPosition       :
            return float  (self.EditMPosition       .value())
        return float  (0)

    def initValue(self):
        super(PositionOperation, self).initValue()
        self.initInfoXPosition ()
        self.initEditXPosition ()
        self.initInfoYPosition ()
        self.initEditYPosition ()
        self.initInfoMPosition ()
        self.initEditMPosition ()
        self.initReadButton    ()
        self.initMoveButton    ()


    def initProperty(self):
        super(PositionOperation, self).initProperty()
        self.ReadButton          .setText("当前位置　")
        self.MoveButton          .setText("移动托盘　")
        self.InfoXPosition       .setText('Ｘ轴位置　')
        self.InfoYPosition       .setText('Ｙ轴位置　')
        self.InfoMPosition       .setText('显微镜位置')
        self.EditXPosition       .setRange(0.0, 155.0)
        self.EditYPosition       .setRange(0.0, 155.0)
        self.EditMPosition       .setRange(0.0, 25000000.0)
        self.EditXPosition       .setSingleStep(0.01        )
        self.EditYPosition       .setSingleStep(0.01        )
        self.EditMPosition       .setSingleStep(10000.0   )

        self.InfoXPosition       .setFixedHeight(40)
        self.EditXPosition       .setFixedHeight(40)
        self.InfoYPosition       .setFixedHeight(40)
        self.EditYPosition       .setFixedHeight(40)
        self.InfoMPosition       .setFixedHeight(40)
        self.EditMPosition       .setFixedHeight(40)
        self.ReadButton          .setFixedHeight(40)
        self.MoveButton          .setFixedHeight(40)

    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        main_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        row1: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row2: Qt.QHBoxLayout = Qt.QHBoxLayout()
        main_layout.setSpacing(2)
        main_layout.setContentsMargins(10, 2, 10, 2)

        row1.setSpacing(2)
        row1.setContentsMargins(10, 2, 10, 2)

        row2.setSpacing(2)
        row2.setContentsMargins(10, 2, 10, 2)

        row1.addWidget(self.InfoXPosition   )
        row1.addWidget(self.EditXPosition   )
        row1.addWidget(self.InfoYPosition   )
        row1.addWidget(self.EditYPosition   )
        row2.addWidget(self.InfoMPosition   )
        row2.addWidget(self.EditMPosition   )
        row2.addWidget(self.ReadButton      )
        row2.addWidget(self.MoveButton      )
        main_layout.addLayout(row1)
        main_layout.addLayout(row2)
        self.setLayout(main_layout)
    def initInfoXPosition       (self):
        if not self.hasInfoXPosition       :
            self.InfoXPosition        = Qt.QPushButton       ()
    def initEditXPosition       (self):
        if not self.hasEditXPosition       :
            self.EditXPosition        = Qt.QDoubleSpinBox    ()
    def initInfoYPosition       (self):
        if not self.hasInfoYPosition       :
            self.InfoYPosition        = Qt.QPushButton       ()
    def initEditYPosition       (self):
        if not self.hasEditYPosition       :
            self.EditYPosition        = Qt.QDoubleSpinBox    ()
    def initInfoMPosition       (self):
        if not self.hasInfoMPosition       :
            self.InfoMPosition        = Qt.QPushButton       ()
    def initEditMPosition       (self):
        if not self.hasEditMPosition       :
            self.EditMPosition        = Qt.QDoubleSpinBox    ()
    def initReadButton          (self):
        if not self.hasReadButton          :
            self.ReadButton           = Qt.QPushButton       ()
    def initMoveButton          (self):
        if not self.hasMoveButton          :
            self.MoveButton           = Qt.QPushButton       ()





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

    @property
    def hasEditXPosition (self) -> bool:
        return hasattr(self, 'EditXPosition'     ) and isinstance(self.EditXPosition , Qt.QDoubleSpinBox )

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

    @property
    def hasEditYPosition (self) -> bool:
        return hasattr(self, 'EditYPosition'     ) and isinstance(self.EditYPosition , Qt.QDoubleSpinBox )

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

    @property
    def hasEditMPosition (self) -> bool:
        return hasattr(self, 'EditMPosition'     ) and isinstance(self.EditMPosition , Qt.QDoubleSpinBox )

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

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

    pass