@@ -578,6 +578,33 @@ def OnLayerContextMenu(self, event):
578
578
self .OnAlignCompRegToRaster ,
579
579
id = self .popupID ["align" ],
580
580
)
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
+ )
581
608
582
609
# vector layers (specific items)
583
610
if ltype and ltype == "vector" and numSelected == 1 :
@@ -1189,6 +1216,49 @@ def OnPopupProperties(self, event):
1189
1216
"""Popup properties dialog"""
1190
1217
self .PropertiesDialog (self .layer_selected )
1191
1218
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
+
1192
1262
def OnPopupOpacityLevel (self , event ):
1193
1263
"""Popup opacity level indicator"""
1194
1264
if not self .GetLayerInfo (self .layer_selected , key = "ctrl" ):
0 commit comments