Files
Plugin_SN_Basis/functions/ly_style_wrapper.py

28 lines
625 B
Python
Raw Normal View History

# layer/style.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,
)
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