- KDE/Windows accent-driven Material 3 theme, live updating - Library, tabbed playlists, smart/saved lists, queue, ratings - mpv and Qt Multimedia engines, EQ, ReplayGain, gapless - Synced lyrics (LRCLIB, NetEase, local .lrc), covers, MusicBrainz tags - Last.fm/ListenBrainz scrobbling, MPRIS, Windows media keys - Audio CD playback and ripping - PyInstaller, Inno Setup and AppImage builds via GitHub Actions Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01J7imThHV9BMkG24GaxPDeq
601 lines
28 KiB
Python
601 lines
28 KiB
Python
"""Material You colour scheme generated from the user's KDE colours.
|
|
|
|
Reads ~/.config/kdeglobals (accent, window background, font), builds tonal
|
|
palettes in OKLCH space (tone == CIE L*), produces the Material 3 colour roles
|
|
and a Qt stylesheet. The file is watched, so changing the KDE colour scheme or
|
|
accent recolours the player live.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import configparser
|
|
import math
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from PyQt6.QtCore import QFileSystemWatcher, QObject, QTimer, pyqtSignal
|
|
from PyQt6.QtGui import QColor, QFont, QFontDatabase, QImage, QPalette
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
from .config import settings
|
|
|
|
|
|
# ------------------------------------------------------------------ colour math
|
|
def _srgb_to_lin(c):
|
|
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
|
|
|
|
|
def _lin_to_srgb(c):
|
|
return 12.92 * c if c <= 0.0031308 else 1.055 * (c ** (1 / 2.4)) - 0.055
|
|
|
|
|
|
def rgb_to_oklch(r, g, b):
|
|
r, g, b = (_srgb_to_lin(x / 255) for x in (r, g, b))
|
|
l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b
|
|
m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b
|
|
s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b
|
|
l, m, s = (math.copysign(abs(x) ** (1 / 3), x) for x in (l, m, s))
|
|
L = 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s
|
|
A = 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s
|
|
B = 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s
|
|
return L, math.hypot(A, B), math.degrees(math.atan2(B, A)) % 360
|
|
|
|
|
|
def _oklch_to_lin(L, C, H):
|
|
a = C * math.cos(math.radians(H))
|
|
b = C * math.sin(math.radians(H))
|
|
l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3
|
|
m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3
|
|
s = (L - 0.0894841775 * a - 1.2914855480 * b) ** 3
|
|
r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s
|
|
g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s
|
|
bb = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
|
|
return r, g, bb
|
|
|
|
|
|
def oklch_to_qcolor(L, C, H) -> QColor:
|
|
"""Convert with gamut mapping (reduce chroma until it fits sRGB)."""
|
|
lo, hi = 0.0, C
|
|
rgb = _oklch_to_lin(L, C, H)
|
|
if not all(-1e-4 <= x <= 1.0001 for x in rgb):
|
|
for _ in range(18):
|
|
mid = (lo + hi) / 2
|
|
rgb2 = _oklch_to_lin(L, mid, H)
|
|
if all(-1e-4 <= x <= 1.0001 for x in rgb2):
|
|
lo = mid
|
|
else:
|
|
hi = mid
|
|
rgb = _oklch_to_lin(L, lo, H)
|
|
r, g, b = (max(0, min(255, round(_lin_to_srgb(max(0.0, min(1.0, x))) * 255))) for x in rgb)
|
|
return QColor(r, g, b)
|
|
|
|
|
|
def tone_to_L(t: float) -> float:
|
|
"""CIE L* tone (0-100) to OKLab lightness (achromatic identity)."""
|
|
if t <= 8:
|
|
y = t / 903.2963
|
|
return y ** (1 / 3)
|
|
return (t + 16) / 116
|
|
|
|
|
|
def L_to_tone(L: float) -> float:
|
|
y = L ** 3
|
|
return 903.2963 * y if y <= 0.008856 else 116 * L - 16
|
|
|
|
|
|
class Tonal:
|
|
def __init__(self, hue: float, chroma: float):
|
|
self.h, self.c = hue, chroma
|
|
|
|
def __call__(self, tone: float) -> QColor:
|
|
return oklch_to_qcolor(tone_to_L(tone), self.c, self.h)
|
|
|
|
|
|
def mix(a: QColor, b: QColor, t: float) -> QColor:
|
|
return QColor(round(a.red() + (b.red() - a.red()) * t),
|
|
round(a.green() + (b.green() - a.green()) * t),
|
|
round(a.blue() + (b.blue() - a.blue()) * t),
|
|
round(a.alpha() + (b.alpha() - a.alpha()) * t))
|
|
|
|
|
|
def alpha(c: QColor, a: float) -> QColor:
|
|
q = QColor(c)
|
|
q.setAlphaF(max(0.0, min(1.0, a)))
|
|
return q
|
|
|
|
|
|
def rgba(c: QColor, a: float | None = None) -> str:
|
|
a = c.alphaF() if a is None else a
|
|
return f"rgba({c.red()},{c.green()},{c.blue()},{a:.3f})"
|
|
|
|
|
|
def dominant_color(img: QImage) -> QColor | None:
|
|
"""Pick a vivid representative colour from artwork (Material 'score' style)."""
|
|
if img is None or img.isNull():
|
|
return None
|
|
small = img.scaled(48, 48).convertToFormat(QImage.Format.Format_RGB32)
|
|
buckets: dict[int, list] = {}
|
|
for y in range(small.height()):
|
|
for x in range(small.width()):
|
|
c = small.pixelColor(x, y)
|
|
L, C, H = rgb_to_oklch(c.red(), c.green(), c.blue())
|
|
if C < 0.03 or L < 0.2 or L > 0.95:
|
|
continue
|
|
key = int(H // 15)
|
|
b = buckets.setdefault(key, [0.0, 0.0, 0.0, 0.0])
|
|
w = C * C
|
|
b[0] += w
|
|
b[1] += math.cos(math.radians(H)) * w
|
|
b[2] += math.sin(math.radians(H)) * w
|
|
b[3] += C * w
|
|
if not buckets:
|
|
return None
|
|
best = max(buckets.values(), key=lambda b: b[0])
|
|
hue = math.degrees(math.atan2(best[2], best[1])) % 360
|
|
chroma = best[3] / best[0]
|
|
return oklch_to_qcolor(0.65, max(chroma, 0.1), hue)
|
|
|
|
|
|
# ------------------------------------------------------------------ KDE reading
|
|
def _kdeglobals_path() -> Path:
|
|
base = os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config")
|
|
return Path(base) / "kdeglobals"
|
|
|
|
|
|
def _parse_rgb(s: str | None) -> QColor | None:
|
|
if not s:
|
|
return None
|
|
try:
|
|
parts = [int(p) for p in s.split(",")[:3]]
|
|
return QColor(*parts)
|
|
except ValueError:
|
|
c = QColor(s.strip())
|
|
return c if c.isValid() else None
|
|
|
|
|
|
def read_kde() -> dict:
|
|
p = _kdeglobals_path()
|
|
out = {}
|
|
if not p.exists():
|
|
return out
|
|
cp = configparser.ConfigParser(interpolation=None, strict=False)
|
|
cp.optionxform = str
|
|
try:
|
|
cp.read(p, encoding="utf-8")
|
|
except configparser.Error:
|
|
return out
|
|
|
|
def g(sec, key):
|
|
try:
|
|
return cp.get(sec, key)
|
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
return None
|
|
|
|
out["accent"] = _parse_rgb(g("General", "AccentColor")) or _parse_rgb(g("Colors:Selection", "BackgroundNormal"))
|
|
out["window_bg"] = _parse_rgb(g("Colors:Window", "BackgroundNormal"))
|
|
out["view_bg"] = _parse_rgb(g("Colors:View", "BackgroundNormal"))
|
|
out["window_fg"] = _parse_rgb(g("Colors:Window", "ForegroundNormal"))
|
|
font = g("General", "font")
|
|
if font:
|
|
out["font"] = font.split(",")[0]
|
|
try:
|
|
out["font_size"] = float(font.split(",")[1])
|
|
except (IndexError, ValueError):
|
|
pass
|
|
return out
|
|
|
|
|
|
def read_windows() -> dict:
|
|
"""Windows accent colour (DWM) and app light/dark mode from the registry."""
|
|
out = {}
|
|
try:
|
|
import winreg
|
|
except ImportError:
|
|
return out
|
|
|
|
def val(path, name):
|
|
try:
|
|
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as k:
|
|
return winreg.QueryValueEx(k, name)[0]
|
|
except OSError:
|
|
return None
|
|
acc = val(r"Software\Microsoft\Windows\DWM", "AccentColor")
|
|
if acc is None:
|
|
acc = val(r"Software\Microsoft\Windows\DWM", "ColorizationColor")
|
|
if acc is not None: # 0xAARRGGBB
|
|
out["accent"] = QColor((acc >> 16) & 0xFF, (acc >> 8) & 0xFF, acc & 0xFF)
|
|
else: # 0xAABBGGRR
|
|
out["accent"] = QColor(acc & 0xFF, (acc >> 8) & 0xFF, (acc >> 16) & 0xFF)
|
|
light = val(r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme")
|
|
dark = (light == 0) if light is not None else True
|
|
out["window_bg"] = QColor(32, 32, 32) if dark else QColor(243, 243, 243)
|
|
fams = set(QFontDatabase.families())
|
|
out["font"] = next((f for f in ("Segoe UI Variable Text", "Segoe UI") if f in fams), "")
|
|
out["font_size"] = 9.5
|
|
return out
|
|
|
|
|
|
def read_generic() -> dict:
|
|
"""Any other desktop: Qt's own idea of accent + light/dark."""
|
|
out = {}
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
return out
|
|
pal = app.palette()
|
|
try:
|
|
acc = pal.color(QPalette.ColorRole.Accent)
|
|
except AttributeError:
|
|
acc = pal.color(QPalette.ColorRole.Highlight)
|
|
if acc.isValid():
|
|
out["accent"] = acc
|
|
try:
|
|
from PyQt6.QtCore import Qt as _Qt
|
|
scheme = app.styleHints().colorScheme()
|
|
if scheme == _Qt.ColorScheme.Dark:
|
|
out["window_bg"] = QColor(28, 27, 31)
|
|
elif scheme == _Qt.ColorScheme.Light:
|
|
out["window_bg"] = QColor(250, 248, 252)
|
|
except AttributeError:
|
|
pass
|
|
return out
|
|
|
|
|
|
def read_system() -> dict:
|
|
if sys.platform == "win32":
|
|
return read_windows()
|
|
kde = read_kde()
|
|
return kde if kde else read_generic()
|
|
|
|
|
|
# ------------------------------------------------------------------ theme object
|
|
ROLES = (
|
|
"primary onPrimary primaryContainer onPrimaryContainer secondary onSecondary "
|
|
"secondaryContainer onSecondaryContainer tertiary onTertiary tertiaryContainer "
|
|
"onTertiaryContainer error onError surface surfaceDim surfaceBright "
|
|
"surfaceContainerLowest surfaceContainerLow surfaceContainer surfaceContainerHigh "
|
|
"surfaceContainerHighest onSurface onSurfaceVariant outline outlineVariant "
|
|
"inverseSurface inverseOnSurface inversePrimary scrim"
|
|
).split()
|
|
|
|
|
|
class Theme(QObject):
|
|
changed = pyqtSignal()
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.c: dict[str, QColor] = {}
|
|
self.dark = True
|
|
self.font_family = ""
|
|
self.display_family = ""
|
|
self.font_size = 10.0
|
|
self.album_seed: QColor | None = None
|
|
self._watcher = QFileSystemWatcher(self)
|
|
self._watcher.fileChanged.connect(self._on_file)
|
|
self._watcher.directoryChanged.connect(self._on_file)
|
|
self._debounce = QTimer(self, singleShot=True, interval=300)
|
|
self._debounce.timeout.connect(self.rebuild)
|
|
p = _kdeglobals_path()
|
|
if p.exists():
|
|
self._watcher.addPath(str(p))
|
|
if p.parent.exists():
|
|
self._watcher.addPath(str(p.parent))
|
|
# Windows has no file to watch: poll the registry cheaply; everywhere
|
|
# also follow Qt's colour-scheme signal (GNOME, Windows, macOS).
|
|
self._snapshot = None
|
|
if sys.platform == "win32":
|
|
self._poll = QTimer(self, interval=2500)
|
|
self._poll.timeout.connect(self._poll_system)
|
|
self._poll.start()
|
|
try:
|
|
QApplication.instance().styleHints().colorSchemeChanged.connect(lambda *_: self._debounce.start())
|
|
except AttributeError:
|
|
pass
|
|
self.rebuild(emit=False)
|
|
|
|
def _poll_system(self):
|
|
snap = tuple((k, v.rgb() if isinstance(v, QColor) else v) for k, v in sorted(read_windows().items()))
|
|
if self._snapshot is not None and snap != self._snapshot:
|
|
self._debounce.start()
|
|
self._snapshot = snap
|
|
|
|
def __getitem__(self, role) -> QColor:
|
|
return self.c[role]
|
|
|
|
def _on_file(self, *_):
|
|
p = _kdeglobals_path()
|
|
if p.exists() and str(p) not in self._watcher.files():
|
|
self._watcher.addPath(str(p))
|
|
self._debounce.start()
|
|
|
|
def set_album_seed(self, col: QColor | None):
|
|
if settings.get("appearance/color_source") != "album":
|
|
self.album_seed = col
|
|
return
|
|
if col is None and self.album_seed is None:
|
|
return
|
|
if col is not None and self.album_seed is not None and col.rgb() == self.album_seed.rgb():
|
|
return
|
|
self.album_seed = col
|
|
self.rebuild()
|
|
|
|
# -------------------------------------------------------------- generation
|
|
def rebuild(self, emit=True):
|
|
kde = read_system()
|
|
src_mode = settings.get("appearance/color_source")
|
|
seed = None
|
|
if src_mode == "album" and self.album_seed is not None:
|
|
seed = self.album_seed
|
|
elif src_mode == "custom":
|
|
seed = QColor(settings.get("appearance/custom_color"))
|
|
if seed is None or not seed.isValid():
|
|
seed = kde.get("accent") or QColor("#9a7fd1")
|
|
|
|
win = kde.get("window_bg")
|
|
mode = settings.get("appearance/mode")
|
|
if mode == "dark":
|
|
dark = True
|
|
elif mode == "light":
|
|
dark = False
|
|
elif win is not None:
|
|
dark = win.lightnessF() < 0.5
|
|
else:
|
|
dark = True
|
|
self.dark = dark
|
|
|
|
_, sc, sh = rgb_to_oklch(seed.red(), seed.green(), seed.blue())
|
|
pc = min(max(sc, 0.085), 0.15)
|
|
primary = Tonal(sh, pc)
|
|
secondary = Tonal(sh, 0.04)
|
|
tertiary = Tonal((sh + 60) % 360, 0.075)
|
|
err = Tonal(25, 0.17)
|
|
|
|
# neutrals follow the KDE window background (hue/chroma/tone)
|
|
base_tone = None
|
|
if win is not None and src_mode == "kde":
|
|
wl, wc, wh = rgb_to_oklch(win.red(), win.green(), win.blue())
|
|
nh = wh if wc > 0.006 else sh
|
|
nc = min(max(wc, 0.008), 0.035)
|
|
base_tone = L_to_tone(wl)
|
|
else:
|
|
nh, nc = sh, 0.014
|
|
neutral = Tonal(nh, nc)
|
|
nvar = Tonal(nh, max(nc * 1.8, 0.022))
|
|
|
|
if dark:
|
|
st = 6 if base_tone is None else max(3.0, min(base_tone, 16.0))
|
|
c = dict(
|
|
primary=primary(80), onPrimary=primary(20), primaryContainer=primary(30),
|
|
onPrimaryContainer=primary(90), secondary=secondary(80), onSecondary=secondary(20),
|
|
secondaryContainer=secondary(30), onSecondaryContainer=secondary(90),
|
|
tertiary=tertiary(80), onTertiary=tertiary(20), tertiaryContainer=tertiary(30),
|
|
onTertiaryContainer=tertiary(90), error=err(80), onError=err(20),
|
|
surface=neutral(st), surfaceDim=neutral(st), surfaceBright=neutral(st + 18),
|
|
surfaceContainerLowest=neutral(max(st - 2, 1)), surfaceContainerLow=neutral(st + 4),
|
|
surfaceContainer=neutral(st + 6), surfaceContainerHigh=neutral(st + 11),
|
|
surfaceContainerHighest=neutral(st + 16), onSurface=neutral(90),
|
|
onSurfaceVariant=nvar(80), outline=nvar(60), outlineVariant=nvar(30),
|
|
inverseSurface=neutral(90), inverseOnSurface=neutral(20), inversePrimary=primary(40),
|
|
scrim=QColor(0, 0, 0),
|
|
)
|
|
else:
|
|
st = 98 if base_tone is None else max(90.0, min(base_tone, 99.0))
|
|
c = dict(
|
|
primary=primary(40), onPrimary=primary(100), primaryContainer=primary(90),
|
|
onPrimaryContainer=primary(10), secondary=secondary(40), onSecondary=secondary(100),
|
|
secondaryContainer=secondary(90), onSecondaryContainer=secondary(10),
|
|
tertiary=tertiary(40), onTertiary=tertiary(100), tertiaryContainer=tertiary(90),
|
|
onTertiaryContainer=tertiary(10), error=err(40), onError=err(100),
|
|
surface=neutral(st), surfaceDim=neutral(st - 11), surfaceBright=neutral(st),
|
|
surfaceContainerLowest=neutral(100), surfaceContainerLow=neutral(st - 2),
|
|
surfaceContainer=neutral(st - 4), surfaceContainerHigh=neutral(st - 6),
|
|
surfaceContainerHighest=neutral(st - 8), onSurface=neutral(10),
|
|
onSurfaceVariant=nvar(30), outline=nvar(50), outlineVariant=nvar(80),
|
|
inverseSurface=neutral(20), inverseOnSurface=neutral(95), inversePrimary=primary(80),
|
|
scrim=QColor(0, 0, 0),
|
|
)
|
|
self.c = c
|
|
|
|
fam = settings.get("appearance/font") or kde.get("font") or QApplication.font().family()
|
|
self.font_family = fam
|
|
self.font_size = kde.get("font_size", QApplication.font().pointSizeF() or 10.0)
|
|
fams = set(QFontDatabase.families())
|
|
self.display_family = next(
|
|
(f for f in ("Google Sans", "Google Sans Text", "Product Sans", "Rubik", "Outfit",
|
|
"Lexend", "Inter Display", "Inter", "Segoe UI Variable Display",
|
|
"Segoe UI Semibold") if f in fams), fam)
|
|
if settings.get("appearance/font"):
|
|
self.display_family = fam
|
|
if emit:
|
|
self.apply()
|
|
self.changed.emit()
|
|
|
|
def display_font(self, px: int, weight=QFont.Weight.Medium) -> QFont:
|
|
f = QFont(self.display_family)
|
|
f.setPixelSize(px)
|
|
f.setWeight(weight)
|
|
return f
|
|
|
|
# -------------------------------------------------------------- applying
|
|
def apply(self):
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
return
|
|
c = self.c
|
|
pal = QPalette()
|
|
for grp in (QPalette.ColorGroup.Active, QPalette.ColorGroup.Inactive, QPalette.ColorGroup.Disabled):
|
|
dis = grp == QPalette.ColorGroup.Disabled
|
|
fg = alpha(c["onSurface"], 0.38) if dis else c["onSurface"]
|
|
pal.setColor(grp, QPalette.ColorRole.Window, c["surface"])
|
|
pal.setColor(grp, QPalette.ColorRole.WindowText, fg)
|
|
pal.setColor(grp, QPalette.ColorRole.Base, c["surfaceContainerLow"])
|
|
pal.setColor(grp, QPalette.ColorRole.AlternateBase, c["surfaceContainer"])
|
|
pal.setColor(grp, QPalette.ColorRole.Text, fg)
|
|
pal.setColor(grp, QPalette.ColorRole.Button, c["surfaceContainerHigh"])
|
|
pal.setColor(grp, QPalette.ColorRole.ButtonText, fg)
|
|
pal.setColor(grp, QPalette.ColorRole.Highlight, c["secondaryContainer"])
|
|
pal.setColor(grp, QPalette.ColorRole.HighlightedText, c["onSecondaryContainer"])
|
|
pal.setColor(grp, QPalette.ColorRole.ToolTipBase, c["inverseSurface"])
|
|
pal.setColor(grp, QPalette.ColorRole.ToolTipText, c["inverseOnSurface"])
|
|
pal.setColor(grp, QPalette.ColorRole.PlaceholderText, alpha(c["onSurfaceVariant"], 0.7))
|
|
pal.setColor(grp, QPalette.ColorRole.Link, c["primary"])
|
|
pal.setColor(grp, QPalette.ColorRole.BrightText, c["error"])
|
|
pal.setColor(grp, QPalette.ColorRole.Mid, c["outlineVariant"])
|
|
pal.setColor(grp, QPalette.ColorRole.Dark, c["surfaceContainerLowest"])
|
|
pal.setColor(grp, QPalette.ColorRole.Light, c["surfaceContainerHighest"])
|
|
pal.setColor(grp, QPalette.ColorRole.Accent, c["primary"])
|
|
app.setPalette(pal)
|
|
f = QFont(self.font_family)
|
|
f.setPointSizeF(self.font_size)
|
|
app.setFont(f)
|
|
app.setStyleSheet(self.stylesheet())
|
|
|
|
def _asset(self, name: str, color: QColor) -> str:
|
|
from .config import CACHE_DIR
|
|
from .icondata import PATHS
|
|
d = CACHE_DIR / "qss"
|
|
d.mkdir(parents=True, exist_ok=True)
|
|
f = d / f"{name}-{color.name()[1:]}.svg"
|
|
if not f.exists():
|
|
f.write_text(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="48" height="48">'
|
|
f'<path fill="{color.name()}" d="{PATHS[name]}"/></svg>')
|
|
return f.as_posix()
|
|
|
|
def stylesheet(self) -> str:
|
|
c = {k: v.name() for k, v in self.c.items()}
|
|
a_close = self._asset("close", self.c["onSurfaceVariant"])
|
|
a_close_h = self._asset("close", self.c["onSurface"])
|
|
a_check = self._asset("check", self.c["onPrimary"])
|
|
a_down = self._asset("expand_more", self.c["onSurfaceVariant"])
|
|
a_up = self._asset("expand_less", self.c["onSurfaceVariant"])
|
|
a_left = self._asset("chevron_left", self.c["onSurfaceVariant"])
|
|
a_right = self._asset("chevron_right", self.c["onSurfaceVariant"])
|
|
a_bc = self._asset("chevron_right", self.c["onSurfaceVariant"])
|
|
a_bo = self._asset("expand_more", self.c["onSurfaceVariant"])
|
|
hov = rgba(self.c["onSurface"], 0.08)
|
|
prs = rgba(self.c["onSurface"], 0.12)
|
|
sel = c["secondaryContainer"]
|
|
return f"""
|
|
* {{ outline: none; }}
|
|
QMainWindow, QDialog {{ background: {c['surface']}; }}
|
|
QWidget {{ color: {c['onSurface']}; }}
|
|
QToolTip {{ background: {c['inverseSurface']}; color: {c['inverseOnSurface']}; border: none;
|
|
border-radius: 6px; padding: 5px 8px; }}
|
|
QMenuBar {{ background: transparent; padding: 2px 6px; }}
|
|
QMenuBar::item {{ padding: 6px 12px; border-radius: 14px; background: transparent; }}
|
|
QMenuBar::item:selected {{ background: {hov}; }}
|
|
QMenuBar::item:pressed {{ background: {sel}; color: {c['onSecondaryContainer']}; }}
|
|
QMenu {{ background: {c['surfaceContainer']}; border: 1px solid {rgba(self.c['outlineVariant'], 0.5)};
|
|
border-radius: 14px; padding: 8px 0; }}
|
|
QMenu::item {{ padding: 8px 28px 8px 14px; margin: 0 6px; border-radius: 10px; }}
|
|
QMenu::item:selected {{ background: {hov}; }}
|
|
QMenu::item:disabled {{ color: {rgba(self.c['onSurface'], 0.38)}; }}
|
|
QMenu::icon {{ padding-left: 10px; }}
|
|
QMenu::separator {{ height: 1px; background: {c['outlineVariant']}; margin: 6px 14px; }}
|
|
QMenu::indicator {{ width: 16px; height: 16px; margin-left: 8px; }}
|
|
QScrollBar:vertical {{ background: transparent; width: 10px; margin: 4px 2px; }}
|
|
QScrollBar:horizontal {{ background: transparent; height: 10px; margin: 2px 4px; }}
|
|
QScrollBar::handle {{ background: {rgba(self.c['onSurfaceVariant'], 0.35)}; border-radius: 3px; min-height: 32px; min-width: 32px; }}
|
|
QScrollBar::handle:hover {{ background: {rgba(self.c['onSurfaceVariant'], 0.6)}; }}
|
|
QScrollBar::add-line, QScrollBar::sub-line {{ width: 0; height: 0; }}
|
|
QScrollBar::add-page, QScrollBar::sub-page {{ background: transparent; }}
|
|
QLineEdit, QSpinBox, QDoubleSpinBox, QPlainTextEdit, QTextEdit, QDateEdit {{
|
|
background: {c['surfaceContainerHighest']}; border: none; border-bottom: 1px solid {c['onSurfaceVariant']};
|
|
border-top-left-radius: 6px; border-top-right-radius: 6px; padding: 7px 10px;
|
|
selection-background-color: {c['primary']}; selection-color: {c['onPrimary']}; }}
|
|
QLineEdit:focus, QSpinBox:focus, QDoubleSpinBox:focus, QPlainTextEdit:focus, QTextEdit:focus {{
|
|
border-bottom: 2px solid {c['primary']}; }}
|
|
QLineEdit#search {{ background: {c['surfaceContainerHigh']}; border: none; border-radius: 19px;
|
|
padding: 0px 14px 0px 38px; }}
|
|
QLineEdit#search:focus {{ background: {c['surfaceContainerHighest']}; border: none; }}
|
|
QPushButton {{ background: {c['secondaryContainer']}; color: {c['onSecondaryContainer']}; border: none;
|
|
border-radius: 17px; padding: 8px 18px; min-height: 20px; font-weight: 500; }}
|
|
QPushButton:hover {{ background: {rgba(self.c['secondaryContainer'], 0.85)}; }}
|
|
QPushButton:pressed {{ background: {c['secondary']}; color: {c['onSecondary']}; }}
|
|
QPushButton:disabled {{ background: {rgba(self.c['onSurface'], 0.12)}; color: {rgba(self.c['onSurface'], 0.38)}; }}
|
|
QPushButton[primary="true"] {{ background: {c['primary']}; color: {c['onPrimary']}; }}
|
|
QPushButton[primary="true"]:hover {{ background: {rgba(self.c['primary'], 0.88)}; }}
|
|
QPushButton[flat="true"] {{ background: transparent; color: {c['primary']}; }}
|
|
QPushButton[flat="true"]:hover {{ background: {rgba(self.c['primary'], 0.08)}; }}
|
|
QPushButton::menu-indicator {{ width: 0; }}
|
|
QToolButton {{ background: transparent; border: none; border-radius: 18px; padding: 6px; }}
|
|
QToolButton:hover {{ background: {hov}; }}
|
|
QToolButton:pressed {{ background: {prs}; }}
|
|
QToolButton:checked {{ background: {sel}; color: {c['onSecondaryContainer']}; }}
|
|
QToolButton::menu-indicator {{ image: none; width: 0; }}
|
|
QComboBox {{ background: {c['surfaceContainerHighest']}; border: none; border-radius: 10px;
|
|
padding: 7px 12px; min-height: 20px; }}
|
|
QComboBox:hover {{ background: {rgba(self.c['surfaceContainerHighest'], 0.8)}; }}
|
|
QComboBox::drop-down {{ border: none; width: 26px; }}
|
|
QComboBox::down-arrow {{ image: url({a_down}); width: 18px; height: 18px; }}
|
|
QSpinBox::up-button, QSpinBox::down-button, QDoubleSpinBox::up-button, QDoubleSpinBox::down-button {{ border: none; width: 18px; background: transparent; }}
|
|
QSpinBox::up-arrow, QDoubleSpinBox::up-arrow {{ image: url({a_up}); width: 14px; height: 14px; }}
|
|
QSpinBox::down-arrow, QDoubleSpinBox::down-arrow {{ image: url({a_down}); width: 14px; height: 14px; }}
|
|
QComboBox QAbstractItemView {{ background: {c['surfaceContainer']}; border: none; border-radius: 10px;
|
|
padding: 6px; selection-background-color: {sel}; selection-color: {c['onSecondaryContainer']}; }}
|
|
QCheckBox, QRadioButton {{ spacing: 10px; }}
|
|
QCheckBox::indicator, QRadioButton::indicator {{ width: 18px; height: 18px; border-radius: 4px;
|
|
border: 2px solid {c['onSurfaceVariant']}; background: transparent; }}
|
|
QRadioButton::indicator {{ border-radius: 11px; }}
|
|
QCheckBox::indicator:checked {{ background: {c['primary']}; border-color: {c['primary']}; image: url({a_check}); }}
|
|
QRadioButton::indicator:checked {{ background: {c['primary']}; border: 5px solid {c['surfaceContainerHighest']}; outline: none; }}
|
|
QGroupBox {{ background: {c['surfaceContainerLow']}; border: none; border-radius: 16px;
|
|
margin-top: 26px; padding: 14px 12px 10px 12px; font-weight: 600; }}
|
|
QGroupBox::title {{ subcontrol-origin: margin; left: 14px; top: 4px; color: {c['primary']}; }}
|
|
QTabWidget::pane {{ border: none; }}
|
|
QTabBar {{ background: transparent; qproperty-drawBase: 0; }}
|
|
QTabBar::tab {{ background: transparent; color: {c['onSurfaceVariant']}; padding: 8px 14px; margin: 4px 2px;
|
|
border-radius: 16px; min-width: 40px; }}
|
|
QTabBar::tab:hover {{ background: {hov}; color: {c['onSurface']}; }}
|
|
QTabBar::tab:selected {{ background: {sel}; color: {c['onSecondaryContainer']}; font-weight: 600; }}
|
|
QTabBar::close-button {{ subcontrol-position: right; image: url({a_close}); width: 14px; height: 14px;
|
|
border-radius: 7px; padding: 1px; }}
|
|
QTabBar::close-button:hover {{ image: url({a_close_h}); background: {hov}; }}
|
|
QTabBar::scroller {{ width: 28px; }}
|
|
QTabBar QToolButton {{ background: {c['surface']}; border-radius: 12px; }}
|
|
QTabBar QToolButton::left-arrow {{ image: url({a_left}); }}
|
|
QTabBar QToolButton::right-arrow {{ image: url({a_right}); }}
|
|
QTreeView, QListView, QTableView {{ background: transparent; border: none;
|
|
selection-background-color: {sel}; selection-color: {c['onSecondaryContainer']};
|
|
alternate-background-color: {rgba(self.c['onSurface'], 0.025)}; }}
|
|
QTreeView::item, QListView::item {{ padding: 4px 4px; border-radius: 10px; }}
|
|
QTreeView::item:hover, QListView::item:hover {{ background: {hov}; }}
|
|
QTreeView::item:selected, QListView::item:selected {{ background: {sel}; color: {c['onSecondaryContainer']}; }}
|
|
QTreeView::branch {{ background: transparent; }}
|
|
QTreeView::branch:has-children:closed {{ image: url({a_bc}); }}
|
|
QTreeView::branch:has-children:open {{ image: url({a_bo}); }}
|
|
QTableView {{ gridline-color: transparent; }}
|
|
QHeaderView {{ background: transparent; border: none; }}
|
|
QHeaderView::section {{ background: transparent; color: {c['onSurfaceVariant']}; border: none;
|
|
border-bottom: 1px solid {c['outlineVariant']}; padding: 6px 8px; font-weight: 600; }}
|
|
QHeaderView::section:hover {{ background: {hov}; }}
|
|
QHeaderView::down-arrow {{ image: url({a_down}); width: 14px; height: 14px; }}
|
|
QHeaderView::up-arrow {{ image: url({a_up}); width: 14px; height: 14px; }}
|
|
QSplitter::handle {{ background: transparent; }}
|
|
QSplitter::handle:hover {{ background: {rgba(self.c['primary'], 0.25)}; }}
|
|
QProgressBar {{ background: {c['secondaryContainer']}; border: none; border-radius: 3px; max-height: 6px; text-align: center; }}
|
|
QProgressBar::chunk {{ background: {c['primary']}; border-radius: 3px; }}
|
|
QSlider::groove:horizontal {{ height: 6px; background: {c['secondaryContainer']}; border-radius: 3px; }}
|
|
QSlider::sub-page:horizontal {{ background: {c['primary']}; border-radius: 3px; }}
|
|
QSlider::handle:horizontal {{ background: {c['primary']}; width: 4px; margin: -8px 2px; border-radius: 2px; }}
|
|
QSlider::groove:vertical {{ width: 6px; background: {c['secondaryContainer']}; border-radius: 3px; }}
|
|
QSlider::add-page:vertical {{ background: {c['primary']}; border-radius: 3px; }}
|
|
QSlider::handle:vertical {{ background: {c['primary']}; height: 4px; margin: 2px -8px; border-radius: 2px; }}
|
|
QListWidget#navlist {{ background: transparent; }}
|
|
QListWidget#navlist::item {{ padding: 10px 14px; border-radius: 22px; margin: 2px 6px; }}
|
|
QListWidget#navlist::item:selected {{ background: {sel}; color: {c['onSecondaryContainer']}; font-weight: 600; }}
|
|
QFrame#card {{ background: {c['surfaceContainerLow']}; border-radius: 20px; }}
|
|
QLabel#muted {{ color: {c['onSurfaceVariant']}; }}
|
|
QLabel#heading {{ font-size: 15pt; font-weight: 600; }}
|
|
QStatusBar {{ background: transparent; }}
|
|
QDialogButtonBox QPushButton {{ min-width: 72px; }}
|
|
"""
|
|
|
|
|
|
theme: Theme | None = None
|
|
|
|
|
|
def init_theme() -> Theme:
|
|
global theme
|
|
theme = Theme()
|
|
theme.apply()
|
|
return theme
|