Add basic dark & light theme (#18)
This commit is contained in:
38
gotify_tray/gui/themes/__init__.py
Normal file
38
gotify_tray/gui/themes/__init__.py
Normal 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}")
|
||||
Reference in New Issue
Block a user