Add basic dark & light theme (#18)

This commit is contained in:
seird
2022-11-02 19:31:56 +01:00
committed by GitHub
parent 7fd412e80b
commit a8a854ce6b
41 changed files with 833 additions and 52 deletions

View File

@@ -0,0 +1,38 @@
import logging
from PyQt6 import QtGui, QtWidgets
from gotify_tray.utils import get_abs_path
from . import default, dark_purple, light_purple
from gotify_tray.database import Settings
settings = Settings("gotify-tray")
logger = logging.getLogger("gotify-tray")
styles = {
"default": default,
"dark_purple": dark_purple,
"light_purple": light_purple,
}
def set_theme(app: QtWidgets.QApplication, style: str = "default"):
app.setStyle("fusion")
if style not in styles.keys():
logger.error(f"set_style: style {style} is unsupported.")
return
stylesheet = ""
with open(get_abs_path(f"gotify_tray/gui/themes/{style}/style.qss"), "r") as f:
stylesheet += f.read()
app.setPalette(styles[style].get_palette())
app.setStyleSheet(stylesheet)
def get_themes():
return styles.keys()
def get_theme_file(file: str, theme: str = None) -> str:
theme = settings.value("theme", type=str) if not theme else theme
return get_abs_path(f"gotify_tray/gui/themes/{theme}/{file}")