feat: Add toolbar icon configuration and update handling for Agravity
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions

This commit is contained in:
claudi 2026-03-12 09:07:14 +01:00
parent eab1009d8c
commit df76cb9b36
8 changed files with 112 additions and 15 deletions

View file

@ -3,6 +3,7 @@
import asyncio
import json
import logging
import os
import re
import subprocess
import sys
@ -1386,16 +1387,13 @@ class MainWindow(QMainWindow):
# Separator
toolbar.addSeparator()
if hasattr(sys, "_MEIPASS"):
icons_dir = Path(sys._MEIPASS) / "resources" / "icons" # type: ignore[attr-defined]
else:
icons_dir = Path(__file__).parent.parent.parent.parent / "resources" / "icons"
# Home button
home_icon_path = icons_dir / "home.ico"
home_icon_path = self._resolve_toolbar_icon_path(
os.getenv("TOOLBAR_ICON_HOME", "resources/icons/home.ico")
)
home_icon = (
QIcon(str(home_icon_path))
if home_icon_path.exists()
if home_icon_path is not None
else self.style().standardIcon(self.style().StandardPixmap.SP_DirHomeIcon)
)
home_action = toolbar.addAction(home_icon, "")
@ -1404,15 +1402,19 @@ class MainWindow(QMainWindow):
# Refresh button
refresh_action = self.web_view.pageAction(self.web_view.page().WebAction.Reload)
reload_icon_path = icons_dir / "reload.ico"
if reload_icon_path.exists():
reload_icon_path = self._resolve_toolbar_icon_path(
os.getenv("TOOLBAR_ICON_RELOAD", "resources/icons/reload.ico")
)
if reload_icon_path is not None:
refresh_action.setIcon(QIcon(str(reload_icon_path)))
toolbar.addAction(refresh_action)
# Open-with-default-app drop zone (right of Reload)
self._open_drop_zone = OpenDropZone()
open_icon_path = icons_dir / "open.ico"
if open_icon_path.exists():
open_icon_path = self._resolve_toolbar_icon_path(
os.getenv("TOOLBAR_ICON_OPEN", "resources/icons/open.ico")
)
if open_icon_path is not None:
self._open_drop_zone.set_icon(QIcon(str(open_icon_path)))
self._open_drop_zone.file_opened.connect(self._on_file_opened_via_drop)
self._open_drop_zone.file_open_failed.connect(self._on_file_open_failed_via_drop)
@ -1422,8 +1424,10 @@ class MainWindow(QMainWindow):
# Open-with chooser drop zone (right of Open-with-default-app)
self._open_with_drop_zone = OpenWithDropZone()
open_with_icon_path = icons_dir / "openwith.ico"
if open_with_icon_path.exists():
open_with_icon_path = self._resolve_toolbar_icon_path(
os.getenv("TOOLBAR_ICON_OPENWITH", "resources/icons/openwith.ico")
)
if open_with_icon_path is not None:
self._open_with_drop_zone.set_icon(QIcon(str(open_with_icon_path)))
self._open_with_drop_zone.file_open_with_requested.connect(
self._on_file_open_with_requested
@ -1467,6 +1471,32 @@ class MainWindow(QMainWindow):
dev_tools_action.setToolTip(tr("toolbar.tooltip.dev_tools"))
dev_tools_action.triggered.connect(self._open_developer_tools)
def _resolve_toolbar_icon_path(self, configured_path: str) -> Path | None:
"""Resolve configured toolbar icon path in both dev and packaged layouts."""
icon_path = Path(configured_path)
candidates: list[Path] = []
if icon_path.is_absolute():
candidates.append(icon_path)
else:
if hasattr(sys, "_MEIPASS"):
meipass = Path(sys._MEIPASS) # type: ignore[attr-defined]
candidates.append(meipass / icon_path)
exe_dir = Path(sys.executable).resolve().parent
candidates.append(exe_dir / icon_path)
candidates.append(exe_dir / "_internal" / icon_path)
project_root = Path(__file__).parent.parent.parent.parent
candidates.append(project_root / icon_path)
for candidate in candidates:
if candidate.exists():
return candidate
logger.warning(f"Toolbar icon not found for configured path: {configured_path}")
return None
def _open_log_file(self) -> None:
"""Open the application log file in the system default text editor.