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
|
|
|
|
|
from sn_basis.functions.sys_wrapper import (
|
|
|
|
|
get_plugin_root,
|
|
|
|
|
join_path,
|
|
|
|
|
file_exists,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_style(layer, style_name: str) -> bool:
|
|
|
|
|
if not layer_exists(layer):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
style_path = join_path(get_plugin_root(), "styles", style_name)
|
|
|
|
|
if not file_exists(style_path):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
ok, _ = layer.loadNamedStyle(style_path)
|
|
|
|
|
if ok:
|
|
|
|
|
getattr(layer, "triggerRepaint", lambda: None)()
|
|
|
|
|
return True
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return False
|