#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :statusbar.py
@时间    :2022/01/22 09:55:34
@作者    :None
@版本    :1.0
@说明    :状态栏页面
'''


from utils.qt import QStatusBar, QLabel, QFrame, QProgressBar, QMetaObject, QCoreApplication, QRadioButton, QButtonGroup, Qt
from utils.globalvar import SD
from ui.own.led import Led


class UiStatusBar(object):
    def setupUi(self, bms_status):
        self.statusbar = QStatusBar()

        # bms软件版本号
        self.lb_bms_version = QLabel()
        self.lb_bms_version.setFrameStyle(QFrame.Panel | QFrame.Raised)
        self.lb_bms_version.setLineWidth(3)
        self.lb_bms_version.setMidLineWidth(3)

        #本地时间
        self.lb_local_time = QLabel()
        self.lb_local_time.setFrameStyle(QFrame.Panel | QFrame.Raised)
        self.lb_local_time.setLineWidth(3)
        self.lb_local_time.setMidLineWidth(3)

        # bms连接状态
        self.label_bms_connect = QLabel()
        self.label_bms_connect.setFrameStyle(QFrame.Panel | QFrame.Raised)
        self.label_bms_connect.setLineWidth(3)
        self.label_bms_connect.setMidLineWidth(3)

        # BMS：SN
        self.lb_bms_sn = QLabel()
        self.lb_bms_sn.setFrameStyle(QFrame.Panel | QFrame.Raised)
        self.lb_bms_sn.setLineWidth(3)
        self.lb_bms_sn.setMidLineWidth(3)

        self.lb_strech = QLabel("     ")

        self.bms_upgrade_status = QProgressBar()
        self.bms_upgrade_status.setProperty("value", 0)
        self.bms_upgrade_status.setVisible(0)

        # self.led_status_normal = Led(self.statusbar)
        # self.lb_bms_normal = QLabel()
        # self.lb_bms_normal.setFrameStyle(QFrame.Panel | QFrame.Raised)
        # self.lb_bms_normal.setLineWidth(3)
        # self.lb_bms_normal.setMidLineWidth(3)
        self.qbg_status = QButtonGroup()
        self.qrb_status_normal = QRadioButton()
        self.qrb_status_normal.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.qrb_status_normal.setFocusPolicy(Qt.NoFocus)
        self.qrb_status_warnest = QRadioButton()
        self.qrb_status_warnest.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.qrb_status_warnest.setFocusPolicy(Qt.NoFocus)
        self.qrb_status_warner = QRadioButton()
        self.qrb_status_warner.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.qrb_status_warner.setFocusPolicy(Qt.NoFocus)
        self.qrb_status_warn = QRadioButton()
        self.qrb_status_warn.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.qrb_status_warn.setFocusPolicy(Qt.NoFocus)
        self.qbg_status.addButton(self.qrb_status_normal, 0)
        self.qbg_status.addButton(self.qrb_status_warnest, 1)
        self.qbg_status.addButton(self.qrb_status_warner, 2)
        self.qbg_status.addButton(self.qrb_status_warn, 3)
        # self.qrb_status_normal.setText("正常")
        # self.lb_bms_normal = QLabel()
        # self.lb_bms_normal.setFrameStyle(QFrame.Panel | QFrame.Raised)
        # self.lb_bms_normal.setLineWidth(3)
        # self.lb_bms_normal.setMidLineWidth(3)

        # self.led_status_normal = Led(self.statusbar)
        # self.lb_bms_normal = QLabel()
        # self.lb_bms_normal.setFrameStyle(QFrame.Panel | QFrame.Raised)
        # self.lb_bms_normal.setLineWidth(3)
        # self.lb_bms_normal.setMidLineWidth(3)

        # self.led_status_normal = Led(self.statusbar)
        # self.lb_bms_normal = QLabel()
        # self.lb_bms_normal.setFrameStyle(QFrame.Panel | QFrame.Raised)
        # self.lb_bms_normal.setLineWidth(3)
        # self.lb_bms_normal.setMidLineWidth(3)

        # 往状态栏中添加组件（stretch应该是拉伸组件宽度）
        self.statusbar.addWidget(self.lb_bms_version, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addWidget(self.lb_local_time, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addWidget(self.label_bms_connect, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addWidget(self.lb_bms_sn, stretch=0)
        # self.statusbar.addWidget(self.label_bms_received, stretch=0)

        self.statusbar.addPermanentWidget(self.qrb_status_normal, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addPermanentWidget(self.qrb_status_warnest, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addPermanentWidget(self.qrb_status_warner, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        self.statusbar.addPermanentWidget(self.qrb_status_warn, stretch=0)
        # self.statusbar.addWidget(self.lb_strech, stretch=0)
        # self.statusbar.addPermanentWidget(self.lb_bms_normal, stretch=0)
        self.statusbar.addPermanentWidget(self.bms_upgrade_status, stretch=0)


        self.statusbar.setSizeGripEnabled(False)

        self.retranslateUi(bms_status)
        QMetaObject.connectSlotsByName(bms_status)

    def retranslateUi(self, bms_status):
        _translate = QCoreApplication.translate
        self.label_bms_connect.setText(_translate("bms_status", "通讯未连接" if SD.SYSTEM_LANGUAGE == 0 else "Not Connected"))
        self.lb_bms_sn.setText(_translate("bms_status", "BATSN:EM0123456"))
        self.qrb_status_normal.setText(_translate("bms_status", "正常" if SD.SYSTEM_LANGUAGE == 0 else "Normal"))
        self.qrb_status_warnest.setText(_translate("bms_status", "三级告警" if SD.SYSTEM_LANGUAGE == 0 else "Warnest"))
        self.qrb_status_warner.setText(_translate("bms_status", "二级告警" if SD.SYSTEM_LANGUAGE == 0 else "Warner"))
        self.qrb_status_warn.setText(_translate("bms_status", "一级告警" if SD.SYSTEM_LANGUAGE == 0 else "Warn/Fault"))
