[GRASS-SVN] r71251 - grass/trunk/gui/wxpython/lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 8 21:29:17 PDT 2017


Author: annakrat
Date: 2017-07-08 21:29:17 -0700 (Sat, 08 Jul 2017)
New Revision: 71251

Modified:
   grass/trunk/gui/wxpython/lmgr/layertree.py
Log:
wxGUI: fix selection of layers in Layer Manager. When one clicks on the layer button, the layer must be selected so that the context action is applied to the intended layer

Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py	2017-07-09 01:58:04 UTC (rev 71250)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py	2017-07-09 04:29:17 UTC (rev 71251)
@@ -411,6 +411,17 @@
         """Skip event, otherwise causing error when layertree is empty"""
         event.Skip()
 
+    def OnLayerContextMenuButton(self, event):
+        """Contextual menu for item/layer when button pressed"""
+        # determine which tree item has the button
+        button = event.GetEventObject()
+        layer = self.FindItemByWindow(button)
+        if layer:
+            # select the layer in the same way as right click
+            if not self.IsSelected(layer):
+                self.DoSelectItem(layer, True, False)
+            self.OnLayerContextMenu(event)
+
     def OnLayerContextMenu(self, event):
         """Contextual menu for item/layer"""
         if not self.layer_selected:
@@ -1339,7 +1350,7 @@
             ctrl = buttons.GenBitmapButton(
                 self, id=wx.ID_ANY, bitmap=btnbmp, size=(24, 24))
             ctrl.SetToolTipString(_("Click to edit layer settings"))
-            self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenu, ctrl)
+            self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenuButton, ctrl)
         # add layer to the layer tree
         if loadWorkspace:
             # when loading workspace, we always append
@@ -1888,7 +1899,7 @@
             newctrl = buttons.GenBitmapButton(
                 self, id=wx.ID_ANY, bitmap=btnbmp, size=(24, 24))
             newctrl.SetToolTipString(_("Click to edit layer settings"))
-            self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenu, newctrl)
+            self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenuButton, newctrl)
             data = self.GetPyData(dragItem)
 
         elif self.GetLayerInfo(dragItem, key='type') == 'group':
@@ -2174,6 +2185,21 @@
 
         return None
 
+    def FindItemByWindow(self, window):
+        """Find item by window (button for context menu)
+
+        :return: window instance
+        :return: None not found
+        """
+        item = self.GetFirstChild(self.root)[0]
+        while item and item.IsOk():
+            if self.GetItemWindow(item) == window:
+                return item
+
+            item = self.GetNextItem(item)
+
+        return None
+
     def EnableItemType(self, type, enable=True):
         """Enable/disable items in layer tree"""
         item = self.GetFirstChild(self.root)[0]



More information about the grass-commit mailing list