farbschema angepasst
This commit is contained in:
1 parent
4503819d13
commit
38ddf6d870
2 files changed
+150
-110
No files matched your search
+61
-13
@@ -75,7 +75,58 @@ DEFAULT_SETTINGS = {
|
||||
"favicon_file": os.environ.get("FAVICON_FILE", ""),
|
||||
}
|
||||
|
||||
DEFAULT_THEME = {'background': '#111', 'surface': '#181818', 'surface_alt': '#222', 'surface_dark': '#0b0b0b', 'text': '#eee', 'text_secondary': '#ccc', 'text_muted': '#aaa', 'text_faint': '#777', 'border': '#333', 'border_subtle': '#2b2b2b', 'control': '#333', 'control_hover': '#444', 'primary': '#1769aa', 'primary_hover': '#1f7fc2', 'accent': '#ffcc33', 'success': '#173d24', 'success_text': '#b8f5c9', 'warning': '#6b4e00', 'danger': '#8b0000', 'danger_soft': '#4a2020', 'danger_soft_hover': '#6a2b2b', 'error': '#4a1b1b', 'error_text': '#ffd0d0', 'recording': '#b00000', 'recording_border': '#3a2222', 'selection': 'rgba(80,150,255,.16)', 'shadow': '#000', 'scroll_thumb': '#777', 'scroll_thumb_hover': '#999', 'scroll_thumb_active': '#aaa', 'live_surface': '#1d1111', 'table_header': '#252525', 'table_text': '#eee', 'footer': '#666', 'white': '#fff','surface_modal':'#202020','overlay':'rgba(0,0,0,.78)'}
|
||||
BASE_THEME = {
|
||||
"background": "#111111", "surface": "#181818", "text": "#eeeeee",
|
||||
"text_secondary": "#cccccc", "primary": "#1769aa", "accent": "#ffcc33",
|
||||
"success": "#2e7d32", "warning": "#ed6c02", "danger": "#d32f2f",
|
||||
}
|
||||
|
||||
BASE_COLOR_LABELS = {
|
||||
"background": "Hintergrund", "surface": "Flächen", "text": "Text",
|
||||
"text_secondary": "Sekundärtext", "primary": "Primärfarbe", "accent": "Akzentfarbe",
|
||||
"success": "Erfolg", "warning": "Warnung", "danger": "Fehler / Gefahr",
|
||||
}
|
||||
|
||||
def _hex_rgb(value):
|
||||
if not isinstance(value, str) or not re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()): return None
|
||||
value = value.strip(); return tuple(int(value[i:i+2], 16) for i in (1, 3, 5))
|
||||
|
||||
def _rgb_hex(rgb):
|
||||
return "#%02x%02x%02x" % tuple(max(0, min(255, round(v))) for v in rgb)
|
||||
|
||||
def _mix(a, b, amount):
|
||||
ra, rb = _hex_rgb(a), _hex_rgb(b)
|
||||
if ra is None or rb is None: return a
|
||||
return _rgb_hex(tuple(x + (y - x) * amount for x, y in zip(ra, rb)))
|
||||
|
||||
def _lighten(value, amount): return _mix(value, "#ffffff", amount)
|
||||
def _darken(value, amount): return _mix(value, "#000000", amount)
|
||||
|
||||
def derive_theme(base):
|
||||
c = dict(BASE_THEME)
|
||||
if isinstance(base, dict):
|
||||
for key in BASE_THEME:
|
||||
value = base.get(key)
|
||||
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()): c[key] = value.strip()
|
||||
bg, surface = c["background"], c["surface"]
|
||||
text, secondary = c["text"], c["text_secondary"]
|
||||
primary, accent = c["primary"], c["accent"]
|
||||
success, warning, danger = c["success"], c["warning"], c["danger"]
|
||||
return {
|
||||
"background": bg, "surface": surface, "surface_alt": _lighten(surface,.12), "surface_dark": _darken(bg,.22),
|
||||
"text": text, "text_secondary": secondary, "text_muted": _mix(secondary,bg,.35), "text_faint": _mix(secondary,bg,.58),
|
||||
"border": _lighten(surface,.28), "border_subtle": _lighten(surface,.16), "control": _lighten(surface,.12), "control_hover": _lighten(surface,.24),
|
||||
"primary": primary, "primary_hover": _lighten(primary,.16), "accent": accent,
|
||||
"success": _darken(success,.42), "success_text": _lighten(success,.68), "warning": _darken(warning,.48),
|
||||
"danger": danger, "danger_soft": _darken(danger,.58), "danger_soft_hover": _darken(danger,.42),
|
||||
"error": _darken(danger,.62), "error_text": _lighten(danger,.70), "recording": _darken(danger,.08), "recording_border": _darken(danger,.52),
|
||||
"selection": "rgba(80,150,255,.16)", "shadow": "#000000", "scroll_thumb": _mix(secondary,bg,.35),
|
||||
"scroll_thumb_hover": _mix(secondary,bg,.18), "scroll_thumb_active": secondary, "live_surface": _mix(danger,bg,.84),
|
||||
"table_header": _lighten(surface,.08), "table_text": text, "footer": _mix(secondary,bg,.50), "white": "#ffffff",
|
||||
"surface_modal": _lighten(surface,.05), "overlay": "rgba(0,0,0,.78)",
|
||||
}
|
||||
|
||||
DEFAULT_THEME = derive_theme(BASE_THEME)
|
||||
|
||||
def load_settings():
|
||||
"""Load UI/branding settings, falling back to environment defaults."""
|
||||
@@ -95,29 +146,26 @@ def load_settings():
|
||||
|
||||
|
||||
def load_theme():
|
||||
"""Load semantic theme colors from settings, then theme.json, then defaults."""
|
||||
theme = dict(DEFAULT_THEME)
|
||||
|
||||
# Keep the existing theme.json as a backwards-compatible fallback.
|
||||
"""Load the base palette and derive all semantic colors."""
|
||||
base = dict(BASE_THEME)
|
||||
if THEME_FILE.is_file():
|
||||
try:
|
||||
data = json.loads(THEME_FILE.read_text(encoding="utf-8"))
|
||||
colors = data.get("colors", data) if isinstance(data, dict) else {}
|
||||
if isinstance(colors, dict):
|
||||
for key in theme:
|
||||
for key in BASE_THEME:
|
||||
value = colors.get(key)
|
||||
if isinstance(value, str) and re.fullmatch(r"(?:#[0-9a-fA-F]{3,8}|rgba?\([^)]*\))", value.strip()):
|
||||
theme[key] = value.strip()
|
||||
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()):
|
||||
base[key] = value.strip()
|
||||
except Exception as exc:
|
||||
print(f"[branding] Theme konnte nicht geladen werden: {exc}", flush=True)
|
||||
|
||||
settings = load_settings()
|
||||
colors = settings.get("colors") if isinstance(settings.get("colors"), dict) else {}
|
||||
for key in theme:
|
||||
for key in BASE_THEME:
|
||||
value = colors.get(key)
|
||||
if isinstance(value, str) and re.fullmatch(r"(?:#[0-9a-fA-F]{3,8}|rgba?\([^)]*\))", value.strip()):
|
||||
theme[key] = value.strip()
|
||||
return theme
|
||||
if isinstance(value, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", value.strip()):
|
||||
base[key] = value.strip()
|
||||
return derive_theme(base)
|
||||
|
||||
|
||||
def theme_css():
|
||||
|
||||
Reference in new issue
Block a user