import sys sys.path.append("..") import mytool.db_helper.db_operation as spmng from PyQt5.QtCore import QSize, QTimer, Qt from PyQt5.QtGui import QFont, QBrush, QColor, QPixmap from PyQt5.QtWidgets import QApplication, QMainWindow, QListWidgetItem, QListWidget, QLabel from ui.ui import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, display_number,unit,task_type,db_config): super().__init__() self.setupUi(self) self.label.setText("上古街智能立体停车库取车排队信息") self.setWindowFlags(Qt.FramelessWindowHint) self.task_type = task_type self.image_label.setPixmap(QPixmap('./image/log.jpg')) self.image_label.setScaledContents(True) self.image_label.setMaximumHeight(140) self.image_label.setMaximumWidth(600) self.db =spmng.DBOperation(db_config['db_ip'],db_config['db_port'],db_config['db_name'],db_config['db_user'],db_config['db_password']) self.display_number = display_number unit_dict = {'A':[11,12,13],'B':[21,22,23,24,25],'C':[31,32]} self.unit_list = unit_dict[unit] self.list_widget_dict = {} self.label_dict = {} self.command_dict = {} # 创建listwidget与label 配置多少个单元生成多少对 for i in self.unit_list: self.list_widget_dict[i] = QListWidget(self) self.list_widget_dict[i].setStyleSheet("border:5px solid #014F84;") self.list_widget_dict[i].setObjectName(('list_widget_%d'%(i+1))) self.process_horizontalLayout.addWidget(self.list_widget_dict[i]) self.label_dict[i] = QLabel(self) self.label_dict[i].setText(unit+str((i%10))) self.label_dict[i].setAlignment(Qt.AlignCenter) self.label_dict[i].setFont(QFont("华文楷体", 60, QFont.Bold)) self.command_dict[i] = [] self.unit_horizontalLayout.addWidget(self.label_dict[i]) self.timer = QTimer() self.timer.timeout.connect(self.Switch) self.timer.start(200) def closeEvent(self, event): event.accept() # 接受关闭事件 def get_listWidget_item(self, dict): item = QListWidgetItem() item.setFont(QFont('微软雅黑', 17, QFont.Bold)) show_str = "" if dict['type'] == 1:#存车指令 item.setBackground(QColor(185,240,240)) if (dict['statu'] == 0): # 排队 item.setForeground(QColor(80, 80, 80)) show_str = dict['car_number'] + " 排队中,请稍等片刻" elif (dict['statu'] == 1): # 工作 item.setForeground(QColor('blue')) show_str = dict['car_number'] + " 存车中,等待存车结束" elif (dict['statu'] == 2): # 已完成 item.setForeground(QColor('green')) show_str = dict['car_number'] + " 存车已完成" elif (dict['statu'] == 3): # 已完成 item.setForeground(QColor('red')) show_str = dict['car_number'] + " 故障,请联系管理员!" show_str = "存 "+show_str elif dict['type'] == 2:#取车指令 item.setBackground(QColor(250,240,200)) if (dict['statu'] == 0): # 排队 item.setForeground(QColor(80, 80, 80)) show_str = dict['car_number'] + " 排队中,请稍等片刻" elif (dict['statu'] == 1): # 工作 item.setForeground(QColor('blue')) show_str = dict['car_number'] + " 取车中,等待取车结束" elif (dict['statu'] == 2): # 已完成 item.setForeground(QColor('green')) show_str = dict['car_number'] + " 已完成,请到%d号口取车" % (dict["export_id"]) elif (dict['statu'] == 3): # 已完成 item.setForeground(QColor('red')) show_str = dict['car_number'] + " 故障,请联系管理员!" show_str = '取 '+ show_str item.setText(show_str) return item def Switch(self): for i in self.unit_list: if self.task_type != 0: t_command_dict = self.db.query_command_all_in_unit_type_and_sort(i,self.task_type) else: t_command_dict = self.db.query_command_all_in_unit_and_sort(i) if self.command_dict[i] != t_command_dict: self.command_dict[i] = t_command_dict self.list_widget_dict[i].clear() for dict in self.command_dict[i]: if dict['statu'] != 3: self.list_widget_dict[i].addItem(self.get_listWidget_item(dict)) for dict in self.command_dict[i]: if dict['statu'] == 3: self.list_widget_dict[i].addItem(self.get_listWidget_item(dict))