From d70e6cef49fdbaa2e778b04d9baff60d57044532 Mon Sep 17 00:00:00 2001 From: 27942 <1313123@342> Date: Sun, 25 Jan 2026 14:51:54 +0800 Subject: [PATCH] =?UTF-8?q?gui=20=E7=AC=AC=E4=B8=80=E7=89=88=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui_app.py | 115 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 26 deletions(-) diff --git a/gui_app.py b/gui_app.py index 4417631..212ce11 100644 --- a/gui_app.py +++ b/gui_app.py @@ -845,20 +845,17 @@ class MainWindow(QMainWindow): self.status_success_value, self.style().standardIcon(QStyle.SP_DialogApplyButton), "#dcfce7", - "点击筛选成功项", - clickable=True + "成功任务数量", + clickable=False ) failed_card = self._build_status_card( "失败", self.status_failed_value, self.style().standardIcon(QStyle.SP_MessageBoxCritical), "#fee2e2", - "点击筛选失败项", - clickable=True + "失败任务数量", + clickable=False ) - # 连接点击事件 - success_card.mousePressEvent = lambda e: self._filter_by_status("成功") - failed_card.mousePressEvent = lambda e: self._filter_by_status("失败") status_layout.addWidget(update_card) status_layout.addWidget(pending_card) @@ -1126,11 +1123,18 @@ class MainWindow(QMainWindow): '执行人', '情况', '文件路径', '进度', '操作' ]) self.table_column_filter.addItem("全部列") - # 第0列为勾选框,过滤列从第1列开始 + # 第0列为勾选框;排除"情况"列,以多多ID等为筛选项;记录下拉项对应的表格列索引及 Model 列索引 + self._filter_table_columns = [] + self._filter_model_columns = [] # Model/View 无勾选列,情况=7 跳过 for col in range(1, 10): header = self.config_table.horizontalHeaderItem(col) - if header: + if header and header.text() != "情况": self.table_column_filter.addItem(header.text()) + self._filter_table_columns.append(col) + self._filter_model_columns.append(8 if col == 9 else col - 1) # 1..7→0..6, 9→8 + # 默认按多多ID筛选(多多ID为下拉第2项,index=1) + if self._filter_table_columns and self._filter_table_columns[0] == 1: + self.table_column_filter.setCurrentIndex(1) header = self.config_table.horizontalHeader() header.setStretchLastSection(False) header.setSectionResizeMode(QHeaderView.Interactive) @@ -1322,6 +1326,9 @@ class MainWindow(QMainWindow): self.shortcut_table_next.activated.connect(self.next_table_match) self.shortcut_table_prev = QShortcut(QKeySequence("Ctrl+Shift+F3"), self) self.shortcut_table_prev.activated.connect(self.prev_table_match) + + # 程序启动时重置状态(不累计历史数据) + self.set_status_cards(update_text="未更新", pending=0, running=0, success=0, failed=0) def _build_status_card(self, title, value_label, icon, bg_color, subtitle, with_progress=False, clickable=False): """创建状态卡片""" @@ -2132,8 +2139,8 @@ class MainWindow(QMainWindow): return regex_enabled = self.table_regex.isChecked() any_term = self.table_any_term.isChecked() - column_index = self.table_column_filter.currentIndex() - 1 - self.table_proxy.setFilterKeyColumn(column_index if column_index >= 0 else -1) + column_index = self._filter_model_column_index() + self.table_proxy.setFilterKeyColumn(column_index) if regex_enabled: pattern = keyword_raw else: @@ -2172,7 +2179,7 @@ class MainWindow(QMainWindow): return terms_raw = [t for t in keyword_raw.split() if t] keyword = keyword_raw if self.table_case_sensitive.isChecked() else keyword_raw.lower() - column_index = self.table_column_filter.currentIndex() - 1 + column_index = self._filter_column_index() visible_count = 0 match_count = 0 matched_rows = [] @@ -2245,7 +2252,7 @@ class MainWindow(QMainWindow): return terms_raw = [t for t in keyword_raw.split() if t] keyword = keyword_raw if self.table_case_sensitive.isChecked() else keyword_raw.lower() - column_index = self.table_column_filter.currentIndex() - 1 + column_index = self._filter_column_index() # 使用正确的列索引映射(排除情况列) regex_enabled = self.table_regex.isChecked() pattern = None if keyword and regex_enabled: @@ -2570,6 +2577,46 @@ class MainWindow(QMainWindow): """默认背景色""" return self.config_table.palette().color(self.config_table.palette().Base) + def _filter_column_index(self): + """筛选项下拉对应的表格列索引;-1 表示全部列。排除情况列,以多多ID等为筛选项。""" + i = self.table_column_filter.currentIndex() + if i <= 0 or not getattr(self, "_filter_table_columns", None): + return -1 + k = i - 1 + if k >= len(self._filter_table_columns): + return -1 + return self._filter_table_columns[k] + + def _filter_model_column_index(self): + """Model/View 模式下筛选项对应的列索引;-1 表示全部列。""" + i = self.table_column_filter.currentIndex() + if i <= 0 or not getattr(self, "_filter_model_columns", None): + return -1 + k = i - 1 + if k >= len(self._filter_model_columns): + return -1 + return self._filter_model_columns[k] + + def _filter_column_index(self): + """筛选项下拉对应的表格列索引;-1 表示全部列。排除情况列,以多多ID等为筛选项。""" + i = self.table_column_filter.currentIndex() + if i <= 0 or not getattr(self, "_filter_table_columns", None): + return -1 + k = i - 1 + if k >= len(self._filter_table_columns): + return -1 + return self._filter_table_columns[k] + + def _filter_model_column_index(self): + """Model/View 模式下筛选项对应的列索引;-1 表示全部列。""" + i = self.table_column_filter.currentIndex() + if i <= 0 or not getattr(self, "_filter_model_columns", None): + return -1 + k = i - 1 + if k >= len(self._filter_model_columns): + return -1 + return self._filter_model_columns[k] + def _show_all_rows(self): """显示全部行""" for row in range(self.config_table.rowCount()): @@ -2598,7 +2645,7 @@ class MainWindow(QMainWindow): total_count = self.config_table.rowCount() for row in range(total_count): - item = self.config_table.item(row, 7) # 第7列是"情况"列 + item = self.config_table.item(row, 8) # 第8列是"情况"列(第0列为勾选框) if item: cell_text = item.text() # 根据状态匹配 @@ -2624,7 +2671,7 @@ class MainWindow(QMainWindow): self._show_infobar("success", "筛选", f"已筛选出 {visible_count} 条{status}记录,再次点击取消筛选") def _update_status_statistics(self): - """更新状态统计(成功/失败/待执行数量)""" + """更新状态统计(成功/失败/待执行数量)- 只统计勾选的配置,不累计历史数据""" if not hasattr(self, 'configs') or not self.configs: self.set_status_cards(pending=0, success=0, failed=0) return @@ -2633,7 +2680,10 @@ class MainWindow(QMainWindow): success_count = 0 failed_count = 0 + # 只统计勾选的配置,不累计历史数据 for config in self.configs: + if not config.get('勾选', False): + continue # 跳过未勾选的配置 status = config.get('情况', '待执行') if "完成" in status or "成功" in status: success_count += 1 @@ -3324,6 +3374,7 @@ class MainWindow(QMainWindow): # 遍历所有行,更新每行的文件路径 total_found = 0 + checked_updated_count = 0 # 只统计勾选的行 for row_idx in range(self.config_table.rowCount()): config = self.get_config_from_table(row_idx) if not config: @@ -3335,6 +3386,15 @@ class MainWindow(QMainWindow): self.log_text.append(f"第 {row_idx + 1} 行:多多ID或序号为空,跳过") continue + # 检查是否勾选(用于统计) + is_checked = False + if self.page_row_indices and row_idx < len(self.page_row_indices): + config_index = self.page_row_indices[row_idx] + else: + config_index = row_idx + if config_index < len(self.configs): + is_checked = self.configs[config_index].get('勾选', False) + self.log_text.append(f"正在更新第 {row_idx + 1} 行的文件路径...") self.log_text.append(f" 多多ID: {config.get('多多id')}, 序号: {config.get('序号')}") @@ -3347,10 +3407,6 @@ class MainWindow(QMainWindow): self.config_table.setItem(row_idx, 9, QTableWidgetItem(file_paths_str)) # 同时更新self.configs中对应的配置 - if self.page_row_indices and row_idx < len(self.page_row_indices): - config_index = self.page_row_indices[row_idx] - else: - config_index = row_idx if config_index < len(self.configs): self.configs[config_index]['文件路径'] = file_paths_str @@ -3359,22 +3415,26 @@ class MainWindow(QMainWindow): ext in ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm'])) self.log_text.append(f" ✓ 找到 {len(found_files)} 个文件({video_count} 个视频)") total_found += len(found_files) + if is_checked: + checked_updated_count += 1 else: # 清空文件路径列 self.config_table.setItem(row_idx, 9, QTableWidgetItem("")) - if self.page_row_indices and row_idx < len(self.page_row_indices): - config_index = self.page_row_indices[row_idx] - else: - config_index = row_idx if config_index < len(self.configs): self.configs[config_index]['文件路径'] = "" self.log_text.append(f" ✗ 未找到匹配的文件") self.log_text.append("=" * 50) self.log_text.append(f"批量更新完成!共更新 {self.config_table.rowCount()} 行,找到 {total_found} 个文件") - self.update_status_label.setText(f"已更新: {self.config_table.rowCount()}行,{total_found}个文件") + # 只统计勾选的行中,有文件路径的数量(不累计历史) + checked_with_files = sum(1 for config in self.configs + if config.get('勾选', False) and config.get('文件路径', '').strip()) + checked_file_count = sum(len(config.get('文件路径', '').split(';')) + for config in self.configs + if config.get('勾选', False) and config.get('文件路径', '').strip()) + self.update_status_label.setText(f"已更新: {checked_with_files}行,{checked_file_count}个文件") self.update_status_label.setStyleSheet("color: #4CAF50; font-size: 10px;") - self.set_status_cards(update_text=f"已更新: {self.config_table.rowCount()}行", pending=total_found) + self.set_status_cards(update_text=f"已更新: {checked_with_files}行", pending=checked_file_count) # 更新映射(多多ID+序号 -> 行号),确保后续逐条回写状态准确 self._rebuild_row_map() # 计算并应用间隔时间规则(按多多ID分组) @@ -3561,6 +3621,9 @@ class MainWindow(QMainWindow): def execute_batch_from_excel(self): """从 Excel配置批量执行(自动判断相同多多ID的mp4文件,批量上传)""" + # 开始新任务时重置当前批次状态(不累计历史数据) + self.set_status_cards(pending=0, running=0, success=0, failed=0) + # 获取文件夹路径,如果为空则使用默认路径 folder_path = self.folder_path_input.text().strip() if not folder_path: @@ -4349,7 +4412,7 @@ def main(): sys.excepthook = exception_handler app = QApplication(sys.argv) - + # 解决 macOS 上缺失 Segoe UI 字体导致的警告 if sys.platform == "darwin": font = QFont(".AppleSystemUIFont", 10)