Automatic theme (#29)

* add "automatic" theme

set the theme and icons based on the system theme

* update the default icons based on system theme

* update pyqt to 6.5.0 to get the colorSchemeChanged callback

* rename style to theme

* remove unused svg files for default theme

* ServerInfoDialog: update feedback colors in dark mode
This commit is contained in:
seird
2023-05-21 11:41:01 +02:00
committed by GitHub
parent 34d81ef6d0
commit bc221d6c8f
17 changed files with 105 additions and 272 deletions

View File

@@ -1,5 +1,5 @@
import logging
from PyQt6 import QtGui, QtWidgets
from PyQt6 import QtCore, QtGui, QtWidgets
from gotify_tray.utils import get_abs_path
from . import default, dark_purple, light_purple
from gotify_tray.database import Settings
@@ -9,28 +9,50 @@ settings = Settings("gotify-tray")
logger = logging.getLogger("gotify-tray")
styles = {
themes = {
"default": default,
"automatic": None,
"dark purple": dark_purple,
"light purple": light_purple,
}
def set_theme(app: QtWidgets.QApplication, style: str = "default"):
if style not in styles.keys():
logger.error(f"set_style: style {style} is unsupported.")
return
def get_themes():
return themes.keys()
def is_dark_mode(app: QtWidgets.QApplication) -> bool:
return app.styleHints().colorScheme() == QtCore.Qt.ColorScheme.Dark
def is_valid_theme(theme: str) -> bool:
return theme in get_themes()
def set_theme(app: QtWidgets.QApplication, theme: str = "automatic"):
if not is_valid_theme(theme):
logger.warning(f"set_theme: theme {theme} is unsupported.")
theme = "automatic"
if theme == "automatic":
theme = "dark purple" if is_dark_mode(app) else "light purple"
stylesheet = ""
with open(get_abs_path(f"gotify_tray/gui/themes/{style.replace(' ', '_')}/style.qss"), "r") as f:
with open(get_abs_path(f"gotify_tray/gui/themes/{theme.replace(' ', '_')}/style.qss"), "r") as f:
stylesheet += f.read()
app.setPalette(styles[style].get_palette())
app.setPalette(themes[theme].get_palette())
app.setStyleSheet(stylesheet)
def get_themes():
return styles.keys()
def get_theme_file(file: str, theme: str = None) -> str:
def get_theme_file(app: QtWidgets.QApplication, file: str, theme: str = None) -> str:
theme = settings.value("theme", type=str) if not theme else theme
if not is_valid_theme(theme):
logger.warning(f"set_theme: theme {theme} is unsupported.")
theme = "automatic"
if theme in ("automatic", "default"):
theme = "dark purple" if is_dark_mode(app) else "light purple"
return get_abs_path(f"gotify_tray/gui/themes/{theme.replace(' ', '_')}/{file}")