From 3903494a78892e5922f989b3813e6f9dea5eb3ee Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Wed, 27 Aug 2025 14:42:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=89=93?= =?UTF-8?q?=E5=BC=80=E8=A7=A3=E5=8E=8B=E5=90=8E=E6=97=A5=E5=BF=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/MainWindow.ui | 9 +++++++++ src/MainWindow_ui.py | 5 +++++ src/event_handler.py | 35 ++++++++++++++++++++++++++++++++++- src/service.py | 7 +++++++ src/utils.py | 10 +++++++--- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/resource/MainWindow.ui b/resource/MainWindow.ui index 81df7b2..c1465d7 100644 --- a/resource/MainWindow.ui +++ b/resource/MainWindow.ui @@ -216,6 +216,7 @@ p, li { white-space: pre-wrap; } 文件 + @@ -231,6 +232,14 @@ p, li { white-space: pre-wrap; } Ctrl+O + + + 查看日志 + + + 在文件系统中查看日志 + + diff --git a/src/MainWindow_ui.py b/src/MainWindow_ui.py index ba33ffc..a8a8211 100644 --- a/src/MainWindow_ui.py +++ b/src/MainWindow_ui.py @@ -106,7 +106,10 @@ class Ui_MainWindow(object): MainWindow.setStatusBar(self.statusbar) self.actionUpload_log = QtWidgets.QAction(MainWindow) self.actionUpload_log.setObjectName("actionUpload_log") + self.actionOpen_log = QtWidgets.QAction(MainWindow) + self.actionOpen_log.setObjectName("actionOpen_log") self.menu.addAction(self.actionUpload_log) + self.menu.addAction(self.actionOpen_log) self.menubar.addAction(self.menu.menuAction()) self.retranslateUi(MainWindow) @@ -149,3 +152,5 @@ class Ui_MainWindow(object): self.actionUpload_log.setText(_translate("MainWindow", "打开")) self.actionUpload_log.setStatusTip(_translate("MainWindow", "上传日志文件到程序中")) self.actionUpload_log.setShortcut(_translate("MainWindow", "Ctrl+O")) + self.actionOpen_log.setText(_translate("MainWindow", "查看日志")) + self.actionOpen_log.setToolTip(_translate("MainWindow", "在文件系统中查看日志")) diff --git a/src/event_handler.py b/src/event_handler.py index b2357cc..a6c4a98 100644 --- a/src/event_handler.py +++ b/src/event_handler.py @@ -1,6 +1,9 @@ import os import service -from PyQt5.QtWidgets import QFileDialog +import platform +import subprocess +from utils import show_info_message +from PyQt5.QtWidgets import QFileDialog, QMessageBox from PyQt5.QtCore import Qt from PyQt5.QtGui import QDragEnterEvent, QDropEvent, QTextCharFormat from background_task import FileReaderThread @@ -15,6 +18,7 @@ class EventHandler: """绑定所有界面事件""" # 菜单项事件 self.main_window.actionUpload_log.triggered.connect(self.upload_file) + self.main_window.actionOpen_log.triggered.connect(self.open_onekeylog_in_resourcesManager) # 下拉框变化事件 self.main_window.comboBox.currentTextChanged.connect(self.on_combo_changed) # 图形视图滚轮缩放事件 @@ -35,6 +39,35 @@ class EventHandler: if file_path: self.file_processor.process_uploaded_file(file_path) + def open_onekeylog_in_resourcesManager(self): + if not self.main_window.parse_status.diag_complete_status: + show_info_message( + parent=self.main_window, + title="无法打开日志", + message="当前无日志文件解析\n" + ) + return + + onekeylog_path = service.get_unzip_log_path() + + # 检查路径是否存在 + if not os.path.exists(onekeylog_path): + QMessageBox.warning(self.main_window, '路径不存在', f'指定的路径不存在:\n{onekeylog_path}') + return + + try: + # 根据不同操作系统打开文件资源管理器 + if platform.system() == 'Windows': + # Windows系统:explorer /select 命令可以定位到指定文件/文件夹 + subprocess.run(['explorer', '/select,', onekeylog_path]) + elif platform.system() == 'Darwin': # macOS + subprocess.run(['open', onekeylog_path]) + else: # Linux及其他类Unix系统 + subprocess.run(['xdg-open', onekeylog_path]) + + except Exception as e: + QMessageBox.critical(self.main_window, '错误', f'打开文件资源管理器失败:\n{str(e)}') + def on_combo_changed(self, selected_text): """下拉框选项变化:切换图片""" # 获取选中项对应的路径关键词 diff --git a/src/service.py b/src/service.py index 707ad2f..2846dd4 100644 --- a/src/service.py +++ b/src/service.py @@ -69,6 +69,13 @@ def send_log_to_cache(filepath): cache_dir = os.path.join(project_root, "okd_tmp") utils.unzip_log(filepath, cache_dir) +def get_unzip_log_path(): + project_root = utils.get_project_root() + cache_dir = os.path.join(project_root, "okd_tmp") + onekeylog_dir = os.path.join(cache_dir, "onekeylog") + extlog_dir = os.path.join(onekeylog_dir, "log") + return extlog_dir + def get_sensorhistory_path(type): return sensorparse.get_sensor_all_image_path(type) diff --git a/src/utils.py b/src/utils.py index b83c718..ab02aa4 100644 --- a/src/utils.py +++ b/src/utils.py @@ -42,10 +42,14 @@ def show_question_message(parent, title, message): QMessageBox.No ) -def get_project_root(): +def get_app_cache_root(): current_file = os.path.abspath(__file__) - project_root = os.path.dirname(os.path.dirname(current_file)) - return project_root + app_cache_root = os.path.dirname(os.path.dirname(current_file)) + return app_cache_root + +def get_project_root(): + app_cache_root = get_app_cache_root() + return app_cache_root def unzip_log(tar_path, extract_path='.'): """