forked from CastroFidel/winehelper
added a method to change the color of the tray icon
This commit is contained in:
@@ -13,8 +13,8 @@ from functools import partial
|
|||||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QTabWidget, QTabBar,
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QTabWidget, QTabBar,
|
||||||
QTextEdit, QFileDialog, QMessageBox, QLineEdit, QCheckBox, QStackedWidget, QScrollArea, QFormLayout, QGroupBox, QRadioButton, QComboBox,
|
QTextEdit, QFileDialog, QMessageBox, QLineEdit, QCheckBox, QStackedWidget, QScrollArea, QFormLayout, QGroupBox, QRadioButton, QComboBox,
|
||||||
QListWidget, QListWidgetItem, QGridLayout, QFrame, QDialog, QTextBrowser, QInputDialog, QDialogButtonBox, QSystemTrayIcon, QMenu)
|
QListWidget, QListWidgetItem, QGridLayout, QFrame, QDialog, QTextBrowser, QInputDialog, QDialogButtonBox, QSystemTrayIcon, QMenu)
|
||||||
from PyQt5.QtCore import Qt, QProcess, QSize, QTimer, QProcessEnvironment, QPropertyAnimation, QEasingCurve, pyqtSignal
|
from PyQt5.QtCore import Qt, QProcess, QSize, QTimer, QProcessEnvironment, QPropertyAnimation, QEasingCurve, pyqtSignal, QRect
|
||||||
from PyQt5.QtGui import QIcon, QFont, QTextCursor, QPixmap, QPainter, QCursor, QTextCharFormat
|
from PyQt5.QtGui import QIcon, QFont, QTextCursor, QPixmap, QPainter, QCursor, QTextCharFormat, QColor
|
||||||
from PyQt5.QtNetwork import QLocalServer, QLocalSocket
|
from PyQt5.QtNetwork import QLocalServer, QLocalSocket
|
||||||
|
|
||||||
|
|
||||||
@@ -1739,6 +1739,18 @@ class WineHelperGUI(QMainWindow):
|
|||||||
self.raise_()
|
self.raise_()
|
||||||
self.activateWindow()
|
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):
|
def create_tray_icon(self):
|
||||||
"""Создает и настраивает иконку в системном трее."""
|
"""Создает и настраивает иконку в системном трее."""
|
||||||
if not QSystemTrayIcon.isSystemTrayAvailable():
|
if not QSystemTrayIcon.isSystemTrayAvailable():
|
||||||
@@ -1747,11 +1759,8 @@ class WineHelperGUI(QMainWindow):
|
|||||||
|
|
||||||
self.tray_icon = QSystemTrayIcon(self)
|
self.tray_icon = QSystemTrayIcon(self)
|
||||||
|
|
||||||
icon_path = Var.WH_ICON_TRAY
|
if Var.WH_ICON_TRAY and os.path.exists(Var.WH_ICON_TRAY):
|
||||||
if icon_path and os.path.exists(icon_path):
|
self.tray_icon.setIcon(self.create_colorized_icon(Var.WH_ICON_TRAY, "#0078d7"))
|
||||||
pixmap = QPixmap(icon_path)
|
|
||||||
if not pixmap.isNull():
|
|
||||||
self.tray_icon.setIcon(QIcon(pixmap))
|
|
||||||
|
|
||||||
# Создаем и сохраняем меню как атрибут класса, чтобы оно не удалялось
|
# Создаем и сохраняем меню как атрибут класса, чтобы оно не удалялось
|
||||||
self.tray_menu = QMenu(self)
|
self.tray_menu = QMenu(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user