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

import os
from ui.own.frame_theme import MyFrame
from utils.globalvar import SD
from ui.own.led import Led
from ui.own.switch_button import SwitchButton
from ui.own.palette_theme import set_my_palette
from utils.qt import Qt, QWidget, QVBoxLayout, QHBoxLayout, QStackedWidget, QPixmap, QLabel, QGroupBox, QRect, QPushButton, QSizePolicy, QLineEdit, QTabWidget, QComboBox, QPlainTextEdit, QSize, QCoreApplication, QMetaObject, QIcon
from utils.resource import resource_path


class UiBmsHomePage(object):
    def setupUi(self, main):
        main.resize(1366, 768)
        main.setMinimumSize(1366, 768)

        # main.resize(1920, 1080)
        # main.setMinimumSize(1920, 1080)

        set_my_palette(main)

        self.central_widget = QWidget(main)
        self.main_layout = QVBoxLayout(self.central_widget)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.setSpacing(0)

        # 主窗口上侧布局
        self.top_widget = QWidget(self.central_widget)

        # 主窗口上采用水平布局
        self.top_layout = QHBoxLayout(self.top_widget)
        self.top_layout.setContentsMargins(0, 0, 0, 0)
        self.top_layout.setSpacing(0)

        self.label = QLabel(self.top_widget)
        self.label.setText("")
        self.label.setTextFormat(Qt.RichText)
        self.label.setPixmap(QPixmap(resource_path(os.path.join("assets", "logo.png"))))
        self.label.setScaledContents(False)
        self.top_layout.addWidget(self.label)  

        self.top_layout.addStretch() 

        self.btn_start = QPushButton("启动")
        self.btn_start.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "start.png")))))
        self.top_layout.addWidget(self.btn_start)  

        self.top_layout.addStretch() 

        self.btn_stop = QPushButton("停止")
        self.btn_stop.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "stop.png")))))
        self.top_layout.addWidget(self.btn_stop)  

        self.top_layout.addStretch() 

        self.btn_cut = QPushButton("截图")
        self.btn_cut.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "cut.png")))))
        self.top_layout.addWidget(self.btn_cut)

        self.top_layout.addStretch() 

        self.label_lb = QLabel("当前在线主控: ")
        self.top_layout.addWidget(self.label_lb)
        self.edt_online = QLineEdit()
        self.edt_online.setReadOnly(True)
        self.edt_online.setFixedWidth(500)
        self.top_layout.addWidget(self.edt_online)

        self.top_layout.addStretch() 

        self.zkc = QLabel("主控选择:")
        self.top_layout.addWidget(self.zkc)
        self.cb_bcu = QComboBox()
        for i in range(15):
            self.cb_bcu.addItem("BMU" + str(i + 1))
        self.top_layout.addWidget(self.cb_bcu)

        self.top_layout.addStretch() 

        self.ckc = QLabel("从控选择:")
        self.top_layout.addWidget(self.ckc)
        self.cb_bmu = QComboBox()
        for i in range(15):
            self.cb_bmu.addItem("CMU" + str(i + 1))
        self.top_layout.addWidget(self.cb_bmu)

        self.top_layout.addStretch() 

        self.main_layout.addWidget(self.top_widget, 1)

        # 主窗口下侧布局
        self.under_widget = QWidget(self.central_widget)

        # 主窗口下采用水平布局
        self.under_layout = QHBoxLayout(self.under_widget)
        self.under_layout.setContentsMargins(0, 0, 0, 0)
        self.under_layout.setSpacing(0)

        # 主窗口下左侧布局
        self.under_left_widget = QWidget(self.under_widget)

        # 主窗口左侧采用垂直布局
        self.under_left_layout = QVBoxLayout(self.under_left_widget)
        self.under_left_layout.setContentsMargins(0, 0, 0, 0)
        self.under_left_layout.setSpacing(0)


        self.btn_main_control = QPushButton(self.under_left_widget)
        self.btn_main_control.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "home.png")))))
        self.btn_main_control.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_main_control)

        self.btn_cell_inf = QPushButton(self.under_left_widget)
        self.btn_cell_inf.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "cell.png")))))
        self.btn_cell_inf.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_cell_inf)

        self.btn_double_ccu = QPushButton(self.under_left_widget)
        self.btn_double_ccu.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "bcu.png")))))
        self.btn_double_ccu.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_double_ccu)

        self.btn_protect_inf = QPushButton(self.under_left_widget)
        self.btn_protect_inf.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "protect.png")))))
        self.btn_protect_inf.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_protect_inf)

        self.btn_hard_cali = QPushButton(self.under_left_widget)
        self.btn_hard_cali.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "hard.png")))))
        self.btn_hard_cali.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_hard_cali)

        self.btn_balance_inf = QPushButton(self.under_left_widget)
        self.btn_balance_inf.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "balance.png")))))
        self.btn_balance_inf.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_balance_inf)

        self.btn_data_inf = QPushButton(self.under_left_widget)
        self.btn_data_inf.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "data.png")))))
        self.btn_data_inf.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_data_inf)

        self.btn_download = QPushButton(self.under_left_widget)
        self.btn_download.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "download.png")))))
        self.btn_download.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_download)

        self.btn_set_inf = QPushButton(self.under_left_widget)
        self.btn_set_inf.setIcon(QIcon(QPixmap(resource_path(os.path.join("assets/icon", "set.png")))))
        self.btn_set_inf.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.under_left_layout.addWidget(self.btn_set_inf)

        self.under_layout.addWidget(self.under_left_widget, 1)

        self.under_right_widget = QWidget(self.central_widget)

        self.under_right_layout = QVBoxLayout(self.under_right_widget)
        self.under_right_layout.setContentsMargins(0, 0, 0, 0)
        self.under_right_layout.setSpacing(0)

        self.bms_tab = QStackedWidget(self.under_right_widget)
        self.under_right_layout.addWidget(self.bms_tab)

        self.under_layout.addWidget(self.under_right_widget, 9)

        self.main_layout.addWidget(self.under_widget, 9)

        main.setCentralWidget(self.central_widget)

        self.retranslateUi(main)
        QMetaObject.connectSlotsByName(main)

    def retranslateUi(self, MainWindow):
        _translate = QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "EnergyMath"))
        # self.groupbox_bms_log.setTitle(_translate("MainWindow", "连接状态"))
        self.btn_main_control.setText("主控信息")
        self.btn_cell_inf.setText("单体信息")
        self.btn_double_ccu.setText("并簇信息")
        self.btn_protect_inf.setText("保护参数")
        self.btn_hard_cali.setText("硬件校准")
        self.btn_balance_inf.setText("均衡状态")
        self.btn_data_inf.setText("数据记录")
        self.btn_download.setText("下载调试")
        self.btn_set_inf.setText("设置")