Fix icon loading in PyInstaller builds

PyInstaller bundles data files into sys._MEIPASS, not the executable directory.

- Add get_resource_path() helper in main.py and main_window.py
- Use _MEIPASS for bundled resources (icon, web files)
- Keep app_dir pointing to executable directory for user data (macros.json)

This fixes the missing icon in taskbar and system tray on Windows builds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-03 17:12:39 -08:00
parent 9bba673ba7
commit 418407b2b9
2 changed files with 30 additions and 9 deletions

View File

@@ -5,6 +5,15 @@ import sys
import threading
from typing import Optional
def get_resource_path(relative_path):
"""Get the path to a bundled resource file."""
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
from PySide6.QtWidgets import (
QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QPushButton, QTabWidget, QGridLayout,
@@ -293,11 +302,12 @@ class MainWindow(QMainWindow):
"""Setup system tray icon."""
self.tray_icon = QSystemTrayIcon(self)
# Load icon
icon_path = os.path.join(self.app_dir, "Macro Pad.png")
# Load icon from bundled resources
icon_path = get_resource_path("Macro Pad.png")
if os.path.exists(icon_path):
self.tray_icon.setIcon(QIcon(icon_path))
self.setWindowIcon(QIcon(icon_path))
icon = QIcon(icon_path)
self.tray_icon.setIcon(icon)
self.setWindowIcon(icon)
else:
self.tray_icon.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_ComputerIcon))