Skip to content

Commit

Permalink
wxGUI/lmgr: allow change group layer opacity level (OSGeo#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi authored Apr 12, 2024
1 parent f877fb8 commit c4316f1
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,33 @@ def OnLayerContextMenu(self, event):
self.OnAlignCompRegToRaster,
id=self.popupID["align"],
)
elif ltype == "group":
# Dynamically add Change opacity level menu item according
# if any layer inside group layer is map layer
child, cookie = self.GetFirstChild(self.layer_selected)
child_is_maplayer = None
if child:
while child:
child_maplayer = self.GetLayerInfo(child, key="maplayer")
child_ltype = self.GetLayerInfo(child, key="type")
if child_maplayer and child_ltype != "command":
child_is_maplayer = True
break
child = self.GetNextSibling(child)
if child_is_maplayer:
self.popupMenu.AppendSeparator()
item = wx.MenuItem(
self.popupMenu,
id=self.popupID["opacity"],
text=_("Change opacity level"),
)
item.SetBitmap(MetaIcon(img="layer-opacity").GetBitmap(self.bmpsize))
self.popupMenu.AppendItem(item)
self.Bind(
wx.EVT_MENU,
self.OnPopupGroupOpacityLevel,
id=self.popupID["opacity"],
)

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

def OnPopupGroupOpacityLevel(self, event):
"""Popup opacity level indicator for group of layers"""
# Get opacity level from the first finded map layer
child, cookie = self.GetFirstChild(self.layer_selected)
while child:
maplayer = self.GetLayerInfo(child, key="maplayer")
ltype = self.GetLayerInfo(child, key="type")
if maplayer and ltype != "command":
break
child = self.GetNextSibling(child)
if child is None:
child, cookie = self.GetNextChild(child, cookie)
current_opacity = maplayer.GetOpacity()
dlg = SetOpacityDialog(
self,
opacity=current_opacity,
title=_("Set opacity of <{}>").format(self.layer_selected.GetText()),
)
dlg.applyOpacity.connect(
lambda value: self.ChangeGroupLayerOpacity(layer=child, value=value)
)
# Apply button
dlg.applyOpacity.connect(lambda: self._recalculateLayerButtonPosition())
dlg.CentreOnParent()

if dlg.ShowModal() == wx.ID_OK:
self.ChangeGroupLayerOpacity(layer=child, value=dlg.GetOpacity())
self._recalculateLayerButtonPosition()
dlg.Destroy()

def ChangeGroupLayerOpacity(self, layer, value):
"""Change group layers opacity level
:param wx.lib.agw.customtreectrl.GenericTreeItem obj layer: tree item object
:param int value: opacity value
"""
while layer:
maplayer = self.GetLayerInfo(layer, key="maplayer")
ltype = self.GetLayerInfo(layer, key="type")
if maplayer and ltype != "command":
self.ChangeLayerOpacity(layer=layer, value=value)
layer = self.GetNextSibling(layer)

def OnPopupOpacityLevel(self, event):
"""Popup opacity level indicator"""
if not self.GetLayerInfo(self.layer_selected, key="ctrl"):
Expand Down

0 comments on commit c4316f1

Please sign in to comment.