from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import coder_params as cpars




class check_dlog(QObject):

    def __init__(self,father:QDialog,slave_num:int,txt:str) -> None:
        QObject.__init__(self)
        self.slave_num=slave_num
        self.x_size=100*self.slave_num
        if(self.x_size>1500):
            self.x_size=1500
        self.w=QDialog(father)
        self.w.resize(self.x_size+100,200)
        self.w.setWindowTitle(txt)
        self.w.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
        self.code_list=QTableWidget(self.w)
        self.code_list.setObjectName(u"code_list")
        self.code_list.setGeometry(QRect(50, 50, self.x_size, 100))
        self.code_list.setColumnCount(self.slave_num)
        self.code_list.insertRow(0)
        channel_list=[]
        for i in range(self.slave_num):
            channel_list.append("通道{d}".format(d=i+1))
        self.code_list.setHorizontalHeaderLabels(channel_list)
        self.code_list.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)

    def ack_list_init(self,ack_list:list):
        length=len(ack_list)
        for i in range(length):
            self.code_list.setItem(0,i,QTableWidgetItem(cpars.code_errinfo(int(ack_list[i]))))
            if(ack_list[i]!="0"):
                self.code_list.item(0,i).setBackground(Qt.GlobalColor.red)
    def show(self):
        self.w.show()
    def close(self):
        self.w.destroy(True,True)

