[GRASS-SVN] r58945 - in grass/trunk/gui/wxpython: lmgr mapdisp vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Feb 7 15:13:36 PST 2014


Author: martinl
Date: 2014-02-07 15:13:35 -0800 (Fri, 07 Feb 2014)
New Revision: 58945

Modified:
   grass/trunk/gui/wxpython/lmgr/layertree.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/vdigit/toolbars.py
Log:
wxGUI: change icon of layer item when start/stop editing


Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py	2014-02-07 21:42:11 UTC (rev 58944)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py	2014-02-07 23:13:35 UTC (rev 58945)
@@ -102,7 +102,9 @@
     'layerWMS'      :  MetaIcon(img = 'layer-wms-add',
                             label = _('Add WMS layer.')),
     'layerOptions'  : MetaIcon(img = 'options',
-                               label = _('Set options'))
+                               label = _('Set options')),
+    'layerEdited'     : MetaIcon(img = 'edit',
+                               label = _("Editing mode"))
     }
 
 class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
@@ -215,7 +217,7 @@
                          "layerRastnum", "layerVector", "layerThememap",
                          "layerThemechart", "layerGrid", "layerGeodesic",
                          "layerRhumb", "layerLabels", "layerCmd",
-                         "layerWMS"):
+                         "layerWMS", "layerEdited"):
             iconKey = iconName[len("layer"):].lower()
             icon = LMIcons[iconName].GetBitmap(self.bmpsize)
             self._icon[iconKey] = il.Add(icon)
@@ -261,7 +263,9 @@
 
         return None
 
-    def _setIcon(self, item, iconName):
+    def SetItemIcon(self, item, iconName=None):
+        if not iconName:
+            iconName = self.GetLayerInfo(item, key = 'maplayer').GetType()
         self.SetItemImage(item, self._icon[iconName])
         
     def _setGradient(self, iType = None):
@@ -854,12 +858,7 @@
     def OnStartEditing(self, event):
         """!Start editing vector map layer requested by the user
         """
-        try:
-            maplayer = self.GetLayerInfo(self.layer_selected, key = 'maplayer')
-        except:
-            event.Skip()
-            return
-        
+        mapLayer = self.GetLayerInfo(self.layer_selected, key = 'maplayer')
         if not haveVDigit:
             from vdigit import errorMsg
             
@@ -871,25 +870,28 @@
         
         if not self.mapdisplay.GetToolbar('vdigit'): # enable tool
             self.mapdisplay.AddToolbar('vdigit')
+
         else: # tool already enabled
             pass
         
         # mark layer as 'edited'
-        self.mapdisplay.toolbars['vdigit'].StartEditing(maplayer)
+        self.mapdisplay.toolbars['vdigit'].StartEditing(mapLayer)
         
+    def StartEditing(self, layerItem):
         self._setGradient('vdigit')
-        self.RefreshLine(self.layer_selected)
+        if layerItem:
+            self.SetItemIcon(layerItem, 'edited')
+            self.RefreshLine(layerItem)
         
     def OnStopEditing(self, event):
         """!Stop editing the current vector map layer
         """
-        maplayer = self.GetLayerInfo(self.layer_selected, key = 'maplayer')
-        
         self.mapdisplay.toolbars['vdigit'].OnExit()
-        # here was dead code to enable vdigit button in toolbar
 
+    def StopEditing(self, layerItem):
         self._setGradient()
-        self.RefreshLine(self.layer_selected)
+        self.SetItemIcon(layerItem)
+        self.RefreshLine(layerItem)
 
     ### unused since r58937
     # def OnSetBgMap(self, event):

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2014-02-07 21:42:11 UTC (rev 58944)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2014-02-07 23:13:35 UTC (rev 58945)
@@ -285,8 +285,7 @@
         self._mgr.GetPane('vdigit').Show()
         self.toolbars['vdigit'] = VDigitToolbar(parent=self, toolSwitcher=self._toolSwitcher,
                                                 MapWindow = self.MapWindow,
-                                                digitClass=VDigit, giface=self._giface,
-                                                layerTree=self.tree)
+                                                digitClass=VDigit, giface=self._giface)
         self.MapWindowVDigit.SetToolbar(self.toolbars['vdigit'])
         
         self._mgr.AddPane(self.toolbars['vdigit'],

Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py	2014-02-07 21:42:11 UTC (rev 58944)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py	2014-02-07 23:13:35 UTC (rev 58945)
@@ -6,7 +6,7 @@
 List of classes:
  - toolbars::VDigitToolbar
 
-(C) 2007-2013 by the GRASS Development Team
+(C) 2007-2014 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -34,10 +34,9 @@
     """!Toolbar for digitization
     """
     def __init__(self, parent, toolSwitcher, MapWindow, digitClass, giface,
-                 tools=[], layerTree=None):
+                 tools=[]):
         self.MapWindow     = MapWindow
         self.Map           = MapWindow.GetMap() # Map class instance
