添加了 消息列表弹窗(系统状态消息、预警消息),以及存储消息的数据库

This commit is contained in:
2025-11-13 09:37:41 +08:00
parent aa7dd7974a
commit 3d860b22fd
13 changed files with 615 additions and 29 deletions

View File

@ -1,8 +1,12 @@
# controller/bottom_control_controller.py
from PySide6.QtCore import Qt, QPropertyAnimation, QRect, QParallelAnimationGroup, QEasingCurve
from PySide6.QtCore import Qt, QPropertyAnimation, QRect, QParallelAnimationGroup, QEasingCurve, QPoint, Slot
from view.widgets.system_center_dialog import SystemCenterDialog
from view.widgets.bottom_control_widget import BottomControlWidget
from view.widgets.system_diagnostics_dialog import SystemDiagnosticsDialog
from view.widgets.message_popup_widget import MessagePopupWidget
from service.msg_recorder import MessageRecorder
from service.msg_query_thread import MsgQueryThread
"""
控制主界面底部的所有按钮, 包括系统诊断、系统中心等的行为。
@ -13,29 +17,71 @@ class BottomControlController:
def __init__(self, bottom_control_widget:BottomControlWidget, main_window):
self.bottom_control_widget = bottom_control_widget
self.main_window = main_window
self._bind_buttons()
# 系统中心弹窗
self.system_center_dialog = SystemCenterDialog(self.main_window)
self.system_center_dialog.hide() # 初始隐藏 (必须)
self._init_system_center_dialog_hide_animations()
# 系统诊断弹窗
self.system_diagnostics_dialog = SystemDiagnosticsDialog(self.main_window)
self.system_diagnostics_dialog.hide()
self._init_system_diagnostics_dialog_hide_animations()
# 系统中心弹窗
self.system_center_dialog = SystemCenterDialog(self.main_window)
self._init_system_center_dialog_hide_animations()
# ===================== 消息列表相关 ====================================
# 系统状态消息列表控件
self.status_msg_widget = MessagePopupWidget("系统状态消息", self.main_window)
# 预警消息列表控件
self.warning_msg_widget = MessagePopupWidget("预警消息", self.main_window)
# 消息数据库查询线程
self.msg_query_thread = MsgQueryThread() # 默认1秒查询一次每次16条消息
# 连接线程信号到UI更新函数
self.msg_query_thread.new_messages.connect(self.update_message_ui, Qt.QueuedConnection)
self.msg_query_thread.start() # 启动线程
# =======================================================================
# 绑定主界面底部按钮的信号(如:系统诊断按钮等,点击触发弹窗)
self._bind_buttons()
# 绑定弹窗中按钮的信号
self._bind_dialog_signals()
@Slot(int, list)
def update_message_ui(self, message_type, messages):
"""根据消息类型更新对应UI, message_type为1表示系统状态消息, 为2表示预警消息"""
# 清空当前消息列表(避免重复)
target_widget = self.status_msg_widget if message_type == 1 else self.warning_msg_widget
target_widget.list_widget.clear()
# target_widget.messages.clear()
# 添加新消息 (第三个为 create_time, 第四个为 last_modified)
for content, is_processed, create_time, _ in messages:
# 从create_time中提取时分秒
# time_part = create_time.split()[1] # 空格分隔之后的[1]为时分秒
# 需要添加到消息列表的消息格式为 时分秒 + 消息原始内容
# msg_list_content = f"{create_time} {content}"
target_widget.add_message(content, is_processed = bool(is_processed), msg_time = create_time)
def stop_threads(self):
"""停止当前控制器中的所有线程"""
if hasattr(self, 'msg_query_thread') and self.msg_query_thread.isRunning():
self.msg_query_thread.stop()
def _bind_buttons(self):
# 底部系统中心按钮 → 触发弹窗显示/隐藏
self.bottom_control_widget.center_btn.clicked.connect(self.toggle_system_center_dialog)
# 底部系统诊断按钮 → 触发弹窗显示/隐藏
self.bottom_control_widget.diagnosis_btn.clicked.connect(self.toggle_system_diagnostics_dialog)
# 底部系统状态消息按钮 → 触发系统状态消息列表显示/隐藏
self.bottom_control_widget.status_msg_btn.clicked.connect(self.toggle_system_status_msg_list)
# 底部预警消息列表按钮 → 触发预警消息列表显示/隐藏
self.bottom_control_widget.warning_list_btn.clicked.connect(self.toggle_system_warning_msg_list)
def _bind_dialog_signals(self):
"""绑定弹窗按钮的信号"""
# 系统中心弹窗的按钮信号
self.system_center_dialog.sys_setting_clicked.connect(self.handle_sys_setting)
self.system_center_dialog.data_center_clicked.connect(self.handle_data_center)
self.system_center_dialog.user_center_clicked.connect(self.handle_user_center)
@ -155,25 +201,12 @@ class BottomControlController:
self.system_diagnostics_dialog.show()
def _calc_system_diagnostics_dialog_position(self):
"""计算系统诊断弹窗位置(显示在诊断按钮上方,与中心弹窗布局一致"""
"""计算系统诊断弹窗位置(显示在系统诊断按钮上方)"""
btn = self.bottom_control_widget.diagnosis_btn # 诊断按钮
bottom_widget = self.bottom_control_widget
# 计算按钮在主窗口中的绝对位置
bottom_pos_rel_main = bottom_widget.pos() # 底部控件相对于主窗口的位置
btn_pos_rel_bottom = btn.pos() # 诊断按钮相对于底部控件的位置
btn_pos_rel_main = bottom_pos_rel_main + btn_pos_rel_bottom # 诊断按钮在主窗口中的绝对位置
# 计算弹窗坐标(显示在按钮上方,水平居中对齐)
btn_width = btn.width()
dialog_size = self.system_diagnostics_dialog.size()
# 水平方向:与按钮居中对齐
# dialog_x = btn_pos_rel_main.x() + (btn_width - dialog_size.width()) // 2
# dialog_x = btn_pos_rel_main.x() + (btn_width - dialog_size.width())
dialog_x = btn_pos_rel_main.x() # 与系统诊断按钮的左边平齐
# 垂直方向在按钮上方与按钮保持10px间距
# dialog_y = btn_pos_rel_main.y() - dialog_size.height() - 10
dialog_y = btn_pos_rel_main.y() - dialog_size.height()
btn_pos = btn.mapToGlobal(QPoint(0, 0))
dialog_x = btn_pos.x()
dialog_y = btn_pos.y() - self.system_diagnostics_dialog.height()
# 设置弹窗位置(动画会基于此位置执行滑入效果)
self.system_diagnostics_dialog.move(dialog_x, dialog_y)
@ -191,4 +224,28 @@ class BottomControlController:
# 设置动画参数并启动
self.dia_hide_pos_anim.setStartValue(current_geo)
self.dia_hide_pos_anim.setEndValue(end_rect)
self.dia_hide_anim_group.start()
self.dia_hide_anim_group.start()
# ================== 系统状态消息列表: 显示系统消息 ===================
def toggle_system_status_msg_list(self):
"""系统状态消息按钮点击之后 显示系统消息"""
if not self.status_msg_widget.isVisible():
btn_pos = self.bottom_control_widget.status_msg_btn.mapToGlobal(QPoint(0, 0))
popup_x = btn_pos.x()
popup_y = btn_pos.y() - self.status_msg_widget.height()
self.status_msg_widget.move(popup_x, popup_y)
self.status_msg_widget.show()
else:
self.status_msg_widget.close()
# ================== 预警消息列表: 显示预警消息 ===================
def toggle_system_warning_msg_list(self):
"""预警消息列表按钮点击之后 显示预警消息"""
if not self.warning_msg_widget.isVisible():
btn_pos = self.bottom_control_widget.warning_list_btn.mapToGlobal(QPoint(0, 0))
popup_x = btn_pos.x()
popup_y = btn_pos.y() - self.warning_msg_widget.height()
self.warning_msg_widget.move(popup_x, popup_y)
self.warning_msg_widget.show()
else:
self.warning_msg_widget.close()

View File

@ -7,15 +7,23 @@ from .camera_controller import CameraController
from .bottom_control_controller import BottomControlController
from .hopper_controller import HopperController
from service.msg_recorder import MessageRecorder
class MainController:
def __init__(self):
# 主界面
self.main_window = MainWindow()
self.msg_recorder = MessageRecorder()
self.msg_recorder.normal_record("开始自动智能浇筑系统")
# 初始化子界面和控制器
self._initSubViews()
self._initSubControllers()
# 连接信号
self.__connectSignals()
def showMainWindow(self):
self.main_window.showFullScreen()
# self.main_window.show()
@ -44,4 +52,15 @@ class MainController:
def _initSubViews(self):
pass
pass
def __connectSignals(self):
self.main_window.about_to_close.connect(self.handleMainWindowClose) # 处理主界面关闭
def handleMainWindowClose(self):
"""主界面关闭"""
self.msg_recorder.normal_record("关闭自动智能浇筑系统")
# 停止系统底部控制器中的线程
if hasattr(self, 'bottom_control_controller'):
self.bottom_control_controller.stop_threads()