168 lines
6.3 KiB
Python
168 lines
6.3 KiB
Python
|
# coding: gb2312
|
|||
|
from PyQt5.QtGui import QColor
|
|||
|
from PyQt5.QtWidgets import *
|
|||
|
from LSZXPagesManagerLibrary.consensus import *
|
|||
|
from PyQt5.QtCore import Qt
|
|||
|
|
|||
|
|
|||
|
class ConventionBox(QWidget):
|
|||
|
def __init__(self):
|
|||
|
super().__init__()
|
|||
|
self.data_list = []
|
|||
|
self.header_type_table = HEADER_TYPE_TABLE
|
|||
|
self.column_names = ['<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'Ѫ<EFBFBD><EFBFBD>', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>']
|
|||
|
|
|||
|
self.item_widget = self._init_item_widget()
|
|||
|
self.item_title = self._init_item_title()
|
|||
|
|
|||
|
self.table_widget = self.init_table_widget()
|
|||
|
self.empty_label = self.init_empty_label()
|
|||
|
self.table_stacked_widget = self.init_table_stacked_widget()
|
|||
|
|
|||
|
self.main_layout = QVBoxLayout()
|
|||
|
self.main_layout.setContentsMargins(10, 0, 10, 0)
|
|||
|
self.main_layout.addWidget(self.item_title, 6)
|
|||
|
self.main_layout.addWidget(self.table_stacked_widget, 94)
|
|||
|
self.item_widget.setLayout(self.main_layout)
|
|||
|
|
|||
|
self.layout = QHBoxLayout()
|
|||
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
|||
|
self.layout.addWidget(self.item_widget)
|
|||
|
self.setLayout(self.layout)
|
|||
|
|
|||
|
def set_data(self, title, data):
|
|||
|
self.item_title.setText(title)
|
|||
|
self.data_list = data
|
|||
|
if len(self.data_list) > 0:
|
|||
|
self.table_stacked_widget.addWidget(self.table_widget)
|
|||
|
self.draw_table()
|
|||
|
else:
|
|||
|
self.table_stacked_widget.addWidget(self.empty_label)
|
|||
|
|
|||
|
def draw_table(self):
|
|||
|
self.table_widget.setColumnCount(len(self.column_names))
|
|||
|
self.table_widget.setHorizontalHeaderLabels(self.column_names)
|
|||
|
self.table_widget.setRowCount(len(self.data_list))
|
|||
|
for row_index, row_data in enumerate(self.data_list):
|
|||
|
row_color = QColor("white") # <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
|||
|
if int(row_data['hr']) < 90:
|
|||
|
row_color = QColor("red") # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD> 90<39><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
|||
|
for col_index, col_name in enumerate(self.column_names):
|
|||
|
item = QTableWidgetItem()
|
|||
|
if col_name == self.header_type_table[NAME]:
|
|||
|
value = row_data['name']
|
|||
|
elif col_name == self.header_type_table[ID]:
|
|||
|
value = str(row_data['id'])
|
|||
|
elif col_name == self.header_type_table[HR]:
|
|||
|
value = str(row_data['hr'])
|
|||
|
elif col_name == self.header_type_table[BO]:
|
|||
|
value = str(row_data['bo'])
|
|||
|
elif col_name == self.header_type_table[COUNT]:
|
|||
|
value = str(row_data['count'])
|
|||
|
else:
|
|||
|
value = ""
|
|||
|
item.setText(value)
|
|||
|
item.setTextAlignment(Qt.AlignCenter) # <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>
|
|||
|
item.setForeground(row_color) # <20><><EFBFBD>õ<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
self.table_widget.setItem(row_index, col_index, item)
|
|||
|
|
|||
|
# <20><><EFBFBD>ñ<EFBFBD>ͷ<EFBFBD><CDB7>ʽ
|
|||
|
header = self.table_widget.horizontalHeader()
|
|||
|
header.setStyleSheet("""
|
|||
|
QHeaderView::section {
|
|||
|
background-color: none;
|
|||
|
font: 600 15px \"Microsoft YaHei UI\";
|
|||
|
background: transparent;
|
|||
|
border: 1px solid #0e5af4;
|
|||
|
color: #08a4ff;
|
|||
|
border-image: none;
|
|||
|
padding-top: 3px;
|
|||
|
padding-bottom: 3px;
|
|||
|
margin-top: 6px;
|
|||
|
border-left: none;
|
|||
|
border-right: none;
|
|||
|
}
|
|||
|
""")
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>ʾ<EFBFBD>к<EFBFBD>
|
|||
|
self.table_widget.verticalHeader().setVisible(False)
|
|||
|
# ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|||
|
self.table_widget.horizontalHeader().setStretchLastSection(True)
|
|||
|
self.table_widget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
|||
|
|
|||
|
self.table_widget.horizontalHeader().setSectionResizeMode(len(self.column_names) - 1, QHeaderView.Fixed)
|
|||
|
self.table_widget.setColumnWidth(len(self.column_names) - 1, 50)
|
|||
|
# ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD>иߺ<D0B8><DFBA>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
self.table_widget.verticalHeader().setDefaultSectionSize(20)
|
|||
|
# ˫<><CBAB>ʱ<EFBFBD><CAB1><EFBFBD>ܶԱ<DCB6><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
self.table_widget.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
|||
|
if len(self.data_list) > 0:
|
|||
|
self.table_widget.item(0, len(self.column_names) - 1).setBackground(QColor("#409eff"))
|
|||
|
for row in range(self.table_widget.rowCount()):
|
|||
|
self.table_widget.item(row, len(self.column_names) - 1).setBackground(QColor("#409eff"))
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def init_table_widget():
|
|||
|
table_widget = QTableWidget()
|
|||
|
table_widget.setStyleSheet(
|
|||
|
"background: transparent;"
|
|||
|
"border: none;"
|
|||
|
"border-image: none;"
|
|||
|
"background-image: none;"
|
|||
|
"color: #ffffff;"
|
|||
|
"font: 15px \"Microsoft YaHei UI\";"
|
|||
|
)
|
|||
|
return table_widget
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_item_title():
|
|||
|
item_title = QLabel("")
|
|||
|
item_title.setAlignment(Qt.AlignCenter)
|
|||
|
item_title.setStyleSheet(
|
|||
|
"font: 600 24px \"Microsoft YaHei UI\";"
|
|||
|
"color: #fdbb03;"
|
|||
|
"background: transparent;"
|
|||
|
"border: none;"
|
|||
|
"border-image: none;"
|
|||
|
)
|
|||
|
return item_title
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def _init_item_widget():
|
|||
|
item_widget = QWidget()
|
|||
|
item_widget.setStyleSheet(
|
|||
|
"border-image: url(assets/bg_item.png);"
|
|||
|
"background-size: contain;"
|
|||
|
"background-repeat: no-repeat;"
|
|||
|
"background-position: center;"
|
|||
|
"background: none;"
|
|||
|
"border: none;"
|
|||
|
"background-color: none;"
|
|||
|
)
|
|||
|
return item_widget
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def init_empty_label():
|
|||
|
empty_label = QLabel('<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
|
|||
|
empty_label.setAlignment(Qt.AlignCenter)
|
|||
|
empty_label.setStyleSheet(
|
|||
|
"color: #ffffff;"
|
|||
|
"font: 20px \"Microsoft YaHei UI\";"
|
|||
|
"margin-bottom: 20px;"
|
|||
|
"background: transparent;"
|
|||
|
"border: none;"
|
|||
|
"border-image: none;"
|
|||
|
)
|
|||
|
return empty_label
|
|||
|
|
|||
|
@staticmethod
|
|||
|
def init_table_stacked_widget():
|
|||
|
table_stacked_widget = QStackedWidget()
|
|||
|
table_stacked_widget.setStyleSheet(
|
|||
|
"background: transparent;"
|
|||
|
"border: none;"
|
|||
|
"border-image: none;"
|
|||
|
)
|
|||
|
return table_stacked_widget
|
|||
|
|