#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ themes.py Gestionnaire des thèmes graphiques pour series-studio. """ import json import os THEMES_DIR = os.path.join(os.path.dirname(__file__), "themes") def list_themes(): """Renvoie la liste des thèmes disponibles avec métadonnées et fiches.""" themes = [] if not os.path.exists(THEMES_DIR): return themes fiches = {} fiches_path = os.path.join(THEMES_DIR, "fiches.json") if os.path.exists(fiches_path): try: with open(fiches_path, "r", encoding="utf-8") as f: fiches = json.load(f) except Exception: pass for fname in sorted(os.listdir(THEMES_DIR)): if fname.endswith(".json") and fname != "fiches.json": path = os.path.join(THEMES_DIR, fname) try: with open(path, "r", encoding="utf-8") as f: data = json.load(f) th_name = data.get("name", fname[:-5]) th_label = data.get("label", th_name) fiche = fiches.get(th_name, {}) themes.append({ "name": th_name, "label": th_label, "description": data.get("description") or fiche.get("description", ""), "usage": data.get("usage") or fiche.get("usage", ""), "impression_nb": data.get("impression_nb") or fiche.get("impression_nb", "") }) except Exception: pass return themes def get_theme(theme_name="classique"): """Charge les jetons de style d'un thème donné.""" if not theme_name: theme_name = "classique" path = os.path.join(THEMES_DIR, f"{theme_name}.json") if not os.path.exists(path): raise ValueError(f"Thème inconnu : '{theme_name}'") with open(path, "r", encoding="utf-8") as f: return json.load(f)