系统诊断增加设备检测
This commit is contained in:
@ -66,44 +66,47 @@ class CustomDropdown(QWidget):
|
||||
)
|
||||
|
||||
# 2. 可点击的箭头标签(QLabel)
|
||||
self.arrow_label = QLabel()
|
||||
self.arrow_pixmap = QPixmap(arrow_img_path)
|
||||
self.arrow_label.setStyleSheet("background-image: url(" ");")
|
||||
self.arrow_label.setPixmap(
|
||||
self.arrow_pixmap.scaled(12, 9, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
)
|
||||
self.arrow_label.setCursor(Qt.PointingHandCursor)
|
||||
self.main_layout.addWidget(self.arrow_label, alignment=Qt.AlignTop)
|
||||
# self.arrow_label = QLabel()
|
||||
# self.arrow_pixmap = QPixmap(arrow_img_path)
|
||||
# self.arrow_label.setStyleSheet("background-image: url(" ");")
|
||||
# self.arrow_label.setPixmap(
|
||||
# self.arrow_pixmap.scaled(12, 9, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
# )
|
||||
# self.arrow_label.setCursor(Qt.PointingHandCursor)
|
||||
# self.main_layout.addWidget(self.arrow_label, alignment=Qt.AlignTop)
|
||||
|
||||
# 3. 下拉选项列表(默认选中第一个)
|
||||
self.list_widget = QListWidget()
|
||||
self.list_widget.setWindowFlags(Qt.Popup)
|
||||
# 取消了下拉框 2026/1/11
|
||||
# self.list_widget = QListWidget()
|
||||
# self.list_widget.setWindowFlags(Qt.Popup)
|
||||
|
||||
# 设置选项字体
|
||||
font = QFont()
|
||||
font.setPixelSize(16)
|
||||
|
||||
# 添加所有的下拉选项
|
||||
for option in options:
|
||||
item = QListWidgetItem(option)
|
||||
item.setTextAlignment(Qt.AlignLeft)
|
||||
item.setFont(font)
|
||||
self.list_widget.addItem(item)
|
||||
self.list_widget.setCurrentRow(0) # 默认选中第一项
|
||||
self.list_widget.itemClicked.connect(self.select_option)
|
||||
# 取消了下拉框 2026/1/11
|
||||
# for option in options:
|
||||
# item = QListWidgetItem(option)
|
||||
# item.setTextAlignment(Qt.AlignLeft)
|
||||
# item.setFont(font)
|
||||
# self.list_widget.addItem(item)
|
||||
# self.list_widget.setCurrentRow(0) # 默认选中第一项
|
||||
# self.list_widget.itemClicked.connect(self.select_option)
|
||||
|
||||
# 双保险监听:全局焦点变化 + 事件过滤
|
||||
self.app = QApplication.instance()
|
||||
self.app.focusChanged.connect(self.on_focus_changed)
|
||||
self.list_widget.installEventFilter(self)
|
||||
# 取消了下拉框 2026/1/11
|
||||
# self.app = QApplication.instance()
|
||||
# self.app.focusChanged.connect(self.on_focus_changed)
|
||||
# self.list_widget.installEventFilter(self)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
"""重写鼠标点击事件,实现QLabel点击功能"""
|
||||
# 判断点击是否在result_label或arrow_label区域内
|
||||
# if self.result_label.underMouse() or self.arrow_label.underMouse():
|
||||
# self.toggle_expand()
|
||||
if self.arrow_label.underMouse():
|
||||
self.toggle_expand()
|
||||
# if self.arrow_label.underMouse(): # 取消了下拉箭头 2026/1/11
|
||||
# self.toggle_expand()
|
||||
super().mousePressEvent(event) # 传递事件,不影响其他组件
|
||||
|
||||
def toggle_expand(self):
|
||||
@ -173,15 +176,19 @@ class CustomDropdown(QWidget):
|
||||
# 获取当前选中的设备名
|
||||
def get_selected_device(self):
|
||||
return self.result_label.text()
|
||||
|
||||
|
||||
# 设置选中的设备名
|
||||
def set_selected_device(self, device_name:str):
|
||||
self.result_label.setText(device_name)
|
||||
|
||||
class SystemDiagnosticsDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setAttribute(Qt.WA_TranslucentBackground)
|
||||
self.setWindowOpacity(0.0)
|
||||
self.max_row = 8 # 最大行数为8行
|
||||
self.max_col = 4 # 最大列数为4列
|
||||
self._init_ui()
|
||||
self.init_animations()
|
||||
|
||||
def _init_ui(self):
|
||||
# 无边框模式
|
||||
@ -206,7 +213,7 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
circle_warning_path = ImagePaths.SYSTEM_DIAGNOSTICS_STATUS_YELLOW # 警告状态
|
||||
circle_error_path = ImagePaths.SYSTEM_DIAGNOSTICS_STATUS_RED # 异常状态
|
||||
ms_box_path = ImagePaths.SYSTEM_DIAGNOSTICS_MS_BG
|
||||
dropdown_arrow_path = ImagePaths.SYSTEM_DIAGNOSTICS_DROPDOWN_ARROW
|
||||
dropdown_arrow_path = ImagePaths.SYSTEM_DIAGNOSTICS_DROPDOWN_ARROW # 箭头图标
|
||||
|
||||
# 字体设置
|
||||
ms_font = QFont()
|
||||
@ -214,8 +221,8 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
ms_color = QColor("#14abea")
|
||||
|
||||
# 生成小框
|
||||
for row in range(8):
|
||||
for col in range(4):
|
||||
for row in range(self.max_row):
|
||||
for col in range(self.max_col):
|
||||
box_container = QWidget()
|
||||
box_container.setObjectName(f"box_{row}_{col}")
|
||||
box_container.setStyleSheet(
|
||||
@ -249,6 +256,7 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
ms_layout.setContentsMargins(6, 0, 0, 0)
|
||||
ms_edit = QLineEdit("5ms")
|
||||
ms_edit.setFont(ms_font)
|
||||
ms_edit.setReadOnly(True) # 禁用外部点击输入
|
||||
ms_edit.setStyleSheet(
|
||||
f"""
|
||||
background: none;
|
||||
@ -284,44 +292,6 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
|
||||
grid_layout.addWidget(box_container, row, col)
|
||||
|
||||
def init_animations(self):
|
||||
"""初始化显示动画:从下方滑入 + 淡入"""
|
||||
# 1. 透明度动画(从0→1,与系统中心一致但时长不同)
|
||||
self.opacity_anim = QPropertyAnimation(self, b"windowOpacity")
|
||||
self.opacity_anim.setDuration(400)
|
||||
self.opacity_anim.setStartValue(0.0)
|
||||
self.opacity_anim.setEndValue(1.0)
|
||||
self.opacity_anim.setEasingCurve(QEasingCurve.OutCubic) # 缓动曲线不同
|
||||
|
||||
# 2. 位置动画(从下方100px滑入目标位置,核心差异点)
|
||||
self.pos_anim = QPropertyAnimation(self, b"geometry")
|
||||
self.pos_anim.setDuration(400)
|
||||
self.pos_anim.setEasingCurve(QEasingCurve.OutQuart) # 滑入效果更自然
|
||||
|
||||
# 3. 组合动画(同时执行滑入和淡入)
|
||||
self.anim_group = QParallelAnimationGroup(self)
|
||||
self.anim_group.addAnimation(self.opacity_anim)
|
||||
self.anim_group.addAnimation(self.pos_anim)
|
||||
|
||||
def showEvent(self, event):
|
||||
super().showEvent(event) # 先调用父类方法
|
||||
|
||||
# 动态计算动画起点(在当前位置下方100px,保持宽度和高度不变)
|
||||
current_geometry = self.geometry() # 当前位置和尺寸(需提前用move设置)
|
||||
# 起点:y坐标增加100px(从下方滑入),x和尺寸不变
|
||||
start_rect = QRect(
|
||||
current_geometry.x(),
|
||||
current_geometry.y() + 100, # 下方100px
|
||||
current_geometry.width(),
|
||||
current_geometry.height()
|
||||
)
|
||||
# 设置动画起点和终点
|
||||
self.pos_anim.setStartValue(start_rect)
|
||||
self.pos_anim.setEndValue(current_geometry) # 终点:目标位置
|
||||
|
||||
# 启动动画
|
||||
self.anim_group.start()
|
||||
|
||||
def paintEvent(self, event):
|
||||
"""重写绘制事件,手动在透明背景上绘制图片"""
|
||||
if not self.bg_pixmap.isNull():
|
||||
@ -345,15 +315,22 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
|
||||
# ========== 对外接口:获取选中的设备名 ==========
|
||||
def get_selected_device(self, row, col):
|
||||
"""获取指定行列的选中设备名"""
|
||||
"""获取指定行列的选中设备名, 行号和列号都从0开始"""
|
||||
box = self.findChild(QWidget, f"box_{row}_{col}")
|
||||
if box and hasattr(box, "dropdown"):
|
||||
return box.dropdown.get_selected_device()
|
||||
return None
|
||||
|
||||
# ========== 对外接口:设置选中的设备名 ==========
|
||||
def set_selected_device(self, row, col, device_name:str):
|
||||
"""设置指定行列的选中设备名, 行号和列号都从0开始"""
|
||||
box = self.findChild(QWidget, f"box_{row}_{col}")
|
||||
if box and hasattr(box, "dropdown"):
|
||||
return box.dropdown.set_selected_device(device_name)
|
||||
|
||||
# ========== 对外接口:获取毫秒值 ==========
|
||||
def get_ms_value(self, row, col):
|
||||
"""获取指定行列的毫秒值(如“5ms”)"""
|
||||
"""获取指定行列的毫秒值(如“5ms”), 行号和列号都从0开始"""
|
||||
box = self.findChild(QWidget, f"box_{row}_{col}")
|
||||
if box and hasattr(box, "ms_edit"):
|
||||
# return box.ms_edit.text()
|
||||
@ -366,6 +343,13 @@ class SystemDiagnosticsDialog(QDialog):
|
||||
return number_match.group(1)
|
||||
|
||||
return None
|
||||
|
||||
# ========== 对外接口:设置毫秒值 ==========
|
||||
def set_ms_value(self, row, col, ms:int):
|
||||
"""设置指定行列的毫秒值, 行号和列号都从0开始"""
|
||||
box = self.findChild(QWidget, f"box_{row}_{col}")
|
||||
if box and hasattr(box, "ms_edit"):
|
||||
box.ms_edit.setText(f"{ms}ms")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user