#!/usr/bin/env python
# -*- encoding: utf-8 -*-


from ui.own.frame_theme import MyFrame
from ui.statusbar import UiStatusBar
from utils.globalvar import SD
from utils.qt import QMessageBox, QFileDialog, QTimer, QDateTime


class Win_Bms_Status_Bar(UiStatusBar, MyFrame):
    def __init__(self, parent=None):
        super(Win_Bms_Status_Bar, self).__init__(parent)
        self.setupUi(self)
        self.lb_bms_version.setText("V" + ''.join((str(SD.MAJOR_VERSION_NUMBER), '.', str(SD.MINOR_VERSION_NUMBER))))

        self.timer = QTimer()
        self.timer.timeout.connect(self._show_local_data_time)
        self.timer.start(1000)
        self._show_local_data_time()

    def _show_local_data_time(self):
        dataTime = QDateTime.currentDateTime()
        text = dataTime.toString("yyyy-MM-dd HH:mm:ss")
        self.lb_local_time.setText(text)

    def bms_error(self):
        QMessageBox.warning(self, "警告" if SD.SYSTEM_LANGUAGE == 0 else "Warning", "请连接BMS！" if SD.SYSTEM_LANGUAGE == 0 else "No BMS！")

    def h86_error(self):
        QMessageBox.critical(self, "错误" if SD.SYSTEM_LANGUAGE == 0 else "Error", "不是标准的h86文件！" if SD.SYSTEM_LANGUAGE == 0 else "H86 Error！")

    def hex_error(self):
        QMessageBox.critical(self, "错误" if SD.SYSTEM_LANGUAGE == 0 else "Error", "不是标准的hex文件！" if SD.SYSTEM_LANGUAGE == 0 else "Hex Error！")

    def s19_error(self):
        QMessageBox.critical(self, "错误" if SD.SYSTEM_LANGUAGE == 0 else "Error", "不是标准的s19文件！" if SD.SYSTEM_LANGUAGE == 0 else "S19 Error！")

    def bmu_can_file(self):
        return QFileDialog.getOpenFileName(self, "选取文件" if SD.SYSTEM_LANGUAGE == 0 else "Chose File", SD.FILE_PATH, "Text Files (*.hex)")

    def ccu_can_file(self):
        return QFileDialog.getOpenFileName(self, "选取文件" if SD.SYSTEM_LANGUAGE == 0 else "Chose File", SD.FILE_PATH, "Text Files (*.h86 , *.hex , *.s19)")

    def bams_can_file(self):
        return QFileDialog.getOpenFileName(self, "选取文件" if SD.SYSTEM_LANGUAGE == 0 else "Chose File", SD.FILE_PATH, "Text Files (*.hex)")

    def bams_net_file(self):
        return QFileDialog.getOpenFileName(self, "选取文件" if SD.SYSTEM_LANGUAGE == 0 else "Chose File", SD.FILE_PATH, "Text Files (*.bin)")
