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


from ui.main.main import Main
from ui.own.frame_theme import MyFrame
from ui.own.my_chart_view import MyChartView
from utils.globalvar import SD
from utils.qt import QMessageBox, QChart, QValueAxis, QHBoxLayout, QPainter, Qt, Signal, Slot, QLegendMarker


class Win_Main(Main, MyFrame):

    up_signal = Signal()
    down_signal = Signal()
    controll_signal = Signal(int)
    do1_signal = Signal(int)
    do2_signal = Signal(int)
    do3_signal = Signal(int)
    do4_signal = Signal(int)
    do5_signal = Signal(int)
    do6_signal = Signal(int)
    do7_signal = Signal(int)
    do8_signal = Signal(int)

    fault_release_signal = Signal(int)
    jy_signal = Signal(int)
    jy_one_signal = Signal(int)
    chg_mos_signal = Signal(int)
    dchg_mos_signal = Signal(int)
    pre_mos_signal = Signal(int)
    gjd1_signal = Signal(int)
    gjd2_signal = Signal(int)
    chg_signal = Signal(int)
    sleep_signal = Signal(int)
    reset_signal = Signal(int)
    clear_balance_signal = Signal(int)
    fan_signal = Signal(int)

    def __init__(self, parent=None):
        super(Win_Main, self).__init__(parent)
        self.setupUi(self)

        self.under_widget.btn_up.clicked.connect(self._sys_up)
        self.under_widget.btn_down.clicked.connect(self._sys_down)
        self.under_widget.snkz_check_box.stateChanged.connect(self._controll_sys)
        self.under_widget.p_check_box.stateChanged.connect(self._do1)
        self.under_widget.n_check_box.stateChanged.connect(self._do2)
        self.under_widget.pre_check_box.stateChanged.connect(self._do3)
        self.under_widget.center_check_box.stateChanged.connect(self._do4)
        self.under_widget.dlq_check_box.stateChanged.connect(self._do5)
        self.under_widget.do6_check_box.stateChanged.connect(self._do6)
        self.under_widget.do7_check_box.stateChanged.connect(self._do7)
        self.under_widget.do8_check_box.stateChanged.connect(self._do8)

        self.under_widget.fault_check_box.stateChanged.connect(self._fault)
        self.under_widget.again_check_box.stateChanged.connect(self._against)
        self.under_widget.again_one_check_box.stateChanged.connect(self._again_one)
        self.under_widget.chg_check_box.stateChanged.connect(self._chg)
        self.under_widget.dchg_check_box.stateChanged.connect(self._dchg)
        self.under_widget.pre_check_box.stateChanged.connect(self._pre)
        self.under_widget.gjd1_check_box.stateChanged.connect(self._gjd1)
        self.under_widget.gjd2_check_box.stateChanged.connect(self._gjd2)
        self.under_widget.qiangzhi_chg_check_box.stateChanged.connect(self._qiangzhi_chg)
        self.under_widget.sleep_check_box.stateChanged.connect(self._sleep)
        self.under_widget.reset_check_box.stateChanged.connect(self._reset)
        self.under_widget.clear_balance_check_box.stateChanged.connect(self._clear)
        self.under_widget.fan_check_box.stateChanged.connect(self._fan)


    def _sys_up(self):
        self.up_signal.emit()


    def _sys_down(self):
        self.down_signal.emit()


    def _controll_sys(self, data):
        self.controll_signal.emit(data)


    def _do1(self, data):
        self.do1_signal.emit(data)


    def _do2(self, data):
        self.do2_signal.emit(data)


    def _do3(self, data):
        self.do3_signal.emit(data)


    def _do4(self, data):
        self.do4_signal.emit(data)


    def _do5(self, data):
        self.do5_signal.emit(data)


    def _do6(self, data):
        self.do6_signal.emit(data)


    def _do7(self, data):
        self.do7_signal.emit(data)


    def _do8(self, data):
        self.do8_signal.emit(data)        


    def _fault(self, data):
        self.fault_release_signal.emit(data)


    def _against(self, data):
        self.jy_signal.emit(data)


    def _again_one(self, data):
        self.jy_one_signal.emit(data)


    def _chg(self, data):
        self.chg_mos_signal.emit(data)


    def _dchg(self, data):
        self.dchg_mos_signal.emit(data)


    def _pre(self, data):
        self.pre_mos_signal.emit(data)


    def _gjd1(self, data):
        self.gjd1_signal.emit(data)


    def _gjd2(self, data):
        self.gjd2_signal.emit(data)


    def _qiangzhi_chg(self, data):
        self.chg_signal.emit(data)


    def _sleep(self, data):
        self.sleep_signal.emit(data)


    def _reset(self, data):
        self.reset_signal.emit(data)

    def _clear(self, data):
        self.clear_balance_signal.emit(data)


    def _fan(self, data):
        self.fan_signal.emit(data)


    def can_connect_error(self):
        QMessageBox.critical(self, "连接状态" if SD.SYSTEM_LANGUAGE == 0 else "Connect State", "CAN 连接失败！" if SD.SYSTEM_LANGUAGE == 0 else "CAN Connect Error！")
