def __init__(self, nf_settings_path): super(batch_file_viewer, self).__init__(parent=None) self.nf_settings_parser = custom_config_parser() self.nf_settings_parser.load(nf_settings_path) self.setRowCount(20) self.setColumnCount(2) # Fill all places so there are no "None" types in the table for row in range(self.rowCount()): for column in range(self.columnCount()): item = QTableWidgetItem() item.setText('') self.setItem(row, column, item) self.original_background = item.background() self.clipboard = QGuiApplication.clipboard() self.cellChanged.connect( self.check_cell) # Needs to be after "filling for loop" above self.header = self.horizontalHeader() self.header.setSectionResizeMode(0, QHeaderView.Stretch) self.setHorizontalHeaderLabels(["MS files", "Label"]) self.header.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.header.customContextMenuRequested.connect(self.right_click_menu) self.saved_text = '' self.store_re_text = ''
def on_view_tb_clicked(self): self.table.clear() # 设置表格列数 self.table.setColumnCount(3) # 设置表格行数 self.table.setRowCount(10) # 隐藏水平表头 # self.tableWidget.horizontalHeader().setVisible(False) self.table.setHorizontalHeaderLabels(['时间', '温度', '湿度']) start_date,end_date = self.get_date() try: query = self.conn.show_data(self.sel_name,start_date,end_date) # j表示行数,i表示列数,d表示 j = 0 while query.next(): # 当数据大于默认的行数时,在最后一行加入一个空行 if j >= self.table.rowCount(): self.table.insertRow(j) for i in range(3): if i == 0: newitem = QTableWidgetItem(str(query.value(0).toString('yyyy/M/d h:mm:ss'))) self.table.setItem(j, i, newitem) elif i == 1: newitem = QTableWidgetItem(str(query.value(1))) if query.value(1) >= self.one_high or query.value(1) <= self.one_low: self.bgbruse = newitem.background() newitem.setBackground(QColor(125, 32, 67)) self.table.setItem(j, i, newitem) # 把数字转换成字符串 else: self.table.setItem(j, i, newitem) elif i == 2: newitem = QTableWidgetItem(str(query.value(2))) if query.value(2) >= self.two_high or query.value(2) <= self.two_low: self.bgbruse = newitem.background() newitem.setBackground(QColor(125, 32, 67)) self.table.setItem(j, i, newitem) # 把数字转换成字符串 else: self.table.setItem(j, i, newitem) j += 1 self.items = {} # 获取总行数 self.set_items(self.table.rowCount()) d = [] wendu = [] shidu = [] for c in range(self.table.rowCount()): # print(self.table.item(c,0).text()) d.append(self.table.item(c,0).text()) wendu.append(self.table.item(c,1).text()) shidu.append(self.table.item(c,2).text()) # self._static_ax.plot(d,wendu) # self._static_ax.plot(d,shidu) # plt.xticks(rotation=45) # plt.plot(d,[30]*len(wendu)) # plt.plot(d,[10]*len(wendu)) # plt.plot(d, wendu) # # plt.plot(d, shidu) # plt.show() for k,v in self.items.items(): self.table.item(v[2] - 1, 0).setBackground(QColor(255, 0, 0)) self.table.item(v[2], 0).setBackground(QColor(0, 255, 0)) self.statusBar.showMessage(f"总共有 {len(self.items)} 处丢失数据") except BaseException as m: # print(m) # print(type(m)) QMessageBox.information(self, "消息框标题", "请先选择一个需要查询的表", )