-        self.layerTree     = layerTree  # reference to layer tree associated to map display
         self.tools         = tools
         self.digitClass    = digitClass
         BaseToolbar.__init__(self, parent, toolSwitcher)
@@ -45,6 +44,11 @@
         self._giface       = giface
         
         self.editingStarted = Signal("VDigitToolbar.editingStarted")
+        self.editingStopped = Signal("VDigitToolbar.editingStopped")
+        layerTree = self._giface.GetLayerTree()
+        if layerTree:
+            self.editingStarted.connect(layerTree.StartEditing)
+            self.editingStopped.connect(layerTree.StopEditing)
 
         # currently selected map layer for editing (reference to MapLayer instance)
         self.mapLayer = None
@@ -562,7 +566,7 @@
         
         # select background map
         dlg = VectorDialog(self.parent, title = _("Select background vector map"),
-                           layerTree = self.layerTree)
+                           layerTree = self._giface.GetLayerTree())
         if dlg.ShowModal() != wx.ID_OK:
             dlg.Destroy()
             return
@@ -768,7 +772,7 @@
             
             if dlg and dlg.GetName():
                 # add layer to map layer tree
-                if self.layerTree:
+                if self._giface.GetLayerTree():
                     mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
                     self._giface.GetLayerList().AddLayer(ltype='vector',
                                                          name=mapName,
@@ -808,7 +812,7 @@
         
         event.Skip()
         
-    def StartEditing (self, mapLayer):
+    def StartEditing(self, mapLayer):
         """!Start editing selected vector map layer.
 
         @param mapLayer MapLayer to be edited
@@ -893,8 +897,15 @@
         if opacity < 1.0:
             alpha = int(opacity * 255)
             self.digit.GetDisplay().UpdateSettings(alpha = alpha)
-        
-        self.editingStarted.emit(vectMap = mapLayer.GetName(), digit = self.digit)
+
+        # emit signal
+        layerTree = self._giface.GetLayerTree()
+        if layerTree:
+            item = layerTree.FindItemByData('maplayer', self.mapLayer)
+        else:
+            item = None
+        self.editingStarted.emit(vectMap = mapLayer.GetName(), digit = self.digit, layerItem = item)
+
         return True
 
     def StopEditing(self):
@@ -903,6 +914,8 @@
         @return True on success
         @return False on failure
         """
+        item = None
+        
         if self.combo:
             self.combo.SetValue (_('Select vector map'))
         
@@ -932,19 +945,15 @@
                                 internal = True):
                 self.digit.CloseBackgroundMap()
             
-            # TODO: replace by giface
-            lmgr = self.parent.GetLayerManager()
-            if lmgr:
-                # here was dead code to enable vdigit button in toolbar
-                # some signal (DigitizerEnded) can be emitted here
-                lmgr._giface.GetProgress().SetValue(0)
-                lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
-                                                    self.mapLayer.GetName(),
-                                                notification=Notification.HIGHLIGHT)
-            # re-active layer 
-            if self.parent.tree:
-                item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
-                if item and self.parent.tree.IsItemChecked(item):
+            self._giface.GetProgress().SetValue(0)
+            self._giface.WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
+                                         self.mapLayer.GetName(),
+                                     notification=Notification.HIGHLIGHT)
+            # re-active layer
+            layerTree = self._giface.GetLayerTree()
+            if layerTree:
+                item = layerTree.FindItemByData('maplayer', self.mapLayer)
+                if item and layerTree.IsItemChecked(item):
                     self.Map.ChangeLayerActive(self.mapLayer, True)
         
         # change cursor
@@ -959,11 +968,13 @@
         
         del self.digit
         del self.MapWindow.digit
+
+        self.editingStopped.emit(layerItem = item)
         
         self.mapLayer = None
         
         self.MapWindow.redrawAll = True
-        
+
         return True
     
     def UpdateListOfLayers (self, updateTool = False):



More information about the grass-commit mailing list