forked from CastroFidel/winehelper
added a change in the color of the tray icon depending on the theme
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user