feat(添加favicon)

This commit is contained in:
marcinlei@outlook.com 2025-08-24 22:37:27 +08:00
parent 5169a6c759
commit f58eda0421
12 changed files with 118 additions and 48 deletions

@ -1,6 +1,23 @@
# -*- mode: python ; coding: utf-8 -*-
import os
import sys
from PyInstaller.utils.hooks import collect_data_files
block_cipher = None
# 获取spec文件所在目录项目根目录
spec_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
# 定义需要打包的资源文件
resource_files = [
# 将resource文件夹下的所有文件打包到程序内的resource目录
(os.path.join(spec_dir, 'resource'), 'resource')
]
# 收集PyQt相关的数据文件
qt_data = collect_data_files('PyQt5')
# 合并所有资源文件
all_resources = resource_files + qt_data
# 定义所有需要打包的文件和依赖
a = Analysis(
@ -43,5 +60,7 @@ exe = EXE(
target_arch=None,
codesign_identity=None,
entitlements_file=None,
# 指定程序图标使用resources文件夹中的ico文件
icon=os.path.join(spec_dir, 'resource','favicon.ico'),
)

BIN
resource/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -0,0 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}

@ -1,13 +1,30 @@
import os
import sys
import service
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QIcon
from main_window import MainWindow # 导入重构后的主窗口类
if __name__ == "__main__":
# Windows系统特定设置确保任务栏图标正确显示
try:
from ctypes import windll
myappid = 'marcin.ZiJin.onekeydiag.1.0' # 自定义唯一ID
windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except ImportError:
pass # 非Windows系统忽略
# 初始化服务缓存
service.app_cache_init()
# 创建PyQt应用实例
app = QApplication(sys.argv)
# 获取文件系统中存放的icon
icon_path = service.get_icon_path()
if os.path.exists(icon_path):
app.setWindowIcon(QIcon(icon_path))
else:
print("not found favicon")
# 初始化并显示主窗口
window = MainWindow()
window.show()

@ -43,7 +43,17 @@ def app_cache_init():
utils.clean_log_data(cache_dir)
os.mkdir(cache_dir)
pass
def get_icon_path():
"""获取资源文件的绝对路径"""
try:
# 打包后的环境
base_path = sys._MEIPASS
except AttributeError:
# 开发环境:
base_path = utils.get_project_root()
resource_dir = os.path.join(base_path, "resource")
return os.path.join(resource_dir, "favicon.ico")
def send_log_to_cache(filepath):
project_root = utils.get_project_root()

@ -5,7 +5,8 @@ from PyQt5.QtWidgets import (QApplication, QWidget, QGraphicsView, QGraphicsScen
QGraphicsTextItem, QToolTip, QVBoxLayout,
QTabWidget, QLabel)
from PyQt5.QtCore import Qt, QEvent, QTimer, QPoint
from PyQt5.QtGui import QPen, QBrush, QColor, QFont, QPainter
from PyQt5.QtGui import QPen, QBrush, QColor, QFont, QPainter, QIcon
import service
class TimelineEvent:
"""事件数据封装类"""
@ -312,6 +313,10 @@ class TimelineTabContent(QWidget):
self.init_ui()
def init_ui(self):
# 设置窗口图标
icon_path = service.get_icon_path()
self.setWindowIcon(QIcon(icon_path))
layout = QVBoxLayout(self)
title_label = QLabel("事件时间线")