90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
# coding: gb2312
|
|
|
|
from PyQt5.QtWidgets import *
|
|
from PyQt5.QtChart import *
|
|
from PyQt5.QtCore import *
|
|
from PyQt5.QtGui import *
|
|
from LSZXPagesManagerLibrary.echarts_pie import PieCircleWidget
|
|
|
|
|
|
class EchartsPieTable:
|
|
|
|
def __init__(self, columns_num=2, rows_num=4):
|
|
super().__init__()
|
|
self.rows_num = rows_num
|
|
self.columns_num = columns_num
|
|
|
|
# self.table_list = {
|
|
# "categorize": [
|
|
# {"keyname": "situp", "name": "仰卧起坐"},
|
|
# {"keyname": "runaround", "name": "30*2蛇形跑"},
|
|
# {"keyname": "pullup", "name": "引体向上"},
|
|
# {"keyname": "running", "name": "长跑"}
|
|
# ],
|
|
# "data": {
|
|
# "pullup": [17.86, 39.29, 16.07, 26.79, 0],
|
|
# "runaround": [12.5, 53.57, 23.21, 10.71, 0],
|
|
# "running": [16.07, 64.29, 10.71, 8.93, 0],
|
|
# "situp": [25, 39.29, 23.21, 12.5, 0]
|
|
# },
|
|
# "status": 0
|
|
# }
|
|
self.table_list = {}
|
|
self.scroll_area = self._init_scroll_area_widget()
|
|
# 绘制切换转盘
|
|
self.layout = QVBoxLayout()
|
|
self.layout.addWidget(self.scroll_area)
|
|
self.layout.setContentsMargins(10, 10, 10, 10)
|
|
|
|
def set_data(self, _data_list):
|
|
self.table_list = _data_list
|
|
column_num = self.columns_num
|
|
row_num = self.rows_num
|
|
scroll_widget = QWidget()
|
|
realtime_layout = QVBoxLayout(scroll_widget)
|
|
scroll_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
row_layout = QHBoxLayout()
|
|
count = 0
|
|
for item in self.table_list["categorize"]:
|
|
# 初始化图标对象
|
|
item_widget = QWidget()
|
|
item_widget.setStyleSheet("border: 1px solid #f0f0f0")
|
|
item_layout = QVBoxLayout()
|
|
label_widget = PieCircleWidget()
|
|
item_layout.addWidget(label_widget)
|
|
item_widget.setLayout(item_layout)
|
|
label_widget.set_data([25, 39.29, 23.21, 12.5, 0], item["name"])
|
|
row_layout.addWidget(item_widget)
|
|
if (count + 1) % column_num == 0:
|
|
realtime_layout.addLayout(row_layout)
|
|
row_layout = QHBoxLayout()
|
|
count += 1
|
|
# 补充剩余的人员信息,并绘制留白。
|
|
if row_layout.count() > 0:
|
|
for _ in range(column_num - row_layout.count()):
|
|
# 空白框
|
|
empty_box = QLabel()
|
|
row_layout.addWidget(empty_box)
|
|
realtime_layout.addLayout(row_layout)
|
|
if realtime_layout.count() < row_num:
|
|
for _ in range(row_num - realtime_layout.count()):
|
|
# 空白框
|
|
empty_box = QLabel()
|
|
# 增加到布局中
|
|
row_layout = QHBoxLayout()
|
|
row_layout.addWidget(empty_box)
|
|
realtime_layout.addLayout(row_layout)
|
|
self.scroll_area.setWidget(scroll_widget)
|
|
|
|
def get_layout(self):
|
|
return self.layout
|
|
|
|
@staticmethod
|
|
def _init_scroll_area_widget():
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setStyleSheet(
|
|
"border: none;"
|
|
)
|
|
return scroll_area
|