From c68bcc9abf206e2a9650ed98af85457567ae23b1 Mon Sep 17 00:00:00 2001 From: Sergey Palcheh Date: Thu, 23 Oct 2025 12:38:10 +0600 Subject: [PATCH] added a method to change the color of the tray icon --- winehelper_gui.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/winehelper_gui.py b/winehelper_gui.py index 354c3d2..34fce28 100644 --- a/winehelper_gui.py +++ b/winehelper_gui.py @@ -13,8 +13,8 @@ from functools import partial from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QTabWidget, QTabBar, 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 -from PyQt5.QtGui import QIcon, QFont, QTextCursor, QPixmap, QPainter, QCursor, QTextCharFormat +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.QtNetwork import QLocalServer, QLocalSocket @@ -1739,6 +1739,18 @@ class WineHelperGUI(QMainWindow): self.raise_() self.activateWindow() + def create_colorized_icon(self, icon_path, color): + """Загружает иконку (SVG) и применяет к ней указанный цвет.""" + target_pixmap = QPixmap(icon_path) + if target_pixmap.isNull(): + return QIcon() + + painter = QPainter(target_pixmap) + painter.setCompositionMode(QPainter.CompositionMode_SourceIn) + painter.fillRect(target_pixmap.rect(), QColor(color)) + painter.end() + return QIcon(target_pixmap) + def create_tray_icon(self): """Создает и настраивает иконку в системном трее.""" if not QSystemTrayIcon.isSystemTrayAvailable(): @@ -1747,11 +1759,8 @@ class WineHelperGUI(QMainWindow): self.tray_icon = QSystemTrayIcon(self) - icon_path = Var.WH_ICON_TRAY - if icon_path and os.path.exists(icon_path): - pixmap = QPixmap(icon_path) - if not pixmap.isNull(): - self.tray_icon.setIcon(QIcon(pixmap)) + 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")) # Создаем и сохраняем меню как атрибут класса, чтобы оно не удалялось self.tray_menu = QMenu(self)