From 1e4ab5a1780b59a56b5df2ee7b4125c0ced4c26b Mon Sep 17 00:00:00 2001 From: kaiser Date: Tue, 23 Dec 2025 16:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E5=8A=9F=E8=83=BD=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 98 +++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 33 deletions(-) diff --git a/main.py b/main.py index e68160f..114e17d 100644 --- a/main.py +++ b/main.py @@ -72,46 +72,65 @@ class ScreenLabel(QLabel): :param selected: bool, True为选中(高亮),False为取消选中(正常) """ self.is_selected = selected # 保存状态 - self.update_style() - # if selected: - # # 如果选中,设置一个红色/蓝色的边框,或者背景色 - # self.setStyleSheet(""" - # border: 2px solid red; - # background-color: rgba(255, 0, 0, 0.1); - # """) - # else: - # # 如果取消选中,恢复默认样式(假设默认是灰色边框) - # self.setStyleSheet(""" - # border: 1px solid gray; - # background-color: white; - # """) - - # 强制刷新界面 - self.update() - - def update_style(self): if self.is_selected: - if self.screen_id not in ScreenLabel.click_labels: ScreenLabel.click_labels.append(self.screen_id) ScreenLabel.split_solution[self.screen_id - 1]['status'] = 1 - # 选中状态:蓝色背景 - self.setStyleSheet(""" - background-color: rgb(0, 170, 255); - color: white; - border: 2px solid yellow; - font-weight: bold; - """) + self.update_style(1) else: if self.screen_id in ScreenLabel.click_labels: ScreenLabel.click_labels.remove(self.screen_id) if ScreenLabel.split_solution[self.screen_id - 1]: ScreenLabel.split_solution[self.screen_id - 1]['status'] = 0 + self.update_style(0) + # 强制刷新界面 + self.update() + + def update_style(self, status): + if status == 0: self.init_style() + elif status == 1: + # 选中状态:蓝色背景 + self.setStyleSheet(""" + background-color: rgb(0, 170, 255); + color: white; + border: 2px solid yellow; + font-weight: bold; + """) + elif status == 2: + # 锁定状态:绿色背景 + self.setStyleSheet(""" + background-color: rgb(0, 255, 0); + color: white; + border: 2px solid yellow; + font-weight: bold; + """) + + # if self.is_selected: + # + # if self.screen_id not in ScreenLabel.click_labels: + # ScreenLabel.click_labels.append(self.screen_id) + # + # ScreenLabel.split_solution[self.screen_id - 1]['status'] = 1 + # # 选中状态:蓝色背景 + # self.setStyleSheet(""" + # background-color: rgb(0, 170, 255); + # color: white; + # border: 2px solid yellow; + # font-weight: bold; + # """) + # else: + # if self.screen_id in ScreenLabel.click_labels: + # ScreenLabel.click_labels.remove(self.screen_id) + # + # if ScreenLabel.split_solution[self.screen_id - 1]: + # ScreenLabel.split_solution[self.screen_id - 1]['status'] = 0 + # + # self.init_style() class MatrixControlApp(QMainWindow, Ui_MainWindow): def __init__(self): @@ -296,8 +315,9 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): # 这部分逻辑比较重,通常我们用 方案 A 的缓存方式。 def assign_source_to_screen(self, screen_id, source): - """分配信号源给屏幕""" - + """ + 分配信号源给屏幕 + """ # 2. 【新增】通过串口管理器发送 # 这里的 self.serial_manager 来自于我们在 main.py 中的初始化 if hasattr(self, 'serial_manager') and self.serial_manager.is_connected: @@ -386,11 +406,9 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): # 获取选中的屏幕控件 selected_widgets = [self.screen_labels[value - 1] for value in ScreenLabel.click_labels] - print(selected_widgets) # 生成拼接指令参数 params = self.serial_protocol.calculate_mosaic_params(selected_widgets) - print(params) # 2. 【新增】通过串口管理器发送 # 这里的 self.serial_manager 来自于我们在 main.py 中的初始化 @@ -441,8 +459,8 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): ScreenLabel.split_solution[i - 1]["status"] = 3 ScreenLabel.split_solution[i - 1]["big_pic_id"] = big_pic_id - # 1. 查找对应的 Label 对象 - # label = self.screen_labels[screen_id - 1] # 数组下标从0开始 + label = self.screen_labels[i - 1] # 数组下标从0开始 + label.setText(f"Screen {i}\n[分组_{big_pic_id}]\n(已拼接)") logger.info(f"✅ 指令发送成功") else: @@ -453,7 +471,9 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): return def clear_screen(self, screen_id): - + """ + 清空屏幕 + """ screen_pos = ScreenLabel.split_solution[screen_id - 1]['big_pic_id'] screen_status = ScreenLabel.split_solution[screen_id - 1]['status'] @@ -486,18 +506,27 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): print(f"【指令】屏幕 {screen_id} 已清屏") def mouse_press_event(self, event): + """ + 鼠标按下时,显示选框 + """ # 鼠标按下时记录起点,显示选框 self.origin = event.pos() self.rubber_band.setGeometry(QRect(self.origin, QSize())) self.rubber_band.show() def mouse_move_event(self, event): + """ + 鼠标移动时,显示选框 + """ # 鼠标移动时调整选框大小 if self.rubber_band.isVisible(): rect = QRect(self.origin, event.pos()).normalized() self.rubber_band.setGeometry(rect) def mouse_release_event(self, event): + """ + 鼠标释放后,执行操作 + """ # 鼠标释放时,隐藏选框,并检查选中了哪些屏幕 self.rubber_band.hide() @@ -526,6 +555,9 @@ class MatrixControlApp(QMainWindow, Ui_MainWindow): screen_widget.set_selected(False) def send_mosaic_command(self, start, hcount, vcount): + """ + 调用预设方案 + """ print(f"当前 serial_manager 对象: {id(self.serial_manager)}") print(f"当前 is_connected 状态: {self.serial_manager.is_connected}")