feat :添加打开解压后日志文件功能
This commit is contained in:
parent
1c384130bf
commit
3903494a78
@ -216,6 +216,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>文件</string>
|
||||
</property>
|
||||
<addaction name="actionUpload_log"/>
|
||||
<addaction name="actionOpen_log"/>
|
||||
</widget>
|
||||
<addaction name="menu"/>
|
||||
</widget>
|
||||
@ -231,6 +232,14 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpen_log">
|
||||
<property name="text">
|
||||
<string>查看日志</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>在文件系统中查看日志</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@ -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", "在文件系统中查看日志"))
|
||||
|
||||
@ -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):
|
||||
"""下拉框选项变化:切换图片"""
|
||||
# 获取选中项对应的路径关键词
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
10
src/utils.py
10
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='.'):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user