mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-gui.git
synced 2025-06-24 13:14:11 +08:00
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QLabel, QScrollArea, QFrame
|
|
|
|
from core.context import AppContext
|
|
from widget.task_item import TaskItemFrame
|
|
|
|
class TaskListFrame(QFrame):
|
|
def __init__(self, parent=None):
|
|
super(TaskListFrame, self).__init__(parent)
|
|
|
|
self.setStyleSheet("background-color: #15182b")
|
|
|
|
layout = QVBoxLayout(self)
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
layout.setSpacing(0)
|
|
|
|
self.content_widget = QWidget()
|
|
self.content_widget_layout = QGridLayout(self.content_widget)
|
|
self.content_widget_layout.setContentsMargins(10, 10, 20, 10)
|
|
self.content_widget_layout.setSpacing(10)
|
|
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setObjectName("taskArea")
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
|
scroll_area.setWidget(self.content_widget)
|
|
layout.addWidget(scroll_area)
|
|
|
|
AppContext.get_edge_context().get_component('dat_task').signals.on_receive_task.connect(self.init_ui)
|
|
|
|
def showEvent(self, e):
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
task_table = AppContext.get_edge_context().get_component("dat_task")
|
|
tasks = task_table.list_task(1)
|
|
if len(tasks) == 0:
|
|
return
|
|
|
|
while self.content_widget_layout.count():
|
|
item = self.content_widget_layout.takeAt(0)
|
|
widget = item.widget()
|
|
if widget is not None:
|
|
widget.deleteLater()
|
|
|
|
row = 0
|
|
column = 0
|
|
for task in tasks:
|
|
task_item = TaskItemFrame(task, self.content_widget.geometry().height())
|
|
self.content_widget_layout.addWidget(task_item, row, column, Qt.AlignTop)
|
|
column += 1
|
|
if column == 3:
|
|
row += 1
|
|
column = 0
|
|
|
|
if column == 1 and row == 0:
|
|
self.content_widget_layout.addWidget(QWidget(), 0, 1)
|
|
self.content_widget_layout.addWidget(QWidget(), 0, 2)
|
|
if column == 2 and row == 0:
|
|
self.content_widget_layout.addWidget(QWidget(), 0, 2)
|