This commit is contained in:
njdaoyehu 2024-11-28 10:20:55 +08:00
parent 0f3eb3aa7b
commit b033ec5c0c

View File

@ -1,6 +1,7 @@
import cv2 import cv2
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QImage, QTextCursor from PyQt5.QtGui import QPixmap, QImage, QTextCursor, QTextCharFormat, QBrush, QColor
from PyQt5.QtMultimedia import QCameraInfo
from PyQt5.QtWidgets import QDialog, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QScrollArea, QPushButton, \ from PyQt5.QtWidgets import QDialog, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QScrollArea, QPushButton, \
QSpacerItem, QSizePolicy, QLabel, QMessageBox, QPlainTextEdit QSpacerItem, QSizePolicy, QLabel, QMessageBox, QPlainTextEdit
@ -64,9 +65,9 @@ class TaskRunDialog(QDialog):
dd = 0 dd = 0
elif msg.msg_type == MSG_DETECTION_RECORD: elif msg.msg_type == MSG_DETECTION_RECORD:
# 显示日志 # 显示日志
self.log_text.appendPlainText(get_msg_info(msg.record.code).decode('utf-8')) # self.log_text.appendPlainText(get_msg_info(msg.record.code).decode('utf-8'))
if msg.record.code < 0: if msg.record.code < 0:
self.insert_text(get_msg_info(msg.record.code).decode('utf-8'), QColor("red"))
QMessageBox.warning(self, '错误信息', get_msg_info(msg.record.code).decode('utf-8')) QMessageBox.warning(self, '错误信息', get_msg_info(msg.record.code).decode('utf-8'))
self.set_button_default() self.set_button_default()
AppContext.get_edge_context().get_component('image-framework').start_location() AppContext.get_edge_context().get_component('image-framework').start_location()
@ -76,11 +77,12 @@ class TaskRunDialog(QDialog):
self.stop_check_button.setEnabled(True) self.stop_check_button.setEnabled(True)
self.stop_task_button.setEnabled(False) self.stop_task_button.setEnabled(False)
elif msg.record.code == 1012: elif msg.record.code == 1012:
self.insert_text(get_msg_info(msg.record.code).decode('utf-8'), QColor("green"))
QMessageBox.warning(self, '成功信息', "检测结束") QMessageBox.warning(self, '成功信息', "检测结束")
self.set_button_default() self.set_button_default()
AppContext.get_edge_context().get_component('image-framework').start_location() AppContext.get_edge_context().get_component('image-framework').start_location()
else: else:
dddd = 0 self.insert_text(get_msg_info(msg.record.code).decode('utf-8'), QColor("white"))
if qt_image is None: if qt_image is None:
return return
@ -92,6 +94,33 @@ class TaskRunDialog(QDialog):
else: else:
ddd = 0 ddd = 0
def insert_text(self, text, font_color):
fmt = QTextCharFormat()
fmt.setForeground(QBrush(font_color))
self.log_text.mergeCurrentCharFormat(fmt)
self.log_text.appendPlainText(text)
# InsertText(QString
# text, QPlainTextEdit * plainTextEdit, int
# fontSize, QColor
# fontColor, QColor
# backColor)
# {
# QTextCharFormat
# fmt;
# // 字体色
# fmt.setForeground(QBrush(fontColor));
# // fmt.setUnderlineColor("red");
#
# // 背景色
# fmt.setBackground(QBrush(backColor));
# // 字体大小
# fmt.setFontPointSize(fontSize);
# // 文本框使用以上设定
# plainTextEdit->mergeCurrentCharFormat(fmt);
# // 文本框添加文本
# plainTextEdit->appendPlainText(text);
# }
def showEvent(self, e): def showEvent(self, e):
AppContext.get_edge_context().get_component('image-framework').start_location() AppContext.get_edge_context().get_component('image-framework').start_location()