mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-gui.git
synced 2025-06-24 13:14:11 +08:00
154 lines
6.3 KiB
Python
154 lines
6.3 KiB
Python
from datetime import datetime
|
|
from os import replace
|
|
|
|
from PyQt5.QtGui import QColor, QIcon
|
|
from PyQt5.QtWidgets import QVBoxLayout, QWidget, QFrame, QHBoxLayout, QLabel, QGridLayout, QPlainTextEdit, \
|
|
QGraphicsDropShadowEffect, QCommandLinkButton, QScrollArea, QMessageBox
|
|
from PyQt5.QtCore import Qt, QSize
|
|
import json
|
|
|
|
from widget.message_box import MessageBox
|
|
from widget.task_result import TaskResultFrame
|
|
from widget.task_run import TaskRunDialog
|
|
from core.context import AppContext
|
|
|
|
class TaskItemFrame(QFrame):
|
|
def __init__(self, task, max_height, parent=None):
|
|
super(TaskItemFrame, self).__init__(parent)
|
|
|
|
self.setFixedSize(int((1920 - 50)/3), int((max_height - 30)/2))
|
|
self.setStyleSheet("background-color: #2a2f55; border-radius: 10px;")
|
|
|
|
self.effect_shadow = QGraphicsDropShadowEffect(self)
|
|
self.effect_shadow.setOffset(0, 0) # 偏移
|
|
self.effect_shadow.setBlurRadius(10) # 阴影半径
|
|
self.effect_shadow.setColor(QColor(85,89,119)) # 阴影颜色
|
|
self.setGraphicsEffect(self.effect_shadow)
|
|
|
|
layout = QGridLayout()
|
|
layout.setSpacing(0)
|
|
layout.setContentsMargins(30, 10, 20, 10)
|
|
|
|
layout.addWidget(self.add_item("任务名称:", True), 0, 0)
|
|
layout.addWidget(self.add_item(task[1]), 0, 1)
|
|
layout.addWidget(self.add_item("设备序列号:", True), 1, 0)
|
|
layout.addWidget(self.add_item(task[2]), 1, 1, 1, 2)
|
|
layout.addWidget(self.add_item("开始时间:", True), 3, 0)
|
|
if task[6] is None:
|
|
layout.addWidget(self.add_item(""), 3, 1, 1, 2)
|
|
else:
|
|
layout.addWidget(self.add_item(task[6][0: -10]), 3, 1, 1, 2)
|
|
layout.addWidget(self.add_item("结束时间:", True), 4, 0)
|
|
if task[7] is None:
|
|
layout.addWidget(self.add_item(""), 4, 1, 1, 2)
|
|
else:
|
|
layout.addWidget(self.add_item(task[7][0: -10]), 4, 1, 1, 2)
|
|
layout.addWidget(self.add_item("创建时间:", True), 5, 0)
|
|
layout.addWidget(self.add_item(task[9][0: -3]), 5, 1, 1, 2)
|
|
layout.addWidget(self.add_item("任务参数:", True), 6, 0)
|
|
layout.addWidget(self.add_param(task[3]), 6, 1, 1, 2, Qt.AlignTop)
|
|
|
|
button_start = QCommandLinkButton("", self)
|
|
button_start.setCheckable(True)
|
|
icon = QIcon("assets/run.png")
|
|
button_start.setIcon(icon)
|
|
button_start.setIconSize(QSize(36, 36))
|
|
button_start.clicked.connect(lambda: self.start_task(task))
|
|
layout.addWidget(button_start, 0, 2)
|
|
|
|
self.setLayout(layout)
|
|
|
|
@staticmethod
|
|
def add_item(text, is_label = False):
|
|
label = QLabel()
|
|
if is_label:
|
|
label.setFixedWidth(100)
|
|
label.setText(text)
|
|
return label
|
|
|
|
def add_param(self, json_str):
|
|
content_widget = QWidget()
|
|
content_widget.setStyleSheet("border: none;")
|
|
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setObjectName("paramArea")
|
|
scroll_area.setStyleSheet("border-radius: 0;")
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
|
scroll_area.setFixedSize(QSize(470, 200))
|
|
|
|
scroll_area.setWidget(content_widget)
|
|
|
|
if json_str is None or len(json_str) == 0:
|
|
return scroll_area
|
|
|
|
params = json.loads(json_str)
|
|
|
|
if len(params) == 0:
|
|
return scroll_area
|
|
|
|
layout = QGridLayout()
|
|
layout.setSpacing(0)
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
row = 0
|
|
layout.addWidget(self.add_param_item("编号", 150, True), row, 0)
|
|
layout.addWidget(self.add_param_item("类型", 100, True), row, 1)
|
|
layout.addWidget(self.add_param_item("X", 65, True), row, 2)
|
|
layout.addWidget(self.add_param_item("Y", 65, True), row, 3)
|
|
layout.addWidget(self.add_param_item("中心点", -1, True), row, 4)
|
|
|
|
row = row + 1
|
|
for param in params:
|
|
layout.addWidget(self.add_param_item(param['code'], 150, is_bottom = row == len(params)), row, 0)
|
|
layout.addWidget(self.add_param_item(param['type'], 100, is_bottom = row == len(params)), row, 1)
|
|
layout.addWidget(self.add_param_item(param['x'], 65, is_bottom = row == len(params)), row, 2)
|
|
layout.addWidget(self.add_param_item(param['y'], 65, is_bottom = row == len(params)), row, 3)
|
|
if len(param['center']) != 0 and '.' not in param['center']:
|
|
index = len(param['center']) - 3
|
|
str1 = param['center'][0: index]
|
|
str2 = param['center'][index: ]
|
|
layout.addWidget(self.add_param_item(str1 + "." + str2, -1, is_bottom = row == len(params)), row, 4)
|
|
else:
|
|
layout.addWidget(self.add_param_item(param['center'], -1, is_bottom = row == len(params)), row, 4)
|
|
row = row + 1
|
|
|
|
content_widget.setLayout(layout)
|
|
return scroll_area
|
|
|
|
@staticmethod
|
|
def add_param_item(text, width, is_header = False, is_bottom = False):
|
|
label = QLabel()
|
|
if width != -1:
|
|
label.setFixedWidth(width)
|
|
style_str = "text-align: center; border-right: 1px solid #ffffff;"
|
|
if is_header:
|
|
label.setFixedHeight(32)
|
|
style_str += "background-color: #454962;"
|
|
if not is_bottom:
|
|
style_str += "border-bottom: 1px solid #ffffff;"
|
|
label.setStyleSheet(style_str)
|
|
label.setAlignment(Qt.AlignCenter)
|
|
label.setText(text)
|
|
return label
|
|
|
|
@staticmethod
|
|
def start_task(task):
|
|
params = json.loads(task[3])
|
|
if len(task[3]) == 0 or len(params) == 0:
|
|
MessageBox("任务名称: " + task[1],"warning", "任务未设置参数!", AppContext.get_main_window()).show()
|
|
return
|
|
task_table = AppContext.get_edge_context().get_component("dat_task")
|
|
task_table.update_task({ "id": task[0], "state": 1, "start_time": datetime.now() })
|
|
|
|
TaskResultFrame(task, AppContext.get_main_window()).show()
|
|
|
|
# self.run_dialog = TaskRunDialog(task[3])
|
|
# self.run_dialog.setGeometry(0,0,1920,1080)
|
|
# dialog_result = self.run_dialog.exec_()
|
|
# if dialog_result == 0:
|
|
# c = 0
|
|
# # self.name_text.setText(None)
|
|
# # self.file_content.setPlainText(None)
|