mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-03 12:28:00 +03:00
Make AppQPushButton theme aware in "Furious/Qt/QtWidgets.py"
Signed-off-by: LorenEteval <loren.eteval@proton.me>
This commit is contained in:
committed by
Loren Eteval
parent
21a99fe3ff
commit
c2aa2517d8
+57
-1
@@ -30,6 +30,8 @@ from PySide6.QtWidgets import *
|
||||
|
||||
from typing import Union
|
||||
|
||||
import functools
|
||||
|
||||
__all__ = [
|
||||
'moveToCenter',
|
||||
'AppQCheckBox',
|
||||
@@ -449,10 +451,64 @@ class AppQMessageBox(Mixins.QTranslatable, Mixins.ConnectionAware, QMessageBox):
|
||||
self.setWindowIcon(AppHue.connectedWindowIcon())
|
||||
|
||||
|
||||
class AppQPushButton(Mixins.QTranslatable, QPushButton):
|
||||
class AppQPushButton(Mixins.QTranslatable, Mixins.ThemeAware, QPushButton):
|
||||
def __init__(self, *args, **kwargs):
|
||||
icon = kwargs.pop('icon', None)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.iconFileName = ''
|
||||
|
||||
if icon is not None:
|
||||
self.setIcon(icon)
|
||||
|
||||
@staticmethod
|
||||
@functools.lru_cache(None)
|
||||
def getIconFileName(fileName):
|
||||
try:
|
||||
return fileName.split('/')[-1]
|
||||
except Exception:
|
||||
# Any non-exit exceptions
|
||||
|
||||
return ''
|
||||
|
||||
def setIconByTheme(self, theme):
|
||||
if not self.iconFileName:
|
||||
return
|
||||
|
||||
if AppSettings.isStateON_('DarkMode'):
|
||||
# Custom dark mode
|
||||
super().setIcon(bootstrapIconWhite(self.iconFileName))
|
||||
|
||||
return
|
||||
|
||||
if theme == 'Dark':
|
||||
if PLATFORM == 'Windows':
|
||||
# Windows
|
||||
if versionToValue(PYSIDE6_VERSION) < versionToValue('6.7.0'):
|
||||
# PySide6 < 6.7.0 has no system theme handling on Windows.
|
||||
# Always use black icon
|
||||
super().setIcon(bootstrapIcon(self.iconFileName))
|
||||
else:
|
||||
# PySide6 has system theme handling.
|
||||
super().setIcon(bootstrapIconWhite(self.iconFileName))
|
||||
else:
|
||||
super().setIcon(bootstrapIconWhite(self.iconFileName))
|
||||
else:
|
||||
super().setIcon(bootstrapIcon(self.iconFileName))
|
||||
|
||||
def setIcon(self, icon: AppQIcon):
|
||||
self.iconFileName = self.getIconFileName(icon.iconFileName)
|
||||
|
||||
if not self.iconFileName:
|
||||
# Fall back
|
||||
super().setIcon(icon)
|
||||
else:
|
||||
self.setIconByTheme(APP().theme())
|
||||
|
||||
def themeChangedCallback(self, theme):
|
||||
self.setIconByTheme(theme)
|
||||
|
||||
def retranslate(self):
|
||||
self.setText(_(self.text()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user