#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ManipulatorController.py
@Description：
@Author：XSH
@Time：2025/11/15 11:10
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                      import Qt
from AppSettings.Settings       import *
from AppCore.Levels             import *
from AppUtils.UiUtils           import UiUtils
from AppUtils.utils                     import *
from AppInterfaces.UiInterface          import UiInterface

class ManipulatorController(Qt.QWidget, UiInterface):
    YPlusButton         : Qt.QPushButton            #
    YMinusButton        : Qt.QPushButton            #
    XPlusButton         : Qt.QPushButton            #
    XMinusButton        : Qt.QPushButton            #
    ZPlusButton         : Qt.QPushButton            #
    ZMinusButton        : Qt.QPushButton            #
    MicPlusButton       : Qt.QPushButton            #
    MicMinusButton      : Qt.QPushButton            #
    HPlusButton         : Qt.QPushButton            #
    HMinusButton        : Qt.QPushButton            #
    ScanCodeButton      : Qt.QPushButton            #
    CodeCompleteButton  : Qt.QPushButton            #
    StepLabel           : Qt.QPushButton            #
    StepEdit            : Qt.QDoubleSpinBox         #
    MicStepLabel        : Qt.QPushButton            #
    MicStepEdit         : Qt.QDoubleSpinBox         #
    ObjectiveLabel      : Qt.QPushButton            #
    ObjectiveEdit       : Qt.QSpinBox               #
    CameraSwitch        : Qt.QPushButton            #
    CameraButton        : Qt.QPushButton            #
    InitXYButton        : Qt.QPushButton            #
    InitZButton         : Qt.QPushButton            #
    InitHButton         : Qt.QPushButton            #
    InitMicButton       : Qt.QPushButton            #
    InitCodeButton      : Qt.QPushButton            #
    InitCameraButton    : Qt.QPushButton  #
    DebugButton         : Qt.QPushButton            #
    GroupBox            : Qt.QGroupBox              #
    OilButton           : Qt.QPushButton            #
    OilSwitch           : bool
    def get_step(self) -> float:
        if self.hasStepEdit:
            return float(round(self.StepEdit.value(), 2))
        return 0.0

    def get_microscope_step(self) -> float:
        if self.hasMicStepEdit:
            return float(round(self.MicStepEdit.value(), 2))
        return 0.0

    def get_objective_value(self) -> int:
        if self.hasObjectiveEdit:
            return abs(int(self.ObjectiveEdit.value()))
        return 1

    def isOilEnabled(self) -> bool:
        if not self.hasOilSwitch:
            self.initOilSwitch()
        return self.OilSwitch

    def setOilEnabled(self, enable: (int, bool)):
        if not self.hasOilSwitch:
            self.initOilSwitch()
        self.OilSwitch = 1 if isinstance(enable, (int, bool)) and enable else 0

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

    def initWidgetStyle(self):
        from AppUtils.UiUtils import UiUtils
        self.setStyleSheet(UiUtils.getTransparentStyle())

    def initValue(self):
        super(ManipulatorController, self).initValue()
        self.initYPlusButton        ()
        self.initYMinusButton       ()
        self.initXPlusButton        ()
        self.initXMinusButton       ()
        self.initZPlusButton        ()
        self.initZMinusButton       ()
        self.initMicPlusButton      ()
        self.initMicMinusButton     ()
        self.initStepLabel          ()
        self.initStepEdit           ()
        self.initMicStepLabel       ()
        self.initMicStepEdit        ()
        self.initGroupBox           ()
        self.initDebugButton        ()
        self.initHPlusButton        ()
        self.initHMinusButton       ()
        self.initScanCodeButton     ()
        self.initCodeCompleteButton ()
        self.initObjectiveLabel     ()
        self.initObjectiveEdit      ()
        self.initCameraSwitch       ()
        self.initCameraButton       ()
        self.initInitXYButton       ()
        self.initInitZButton        ()
        self.initInitHButton        ()
        self.initInitMicButton      ()
        self.initInitCodeButton     ()
        self.initInitCameraButton   ()
        self.initOilSwitch          ()
        self.initOilButton          ()





    def initProperty(self):
        super(ManipulatorController, self).initProperty()
        self.StepLabel          .setText('电机移动步长　')
        self.MicStepLabel       .setText('显微镜移动步长')
        self.DebugButton        .setText('测试按钮')
        self.StepEdit           .setSingleStep(0.01)
        self.MicStepEdit        .setSingleStep(1000)
        self.StepEdit           .setRange(-100.0, 100.0)
        self.MicStepEdit        .setRange(-20000000.0, 20000000.0)
        self.ObjectiveEdit      .setSingleStep  (1)
        self.ObjectiveEdit      .setRange       (1, 7)
        self.MicStepEdit        .setSuffix('mm')
        self.StepEdit           .setSuffix('mm')
        self.ObjectiveLabel     .setText('物镜切换　')
        self.CameraSwitch       .setText('相机开关　')
        self.CameraButton       .setText('十字线画面')

        self.InitXYButton        .setText('初始化ＸＹ　')
        self.InitZButton         .setText('初始化Ｚ　　')
        self.InitHButton         .setText('初始化挂钩　')
        self.InitMicButton       .setText('初始化显微镜')
        self.InitCodeButton      .setText('初始化扫码器')
        self.InitCameraButton    .setText('初始化相机　')

        self.ZPlusButton        .setText("Z+ ▲")
        self.ZMinusButton       .setText("Z- ▼")
        self.MicPlusButton      .setText("M+ ▲")
        self.MicMinusButton     .setText("M- ▼")
        self.YPlusButton        .setText("Y+ ▲")
        self.YMinusButton       .setText("Y- ▼")
        self.XPlusButton        .setText("X+ ▶")
        self.XMinusButton       .setText("X- ◀")
        self.HPlusButton        .setText("H+ ▶")
        self.HMinusButton       .setText("H- ◀")
        self.ScanCodeButton     .setText("扫码")
        self.CodeCompleteButton .setText("拍照")
        self.OilButton          .setText('油泵开关')

        self.ZPlusButton        .setProperty('nav', 'control')
        self.ZMinusButton       .setProperty('nav', 'control')
        self.MicPlusButton      .setProperty('nav', 'control')
        self.MicMinusButton     .setProperty('nav', 'control')
        self.YPlusButton        .setProperty('nav', 'control')
        self.YMinusButton       .setProperty('nav', 'control')
        self.XPlusButton        .setProperty('nav', 'control')
        self.XMinusButton       .setProperty('nav', 'control')

        self.HPlusButton        .setProperty('nav', 'control')
        self.HMinusButton       .setProperty('nav', 'control')
        self.ScanCodeButton     .setProperty('nav', 'control')
        self.CodeCompleteButton .setProperty('nav', 'control')

        self.OilButton          .setStyleSheet(UiUtils.getControlButtonStyle())
        self.ZPlusButton        .setStyleSheet(UiUtils.getControlButtonStyle())
        self.ZMinusButton       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.MicPlusButton      .setStyleSheet(UiUtils.getControlButtonStyle())
        self.MicMinusButton     .setStyleSheet(UiUtils.getControlButtonStyle())
        self.YPlusButton        .setStyleSheet(UiUtils.getControlButtonStyle())
        self.YMinusButton       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.XPlusButton        .setStyleSheet(UiUtils.getControlButtonStyle())
        self.XMinusButton       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.HPlusButton        .setStyleSheet(UiUtils.getControlButtonStyle())
        self.HMinusButton       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.ScanCodeButton     .setStyleSheet(UiUtils.getControlButtonStyle())
        self.CodeCompleteButton .setStyleSheet(UiUtils.getControlButtonStyle())
        self.ObjectiveLabel     .setStyleSheet(UiUtils.getControlButtonStyle())
        self.ObjectiveEdit      .setStyleSheet(UiUtils.getControlButtonStyle())
        self.CameraSwitch       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.CameraButton       .setStyleSheet(UiUtils.getControlButtonStyle())

        self.InitXYButton        .setStyleSheet(UiUtils.getControlButtonStyle())
        self.InitZButton         .setStyleSheet(UiUtils.getControlButtonStyle())
        self.InitHButton         .setStyleSheet(UiUtils.getControlButtonStyle())
        self.InitMicButton       .setStyleSheet(UiUtils.getControlButtonStyle())
        self.InitCodeButton      .setStyleSheet(UiUtils.getControlButtonStyle())
        self.InitCameraButton    .setStyleSheet(UiUtils.getControlButtonStyle())

        self.GroupBox           .setStyleSheet(UiUtils.getGroupBoxStyle())
        self.ZPlusButton        .setFixedSize(70, 70)
        self.ZMinusButton       .setFixedSize(70, 70)
        self.MicPlusButton      .setFixedSize(70, 70)
        self.MicMinusButton     .setFixedSize(70, 70)
        self.YPlusButton        .setFixedSize(70, 70)
        self.YMinusButton       .setFixedSize(70, 70)
        self.XPlusButton        .setFixedSize(70, 70)
        self.XMinusButton       .setFixedSize(70, 70)
        self.HPlusButton        .setFixedSize(70, 70)
        self.HMinusButton       .setFixedSize(70, 70)
        self.ScanCodeButton     .setFixedSize(150, 70)
        self.CodeCompleteButton .setFixedSize(150, 70)

        self.OilButton          .setFixedHeight(40)
        self.StepLabel          .setFixedHeight(40)
        self.MicStepLabel       .setFixedHeight(40)
        self.DebugButton        .setFixedHeight(40)
        self.StepEdit           .setFixedHeight(40)
        self.MicStepEdit        .setFixedHeight(40)
        self.ObjectiveLabel     .setFixedHeight(40)
        self.ObjectiveEdit      .setFixedHeight(40)
        self.CameraSwitch       .setFixedHeight(40)
        self.CameraButton       .setFixedHeight(40)
        self.InitXYButton       .setFixedHeight(40)
        self.InitZButton        .setFixedHeight(40)
        self.InitHButton        .setFixedHeight(40)
        self.InitMicButton      .setFixedHeight(40)
        self.InitCodeButton     .setFixedHeight(40)
        self.InitCameraButton   .setFixedHeight(40)

    def initLayouts(self):
        super(ManipulatorController, self).initLayouts()
        if not self.hasControl or self.layout() is not None:
            return

        box_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        box_layout.setSpacing(2)
        box_layout.setContentsMargins(1, 20, 1, 1)
        # 创建主布局
        main_layout = Qt.QVBoxLayout()
        main_layout.setSpacing(5)
        main_layout.setContentsMargins(1, 1, 1, 1)
        # main_layout.setAlignment(Qt.Qt.AlignTop)
        # 创建三个十字布局的按钮组（横向排列）
        joystick_layout = Qt.QHBoxLayout()
        joystick_layout.setSpacing(5)  # 设置摇杆之间的间距
        joystick_layout.setContentsMargins(5, 5, 5, 5)
        # XY平面按钮组
        xy_layout = Qt.QGridLayout()
        xy_layout.setSpacing(5)  # 设置按钮间距
        xy_layout.setContentsMargins(5, 5, 5, 5)
        # 创建圆形布局
        xy_layout.addWidget(self.YPlusButton    , 0, 1)
        xy_layout.addWidget(self.YMinusButton   , 2, 1)
        xy_layout.addWidget(self.XPlusButton    , 1, 2)
        xy_layout.addWidget(self.XMinusButton   , 1, 0)

        # ZR平面按钮组
        zr_layout = Qt.QGridLayout()
        zr_layout.setSpacing(5)

        # 创建圆形布局
        zr_layout.setContentsMargins(5, 5, 5, 5)
        zr_layout.addWidget(self.ZPlusButton    , 0, 1)
        zr_layout.addWidget(self.ZMinusButton   , 2, 1)
        zr_layout.addWidget(self.MicPlusButton  , 1, 2)
        zr_layout.addWidget(self.MicMinusButton , 1, 0)

        # ZR平面按钮组
        hs_layout = Qt.QGridLayout()
        hs_layout.setSpacing(5)
        # 创建圆形布局
        hs_layout.setContentsMargins(5, 5, 5, 5)
        hs_layout.addWidget(self.ScanCodeButton             , 0, 1)
        hs_layout.addWidget(self.CodeCompleteButton         , 2, 1)
        hs_layout.addWidget(self.HPlusButton                , 1, 2)
        hs_layout.addWidget(self.HMinusButton               , 1, 0)



        # 创建三个容器widget来包含每个圆形布局
        xy_widget = Qt.QWidget()
        xy_widget.setObjectName("xy_widget")
        xy_widget.setLayout(xy_layout)

        zr_widget = Qt.QWidget()
        zr_widget.setObjectName("zr_widget")
        zr_widget.setLayout(zr_layout)

        hs_widget = Qt.QWidget()
        hs_widget.setObjectName("zr_widget")
        hs_widget.setLayout(hs_layout)


        xy_widget.setStyleSheet(UiUtils.getControlWidgetStyle())
        zr_widget.setStyleSheet(UiUtils.getControlWidgetStyle())
        hs_widget.setStyleSheet(UiUtils.getControlWidgetStyle())
        # 添加三个十字布局到横向布局
        joystick_layout.addWidget(xy_widget)
        joystick_layout.addWidget(zr_widget)
        joystick_layout.addWidget(hs_widget)

        # 创建控制面板（横向排列）
        control_panel = Qt.QWidget()
        control_panel_layout: Qt.QVBoxLayout = Qt.QVBoxLayout()
        control_panel_layout.setSpacing(1)
        control_panel_layout.setContentsMargins(2, 2, 2, 2)

        row_1: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_2: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_3: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_4: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_5: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_6: Qt.QHBoxLayout = Qt.QHBoxLayout()
        row_1.setSpacing(1)
        row_1.setContentsMargins(2, 2, 2, 2)
        row_2.setSpacing(1)
        row_2.setContentsMargins(2, 2, 2, 2)

        row_3.setSpacing(1)
        row_3.setContentsMargins(2, 2, 2, 2)

        row_4.setSpacing(1)
        row_4.setContentsMargins(2, 2, 2, 2)

        row_5.setSpacing(1)
        row_5.setContentsMargins(2, 2, 2, 2)

        row_6.setSpacing(1)
        row_6.setContentsMargins(2, 2, 2, 2)

        row_1.addWidget(self.StepLabel          )
        row_1.addWidget(self.StepEdit           )
        row_1.addWidget(self.MicStepLabel       )
        row_1.addWidget(self.MicStepEdit        )

        row_2.addWidget(self.ObjectiveLabel     )
        row_2.addWidget(self.ObjectiveEdit      )
        row_2.addWidget(self.CameraSwitch       )
        row_2.addWidget(self.CameraButton       )


        row_3.addWidget(self.InitXYButton     )
        row_3.addWidget(self.InitZButton      )

        row_4.addWidget(self.InitHButton      )
        row_4.addWidget(self.InitMicButton    )

        row_5.addWidget(self.InitCodeButton   )
        row_5.addWidget(self.InitCameraButton )

        row_6.addWidget(self.DebugButton)
        row_6.addWidget(self.OilButton  )

        control_panel_layout.addLayout(row_1)
        control_panel_layout.addLayout(row_2)
        control_panel_layout.addLayout(row_3)
        control_panel_layout.addLayout(row_4)
        control_panel_layout.addLayout(row_5)
        control_panel_layout.addLayout(row_6)

        control_panel.setLayout(control_panel_layout)
        box_layout.addLayout(joystick_layout)
        box_layout.addWidget(control_panel)
        self.GroupBox.setLayout(box_layout)
        # 添加所有布局到主布局
        main_layout.addWidget(self.GroupBox)
        # 设置主布局
        self.setLayout(main_layout)

    def initYPlusButton         (self):
        if not self.hasYPlusButton         :
            self.YPlusButton         = Qt.QPushButton    ()

    def initYMinusButton        (self):
        if not self.hasYMinusButton        :
            self.YMinusButton        = Qt.QPushButton    ()

    def initXPlusButton         (self):
        if not self.hasXPlusButton         :
            self.XPlusButton         = Qt.QPushButton    ()

    def initXMinusButton        (self):
        if not self.hasXMinusButton        :
            self.XMinusButton        = Qt.QPushButton    ()

    def initZPlusButton         (self):
        if not self.hasZPlusButton         :
            self.ZPlusButton         = Qt.QPushButton    ()

    def initZMinusButton        (self):
        if not self.hasZMinusButton        :
            self.ZMinusButton        = Qt.QPushButton    ()

    def initMicPlusButton       (self):
        if not self.hasMicPlusButton       :
            self.MicPlusButton       = Qt.QPushButton    ()

    def initMicMinusButton      (self):
        if not self.hasMicMinusButton      :
            self.MicMinusButton      = Qt.QPushButton    ()

    def initStepLabel           (self):
        if not self.hasStepLabel           :
            self.StepLabel           = Qt.QPushButton    ()

    def initStepEdit            (self):
        if not self.hasStepEdit            :
            self.StepEdit            = Qt.QDoubleSpinBox ()

    def initMicStepLabel        (self):
        if not self.hasMicStepLabel        :
            self.MicStepLabel        = Qt.QPushButton    ()

    def initMicStepEdit         (self):
        if not self.hasMicStepEdit         :
            self.MicStepEdit         = Qt.QDoubleSpinBox ()

    def initGroupBox            (self):
        if not self.hasGroupBox            :
            self.GroupBox            = Qt.QGroupBox      ()

    def initDebugButton(self):
        if not self.hasDebugButton:
            self.DebugButton = Qt.QPushButton()

    def initHPlusButton        (self):
        if not self.hasHPlusButton       :
            self.HPlusButton        = Qt.QPushButton()

    def initHMinusButton       (self):
        if not self.hasHMinusButton      :
            self.HMinusButton       = Qt.QPushButton()

    def initScanCodeButton     (self):
        if not self.hasScanCodeButton    :
            self.ScanCodeButton     = Qt.QPushButton()

    def initCodeCompleteButton (self):
        if not self.hasCodeCompleteButton:
            self.CodeCompleteButton = Qt.QPushButton()

    def initObjectiveLabel     (self):
        if not self.hasObjectiveLabel     :
            self.ObjectiveLabel      = Qt.QPushButton()

    def initObjectiveEdit      (self):
        if not self.hasObjectiveEdit      :
            self.ObjectiveEdit       = Qt.QSpinBox   ()

    def initCameraSwitch       (self):
        if not self.hasCameraSwitch       :
            self.CameraSwitch        = Qt.QPushButton()

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

    def initInitXYButton(self):
        if not self.hasInitXYButton:
            self.InitXYButton = Qt.QPushButton()

    def initInitZButton        (self):
        if not self.hasInitZButton        :
            self.InitZButton         = Qt.QPushButton()
    def initInitHButton        (self):
        if not self.hasInitHButton        :
            self.InitHButton         = Qt.QPushButton()
    def initInitMicButton      (self):
        if not self.hasInitMicButton      :
            self.InitMicButton       = Qt.QPushButton()
    def initInitCodeButton     (self):
        if not self.hasInitCodeButton     :
            self.InitCodeButton      = Qt.QPushButton()
    def initInitCameraButton   (self):
        if not self.hasInitCameraButton   :
            self.InitCameraButton    = Qt.QPushButton()

    def initOilButton(self):
        if not self.hasOilButton:
            self.OilButton = Qt.QPushButton()

    def initOilSwitch(self):
        if not self.hasOilSwitch:
            self.OilSwitch = False

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

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

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

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

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

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

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

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

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

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

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

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

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

    @property
    def hasGroupBox            (self) -> bool:
        return hasattr(self, 'GroupBox'      ) and isinstance(self.GroupBox            , Qt.QGroupBox     )





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

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

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

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






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

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

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

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

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

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

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

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

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

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

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

    @property
    def hasOilSwitch(self) -> bool:
        return hasattr(self, 'OilSwitch') and isinstance(self.OilSwitch, (int, bool)             )
