main_window_GyBhhy.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from PyQt5.QtCore import QSize, QTimer, Qt
  2. from PyQt5.QtGui import QFont, QBrush, QColor, QPixmap, QCursor
  3. from PyQt5.QtWidgets import QApplication, QMainWindow, QListWidgetItem, QListWidget, QLabel, QMenu
  4. from ui.ui import Ui_MainWindow
  5. class MainWindow(QMainWindow, Ui_MainWindow):
  6. def __init__(self, db, display_number,pagination,task_type):
  7. super().__init__()
  8. self.setupUi(self)
  9. # 设置标题
  10. self.label.setText("碧海花园智能立体停车库流程信息")
  11. # 显示的任务类型
  12. self.task_type = task_type
  13. # 图片以及尺寸
  14. self.image_label.setPixmap(QPixmap('./image/log.jpg'))
  15. self.image_label.setScaledContents(True)
  16. self.image_label.setMaximumHeight(140)
  17. self.image_label.setMaximumWidth(600)
  18. # 数据库操作句柄
  19. self.db = db
  20. # 显示框数量,一般来说有几个单元显示几个
  21. self.display_number = display_number
  22. # 页数
  23. self.pagination = pagination
  24. self.list_widget_dict = {}
  25. self.label_dict = {}
  26. self.command_dict = {}
  27. # 创建listwidget与label 配置多少个单元生成多少对
  28. for i in range(0,self.display_number):
  29. A_ascii = ord('A')
  30. # 设置样式
  31. self.list_widget_dict[i] = QListWidget(self)
  32. self.list_widget_dict[i].setStyleSheet("border:5px solid #014F84;")
  33. self.list_widget_dict[i].setObjectName(('list_widget_%d'%(i+1)))
  34. self.process_horizontalLayout.addWidget(self.list_widget_dict[i])
  35. # 设置单元文本
  36. self.label_dict[i] = QLabel(self)
  37. self.label_dict[i].setText(str(chr(A_ascii+i))+"单元")
  38. self.label_dict[i].setAlignment(Qt.AlignCenter)
  39. self.label_dict[i].setFont(QFont("华文楷体", 60, QFont.Bold))
  40. self.command_dict[i] = []
  41. self.unit_horizontalLayout.addWidget(self.label_dict[i])
  42. self.timer = QTimer()
  43. self.timer.timeout.connect(self.Switch)
  44. self.timer.start(200)
  45. def closeEvent(self, event):
  46. event.accept() # 接受关闭事件
  47. def get_listWidget_item(self, dict):
  48. item = QListWidgetItem()
  49. item.setFont(QFont('微软雅黑', 20, QFont.Bold))
  50. show_str = ""
  51. if dict['type'] == 1:#存车指令
  52. item.setBackground(QColor(185,240,240))
  53. if (dict['statu'] == 0): # 排队
  54. item.setForeground(QColor(80, 80, 80))
  55. show_str = dict['car_number'] + " 存车排队中,请稍等片刻"
  56. elif (dict['statu'] == 1): # 工作
  57. item.setForeground(QColor('blue'))
  58. show_str = dict['car_number'] + " 存车中,等待存车结束"
  59. elif (dict['statu'] == 2): # 已完成
  60. item.setForeground(QColor('green'))
  61. show_str = dict['car_number'] + " 存车已完成"
  62. elif (dict['statu'] == 3): # 已完成
  63. item.setForeground(QColor('red'))
  64. show_str = dict['car_number'] + " 任务故障,请联系管理员!"
  65. show_str = "存 "+show_str
  66. elif dict['type'] == 2:#取车指令
  67. item.setBackground(QColor(250,240,200))
  68. if (dict['statu'] == 0): # 排队
  69. item.setForeground(QColor(80, 80, 80))
  70. show_str = dict['car_number'] + " 取车排队中,请稍等片刻"
  71. elif (dict['statu'] == 1): # 工作
  72. item.setForeground(QColor('blue'))
  73. show_str = dict['car_number'] + " 取车中,等待取车结束"
  74. elif (dict['statu'] == 2): # 已完成
  75. item.setForeground(QColor('green'))
  76. show_str = dict['car_number'] + " 已完成,请到 %d 号出口取车" % (dict["export_id"])
  77. elif (dict['statu'] == 3): # 已完成
  78. item.setForeground(QColor('red'))
  79. show_str = dict['car_number'] + " 任务故障,请联系管理员!"
  80. show_str = "取 "+show_str
  81. item.setText(show_str)
  82. return item
  83. def Switch(self):
  84. # 查询所有指令表
  85. for i in range(0,self.display_number):
  86. if self.task_type != 0:
  87. t_command_dict = self.db.query_command_all_in_unit_type_and_sort((i+1),self.task_type)
  88. else:
  89. t_command_dict = self.db.query_command_all_in_unit_and_sort((i+1))
  90. if self.command_dict[i] != t_command_dict:
  91. self.command_dict[i] = t_command_dict
  92. self.list_widget_dict[i].clear()
  93. for dict in self.command_dict[i]:
  94. self.list_widget_dict[i].addItem(self.get_listWidget_item(dict))