Imports für sn_Verfahrensgebiet ergänzt, Stilprüfer wird jetzt auch für apply_style verwendet

This commit is contained in:
2026-03-06 10:20:40 +01:00
parent 3b56725e4f
commit 5dc8412a6a
7 changed files with 203 additions and 40 deletions

View File

@@ -1,23 +1,44 @@
# sn_basis/functions/ly_style_wrapper.py
from sn_basis.functions.ly_existence_wrapper import layer_exists
from sn_basis.functions.sys_wrapper import (
get_plugin_root,
join_path,
file_exists,
)
from sn_basis.functions.sys_wrapper import get_plugin_root, join_path
from sn_basis.modules.stilpruefer import Stilpruefer
from typing import Optional
def apply_style(layer, style_name: str) -> bool:
"""
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")
if not layer_exists(layer):
return False
style_path = join_path(get_plugin_root(), "styles", style_name)
if not file_exists(style_path):
# 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:
return False
# Stil anwenden
try:
ok, _ = layer.loadNamedStyle(style_path)
ok, _ = layer.loadNamedStyle(str(ergebnis.kontext))
if ok:
getattr(layer, "triggerRepaint", lambda: None)()
return True