From 5b572ff54082fa797c162ea6219472860b4cfa37 Mon Sep 17 00:00:00 2001 From: Sergey Palcheh Date: Thu, 23 Oct 2025 14:00:20 +0600 Subject: [PATCH] added a change in the color of the tray icon depending on the theme --- winehelper_gui.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/winehelper_gui.py b/winehelper_gui.py index 34fce28..7cf8eb7 100644 --- a/winehelper_gui.py +++ b/winehelper_gui.py @@ -14,7 +14,7 @@ from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QH QTextEdit, QFileDialog, QMessageBox, QLineEdit, QCheckBox, QStackedWidget, QScrollArea, QFormLayout, QGroupBox, QRadioButton, QComboBox, QListWidget, QListWidgetItem, QGridLayout, QFrame, QDialog, QTextBrowser, QInputDialog, QDialogButtonBox, QSystemTrayIcon, QMenu) from PyQt5.QtCore import Qt, QProcess, QSize, QTimer, QProcessEnvironment, QPropertyAnimation, QEasingCurve, pyqtSignal, QRect -from PyQt5.QtGui import QIcon, QFont, QTextCursor, QPixmap, QPainter, QCursor, QTextCharFormat, QColor +from PyQt5.QtGui import QIcon, QFont, QTextCursor, QPixmap, QPainter, QCursor, QTextCharFormat, QColor, QPalette from PyQt5.QtNetwork import QLocalServer, QLocalSocket @@ -1759,8 +1759,23 @@ class WineHelperGUI(QMainWindow): self.tray_icon = QSystemTrayIcon(self) + # --- Определение цвета иконки в зависимости от темы --- if Var.WH_ICON_TRAY and os.path.exists(Var.WH_ICON_TRAY): - self.tray_icon.setIcon(self.create_colorized_icon(Var.WH_ICON_TRAY, "#0078d7")) + # Получаем цвет текста окна из палитры приложения. + # Это хороший индикатор для определения контрастного цвета. + window_text_color = self.palette().color(QPalette.WindowText) + + # Если цвет текста светлый (высокая яркость), значит, тема темная. + # И наоборот: если цвет текста темный, тема светлая. + # Яркость > 127 обычно указывает на светлый цвет. + is_dark_theme = window_text_color.lightness() > 127 + + if is_dark_theme: + # Для темных тем используем белую иконку + self.tray_icon.setIcon(self.create_colorized_icon(Var.WH_ICON_TRAY, Qt.white)) + else: + # Для светлых тем используем черную иконку + self.tray_icon.setIcon(self.create_colorized_icon(Var.WH_ICON_TRAY, Qt.black)) # Создаем и сохраняем меню как атрибут класса, чтобы оно не удалялось self.tray_menu = QMenu(self)