2026-01-08 17:13:51 +01:00
|
|
|
# sn_basis/functions/ly_style_wrapper.py
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
from sn_basis.functions.ly_existence_wrapper import layer_exists
|
2026-03-06 10:20:40 +01:00
|
|
|
from sn_basis.functions.sys_wrapper import get_plugin_root, join_path
|
|
|
|
|
from sn_basis.modules.stilpruefer import Stilpruefer
|
|
|
|
|
from typing import Optional
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
def apply_style(layer, style_name: str) -> bool:
|
2026-03-06 10:20:40 +01:00
|
|
|
"""
|
|
|
|
|
Wendet einen Layerstil an, sofern er gültig ist.
|
|
|
|
|
|
|
|
|
|
- Validierung erfolgt ausschließlich über Stilpruefer
|
|
|
|
|
- Keine eigenen Dateisystem- oder Endungsprüfungen
|
|
|
|
|
- Keine Seiteneffekte bei ungültigem Stil
|
|
|
|
|
"""
|
|
|
|
|
print(">>> apply_style() START")
|
|
|
|
|
|
2025-12-19 14:29:52 +01:00
|
|
|
if not layer_exists(layer):
|
|
|
|
|
return False
|
|
|
|
|
|
2026-03-06 10:20:40 +01:00
|
|
|
# Stilpfad zusammensetzen
|
|
|
|
|
style_path = join_path(get_plugin_root(), "sn_verfahrensgebiet","styles", style_name)
|
|
|
|
|
|
|
|
|
|
# Stil prüfen
|
|
|
|
|
pruefer = Stilpruefer()
|
|
|
|
|
ergebnis = pruefer.pruefe(style_path)
|
|
|
|
|
print(">>> Stilprüfung:", ergebnis)
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
f"[Stilprüfung] ok={ergebnis.ok} | "
|
|
|
|
|
f"aktion={ergebnis.aktion} | "
|
|
|
|
|
f"meldung={ergebnis.meldung}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not ergebnis.ok:
|
2025-12-19 14:29:52 +01:00
|
|
|
return False
|
|
|
|
|
|
2026-03-06 10:20:40 +01:00
|
|
|
# Stil anwenden
|
2025-12-19 14:29:52 +01:00
|
|
|
try:
|
2026-03-06 10:20:40 +01:00
|
|
|
ok, _ = layer.loadNamedStyle(str(ergebnis.kontext))
|
2025-12-19 14:29:52 +01:00
|
|
|
if ok:
|
|
|
|
|
getattr(layer, "triggerRepaint", lambda: None)()
|
|
|
|
|
return True
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return False
|