Skip to content

Commit c4316f1

Browse files
authored
wxGUI/lmgr: allow change group layer opacity level (OSGeo#3583)
1 parent f877fb8 commit c4316f1

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

gui/wxpython/lmgr/layertree.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,33 @@ def OnLayerContextMenu(self, event):
578578
self.OnAlignCompRegToRaster,
579579
id=self.popupID["align"],
580580
)
581+
elif ltype == "group":
582+
# Dynamically add Change opacity level menu item according
583+
# if any layer inside group layer is map layer
584+
child, cookie = self.GetFirstChild(self.layer_selected)
585+
child_is_maplayer = None
586+
if child:
587+
while child:
588+
child_maplayer = self.GetLayerInfo(child, key="maplayer")
589+
child_ltype = self.GetLayerInfo(child, key="type")
590+
if child_maplayer and child_ltype != "command":
591+
child_is_maplayer = True
592+
break
593+
child = self.GetNextSibling(child)
594+
if child_is_maplayer:
595+
self.popupMenu.AppendSeparator()
596+
item = wx.MenuItem(
597+
self.popupMenu,
598+
id=self.popupID["opacity"],
599+
text=_("Change opacity level"),
600+
)
601+
item.SetBitmap(MetaIcon(img="layer-opacity").GetBitmap(self.bmpsize))
602+
self.popupMenu.AppendItem(item)
603+
self.Bind(
604+
wx.EVT_MENU,
605+
self.OnPopupGroupOpacityLevel,
606+
id=self.popupID["opacity"],
607+
)
581608

582609
# vector layers (specific items)
583610
if ltype and ltype == "vector" and numSelected == 1:
@@ -1189,6 +1216,49 @@ def OnPopupProperties(self, event):
11891216
"""Popup properties dialog"""
11901217
self.PropertiesDialog(self.layer_selected)
11911218

1219+
def OnPopupGroupOpacityLevel(self, event):
1220+
"""Popup opacity level indicator for group of layers"""
1221+
# Get opacity level from the first finded map layer
1222+
child, cookie = self.GetFirstChild(self.layer_selected)
1223+
while child:
1224+
maplayer = self.GetLayerInfo(child, key="maplayer")
1225+
ltype = self.GetLayerInfo(child, key="type")
1226+
if maplayer and ltype != "command":
1227+
break
1228+
child = self.GetNextSibling(child)
1229+
if child is None:
1230+
child, cookie = self.GetNextChild(child, cookie)
1231+
current_opacity = maplayer.GetOpacity()
1232+
dlg = SetOpacityDialog(
1233+
self,
1234+
opacity=current_opacity,
1235+
title=_("Set opacity of <{}>").format(self.layer_selected.GetText()),
1236+
)
1237+
dlg.applyOpacity.connect(
1238+
lambda value: self.ChangeGroupLayerOpacity(layer=child, value=value)
1239+
)
1240+
# Apply button
1241+
dlg.applyOpacity.connect(lambda: self._recalculateLayerButtonPosition())
1242+
dlg.CentreOnParent()
1243+
1244+
if dlg.ShowModal() == wx.ID_OK:
1245+
self.ChangeGroupLayerOpacity(layer=child, value=dlg.GetOpacity())
1246+
self._recalculateLayerButtonPosition()
1247+
dlg.Destroy()
1248+
1249+
def ChangeGroupLayerOpacity(self, layer, value):
1250+
"""Change group layers opacity level
1251+
1252+
:param wx.lib.agw.customtreectrl.GenericTreeItem obj layer: tree item object
1253+
:param int value: opacity value
1254+
"""
1255+
while layer:
1256+
maplayer = self.GetLayerInfo(layer, key="maplayer")
1257+
ltype = self.GetLayerInfo(layer, key="type")
1258+
if maplayer and ltype != "command":
1259+
self.ChangeLayerOpacity(layer=layer, value=value)
1260+
layer = self.GetNextSibling(layer)
1261+
11921262
def OnPopupOpacityLevel(self, event):
11931263
"""Popup opacity level indicator"""
11941264
if not self.GetLayerInfo(self.layer_selected, key="ctrl"):

0 commit comments

Comments
 (0)