forked from AG_QGIS/Plugin_SN_Basis
Wrappe modular aufgebaut, Tests erfolgreich, Menüleiste und Werzeugleiste werden eingetragen (QT6 und QT5)- (Es fehlen noch Fachplugins, um zu prüfen, ob es auch wirklich in QGIS geht)
This commit is contained in:
40
functions/ly_visibility_wrapper.py
Normal file
40
functions/ly_visibility_wrapper.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# sn_basis/functions/ly_visibility_wrapper.py
|
||||
|
||||
def is_layer_visible(layer) -> bool:
|
||||
if layer is None:
|
||||
return False
|
||||
|
||||
visible = getattr(layer, "visible", None)
|
||||
if visible is not None:
|
||||
return bool(visible)
|
||||
|
||||
try:
|
||||
is_visible = getattr(layer, "isVisible", None)
|
||||
if callable(is_visible):
|
||||
return bool(is_visible())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def set_layer_visible(layer, visible: bool) -> bool:
|
||||
if layer is None:
|
||||
return False
|
||||
|
||||
try:
|
||||
if hasattr(layer, "visible"):
|
||||
layer.visible = bool(visible)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
node = getattr(layer, "treeLayer", lambda: None)()
|
||||
if node and callable(getattr(node, "setItemVisibilityChecked", None)):
|
||||
node.setItemVisibilityChecked(bool(visible))
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user