added a method to change the color of the tray icon

This commit is contained in:
Sergey Palcheh
2025-10-23 12:38:10 +06:00
parent 1ad2c6cfa8
commit c68bcc9abf

View File

@@ -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)