forked from AG_QGIS/Plugin_SN_Basis
28 lines
625 B
Python
28 lines
625 B
Python
|
|
# 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
|