feat: application icon for Windows taskbar + exe
- scripts/gen_icon.py: generates 256x256 SSH client icon (dark terminal window with >_ prompt and SSH connection nodes), outputs multi-size ICO (16-256px) + PNG - resources/icon.ico + icon.png: generated icon files - main.py: _get_icon_path() searches _MEIPASS (onefile), exe dir, source dir; sets app + window icon - build.spec: bundles icon files via datas=, sets exe icon=icon.ico - Windows taskbar will now show the custom icon instead of default PyInstaller icon
This commit is contained in:
@@ -20,11 +20,35 @@ _setup_path()
|
||||
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QFont
|
||||
from PyQt5.QtGui import QFont, QIcon, QPixmap
|
||||
|
||||
from ui.main_window import MainWindow, APP_NAME
|
||||
|
||||
|
||||
def _get_icon_path() -> str:
|
||||
"""找到 icon.ico / icon.png 的路径"""
|
||||
# 搜索目录列表:源码运行 / PyInstaller onefile / PyInstaller onedir
|
||||
search_dirs = []
|
||||
if getattr(sys, "frozen", False):
|
||||
# PyInstaller onefile: 资源解压到 _MEIPASS
|
||||
meipass = getattr(sys, "_MEIPASS", None)
|
||||
if meipass:
|
||||
search_dirs.append(Path(meipass))
|
||||
search_dirs.append(Path(meipass) / "resources")
|
||||
# exe 同目录(onedir 模式或用户手动放)
|
||||
search_dirs.append(Path(sys.executable).parent)
|
||||
search_dirs.append(Path(sys.executable).parent / "resources")
|
||||
else:
|
||||
search_dirs.append(Path(__file__).parent)
|
||||
search_dirs.append(Path(__file__).parent / "resources")
|
||||
for d in search_dirs:
|
||||
for name in ("icon.png", "icon.ico"):
|
||||
p = d / name
|
||||
if p.exists():
|
||||
return str(p)
|
||||
return ""
|
||||
|
||||
|
||||
def main():
|
||||
# Windows 上高 DPI 适配
|
||||
if hasattr(Qt, "AA_EnableHighDpiScaling"):
|
||||
@@ -39,7 +63,14 @@ def main():
|
||||
f = QFont("Consolas", 10)
|
||||
app.setFont(f)
|
||||
|
||||
# 设置应用图标(任务栏 + 窗口标题栏)
|
||||
icon_path = _get_icon_path()
|
||||
if icon_path:
|
||||
app.setWindowIcon(QIcon(icon_path))
|
||||
|
||||
w = MainWindow()
|
||||
if icon_path:
|
||||
w.setWindowIcon(QIcon(icon_path))
|
||||
w.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user