[GRASS-SVN] r57451 - in grass/trunk/gui/wxpython: gui_core psmap vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 13 14:14:53 PDT 2013


Author: martinl
Date: 2013-08-13 14:14:53 -0700 (Tue, 13 Aug 2013)
New Revision: 57451

Modified:
   grass/trunk/gui/wxpython/gui_core/toolbars.py
   grass/trunk/gui/wxpython/psmap/toolbars.py
   grass/trunk/gui/wxpython/vdigit/toolbars.py
   grass/trunk/gui/wxpython/vdigit/wxdigit.py
Log:
wxGUI/vdigit: add button for digitization of area feature


Modified: grass/trunk/gui/wxpython/gui_core/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/toolbars.py	2013-08-13 09:51:46 UTC (rev 57450)
+++ grass/trunk/gui/wxpython/gui_core/toolbars.py	2013-08-13 21:14:53 UTC (rev 57451)
@@ -17,6 +17,7 @@
 """
 
 import platform
+import os
 
 import wx
 
@@ -25,6 +26,7 @@
 from core.utils import _
 from icons.icon import MetaIcon
 from collections import defaultdict
+from core.globalvar import ETCIMGDIR
 
 from grass.pydispatch.signal import Signal
 
@@ -248,7 +250,22 @@
         self.PopupMenu(menu)
         menu.Destroy()
 
+    def CreateSelectionButton(self):
+        """!Add button to toolbar for selection of graphics drawing mode.
 
+        Button must be custom (not toolbar tool) to set smaller width.
+        """
+        arrowPath = os.path.join(ETCIMGDIR, 'small_down_arrow.png')
+        if os.path.isfile(arrowPath) and os.path.getsize(arrowPath):
+            bitmap = wx.Bitmap(name = arrowPath)
+        else:
+            bitmap = wx.ArtProvider.GetBitmap(id = wx.ART_MISSING_IMAGE, client = wx.ART_TOOLBAR)
+        button =  wx.BitmapButton(parent = self, id = wx.ID_ANY, size = ((-1, self.GetSize()[1])),
+                                  bitmap = bitmap, style = wx.NO_BORDER)
+        button.SetToolTipString(_("Select graphics tool"))
+
+        return button
+
 class ToolSwitcher:
     """!Class handling switching tools in toolbar and custom toggle buttons."""
     def __init__(self):

Modified: grass/trunk/gui/wxpython/psmap/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/toolbars.py	2013-08-13 09:51:46 UTC (rev 57450)
+++ grass/trunk/gui/wxpython/psmap/toolbars.py	2013-08-13 21:14:53 UTC (rev 57451)
@@ -14,7 +14,6 @@
 @author Anna Kratochvilova <kratochanna gmail.com>
 """
 
-import os
 import sys
 
 import wx
@@ -23,7 +22,6 @@
 from core.utils import _
 from gui_core.toolbars import BaseToolbar, BaseIcons
 from icons.icon        import MetaIcon
-from core.globalvar    import ETCIMGDIR
 
 class PsMapToolbar(BaseToolbar):
     def __init__(self, parent, toolSwitcher):
@@ -220,19 +218,3 @@
         if event:
             self.drawGraphicsAction = 'rectangleAdd'
             self.parent.OnAddRectangle(event)
-
-    def CreateSelectionButton(self):
-        """!Add button to toolbar for selection of graphics drawing mode.
-
-        Button must be custom (not toolbar tool) to set smaller width.
-        """
-        arrowPath = os.path.join(ETCIMGDIR, 'small_down_arrow.png')
-        if os.path.isfile(arrowPath) and os.path.getsize(arrowPath):
-            bitmap = wx.Bitmap(name = arrowPath)
-        else:
-            bitmap = wx.ArtProvider.GetBitmap(id = wx.ART_MISSING_IMAGE, client = wx.ART_TOOLBAR)
-        button =  wx.BitmapButton(parent = self, id = wx.ID_ANY, size = ((-1, self.GetSize()[1])),
-                                  bitmap = bitmap, style = wx.NO_BORDER)
-        button.SetToolTipString(_("Select graphics tool"))
-
-        return button

Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-13 09:51:46 UTC (rev 57450)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py	2013-08-13 21:14:53 UTC (rev 57451)
@@ -6,7 +6,7 @@
 List of classes:
  - toolbars::VDigitToolbar
 
-(C) 2007-2012 by the GRASS Development Team
+(C) 2007-2013 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.
@@ -72,7 +72,15 @@
             if hasattr(self, tool):
                 tool = getattr(self, tool)
                 self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
+            else:
+                Debug.msg(1, '%s skipped' % tool)
         
+        # custom button for digitization of area/boundary/centroid
+        # TODO: could this be somehow generalized?
+        self.areaButton = self.CreateSelectionButton()
+        self.areaButtonId = self.InsertControl(5, self.areaButton)
+        self.areaButton.Bind(wx.EVT_BUTTON, self.OnAddAreaMenu)
+        
         # realize toolbar
         self.Realize()
         # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
@@ -93,7 +101,7 @@
         """
         data = []
         
-        icons = {
+        self.icons = {
             'addPoint'        : MetaIcon(img = 'point-create',
                                          label = _('Digitize new point'),
                                          desc = _('Left: new point')),
@@ -107,7 +115,7 @@
                                          label = _('Digitize new centroid'),
                                          desc = _('Left: new point')),
             'addArea'         : MetaIcon(img = 'polygon-create',
-                                         label = _('Digitize new area (composition of boundaries without category and one centroid with category)'),
+                                         label = _('Digitize new area'),
                                          desc = _('Left: new point')),
             'addVertex'       : MetaIcon(img = 'vertex-create',
                                          label = _('Add new vertex'),
@@ -156,86 +164,78 @@
         if not self.tools or 'selector' in self.tools:
             data.append((None, ))
         if not self.tools or 'addPoint' in self.tools:
-            data.append(("addPoint", icons["addPoint"],
+            data.append(("addPoint", self.icons["addPoint"],
                          self.OnAddPoint,
                          wx.ITEM_CHECK))
         if not self.tools or 'addLine' in self.tools:
-            data.append(("addLine", icons["addLine"],
+            data.append(("addLine", self.icons["addLine"],
                         self.OnAddLine,
                         wx.ITEM_CHECK))
-        if not self.tools or 'addBoundary' in self.tools:
-            data.append(("addBoundary", icons["addBoundary"],
-                         self.OnAddBoundary,
-                         wx.ITEM_CHECK))
-        if not self.tools or 'addCentroid' in self.tools:
-            data.append(("addCentroid", icons["addCentroid"],
-                         self.OnAddCentroid,
-                         wx.ITEM_CHECK))
         if not self.tools or 'addArea' in self.tools:
-            data.append(("addArea", icons["addArea"],
-                         self.OnAddArea,
-                         wx.ITEM_CHECK))
+            data.append(("addArea", self.icons["addArea"],
+                        self.OnAddAreaTool,
+                        wx.ITEM_CHECK))
         if not self.tools or 'moveVertex' in self.tools:            
-            data.append(("moveVertex", icons["moveVertex"],
+            data.append(("moveVertex", self.icons["moveVertex"],
                          self.OnMoveVertex,
                          wx.ITEM_CHECK))
         if not self.tools or 'addVertex' in self.tools:
-            data.append(("addVertex", icons["addVertex"],
+            data.append(("addVertex", self.icons["addVertex"],
                          self.OnAddVertex,
                          wx.ITEM_CHECK))
         if not self.tools or 'removeVertex' in self.tools:
-            data.append(("removeVertex", icons["removeVertex"],
+            data.append(("removeVertex", self.icons["removeVertex"],
                          self.OnRemoveVertex,
                          wx.ITEM_CHECK))
         if not self.tools or 'editLine' in self.tools:            
-            data.append(("editLine", icons["editLine"],
+            data.append(("editLine", self.icons["editLine"],
                          self.OnEditLine,
                          wx.ITEM_CHECK))
         if not self.tools or 'moveLine' in self.tools:
-            data.append(("moveLine", icons["moveLine"],
+            data.append(("moveLine", self.icons["moveLine"],
                          self.OnMoveLine,
                          wx.ITEM_CHECK))
         if not self.tools or 'deleteLine' in self.tools:
-            data.append(("deleteLine", icons["deleteLine"],
+            data.append(("deleteLine", self.icons["deleteLine"],
                          self.OnDeleteLine,
                          wx.ITEM_CHECK))
         if not self.tools or 'deleteArea' in self.tools:
-            data.append(("deleteArea", icons["deleteArea"],
+            data.append(("deleteArea", self.icons["deleteArea"],
                          self.OnDeleteArea,
                          wx.ITEM_CHECK))
         if not self.tools or 'displayCats' in self.tools:
-            data.append(("displayCats", icons["displayCats"],
+            data.append(("displayCats", self.icons["displayCats"],
                          self.OnDisplayCats,
                          wx.ITEM_CHECK))
         if not self.tools or 'displayAttr' in self.tools:
-            data.append(("displayAttr", icons["displayAttr"],
+            data.append(("displayAttr", self.icons["displayAttr"],
                          self.OnDisplayAttr,
                          wx.ITEM_CHECK))
         if not self.tools or 'additionalSelf.Tools' in self.tools:
-            data.append(("additionalTools", icons["additionalTools"],
+            data.append(("additionalTools", self.icons["additionalTools"],
                          self.OnAdditionalToolMenu,
                          wx.ITEM_CHECK))
         if not self.tools or 'undo' in self.tools or \
                 'redo' in self.tools:
             data.append((None, ))
         if not self.tools or 'undo' in self.tools:
-            data.append(("undo", icons["undo"],
+            data.append(("undo", self.icons["undo"],
                          self.OnUndo))
         if not self.tools or 'redo' in self.tools:
-            data.append(("redo", icons["redo"],
+            data.append(("redo", self.icons["redo"],
                          self.OnRedo))
         if not self.tools or 'settings' in self.tools or \
                 'help' in self.tools or \
                 'quit' in self.tools:
             data.append((None, ))
         if not self.tools or 'settings' in self.tools:
-            data.append(("settings", icons["settings"],
+            data.append(("settings", self.icons["settings"],
                          self.OnSettings))
         if not self.tools or 'help' in self.tools:
-            data.append(("help", icons["help"],
+            data.append(("help", self.icons["help"],
                          self.OnHelp))
         if not self.tools or 'quit' in self.tools:
-            data.append(("quit", icons["quit"],
+            data.append(("quit", self.icons["quit"],
                          self.OnExit))
         
         return self._getToolbarData(data)
@@ -286,34 +286,76 @@
                         'id'   : self.addLine }
         self.MapWindow.mouse['box'] = 'line'
         ### self.MapWindow.polycoords = [] # reset temp line
-                
+
     def OnAddBoundary(self, event):
         """!Add boundary to the vector map layer"""
         Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
+         # reset temp line
         if self.action['desc'] != 'addLine' or \
                 self.action['type'] != 'boundary':
-            self.MapWindow.polycoords = [] # reset temp line
+            self.MapWindow.polycoords = []
+
+        # update icon and tooltip
+        self.SetToolNormalBitmap(self.addArea, self.icons['addBoundary'].GetBitmap())
+        self.SetToolShortHelp(self.addArea, self.icons['addBoundary'].GetLabel())
+
+        # set action
         self.action = { 'desc' : "addLine",
                         'type' : "boundary",
-                        'id'   : self.addBoundary }
+                        'id'   : self.addArea }
         self.MapWindow.mouse['box'] = 'line'
         
     def OnAddCentroid(self, event):
         """!Add centroid to the vector map layer"""
         Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
+
+        # update icon and tooltip
+        self.SetToolNormalBitmap(self.addArea, self.icons['addCentroid'].GetBitmap())
+        self.SetToolShortHelp(self.addArea, self.icons['addCentroid'].GetLabel())
+        
+        # set action
         self.action = { 'desc' : "addLine",
                         'type' : "centroid",
-                        'id'   : self.addCentroid }
+                        'id'   : self.addArea }
         self.MapWindow.mouse['box'] = 'point'
 
     def OnAddArea(self, event):
         """!Add area to the vector map layer"""
         Debug.msg (2, "VDigitToolbar.OnAddArea()")
+        # update icon and tooltip
+        self.SetToolNormalBitmap(self.addArea, self.icons['addArea'].GetBitmap())
+        self.SetToolShortHelp(self.addArea, self.icons['addArea'].GetLabel())
+        
+        # set action
         self.action = { 'desc' : "addLine",
                         'type' : "area",
                         'id'   : self.addArea }
         self.MapWindow.mouse['box'] = 'line'
 
+    def OnAddAreaTool(self, event):
+        """!Area tool activated."""
+        Debug.msg (2, "VDigitToolbar.OnAddAreaTool()")
+        # we need the previous id
+        if 'type' not in self.action or \
+                self.action['type'] in ('addArea', ''): # default action
+            self.OnAddArea(event)
+        elif self.action['type'] == 'addBoundary':
+            self.OnAddBoundary(event)
+        elif self.action['type'] == 'addCentroid':
+            self.OnAddCentroid(event)
+
+    def OnAddAreaMenu(self, event):
+        """!Digitize area menu (add area/boundary/centroid)"""
+        menuItems = []
+        if not self.tools or 'addArea' in self.tools:
+            menuItems.append((self.icons["addArea"], self.OnAddArea))
+        if not self.tools or 'addBoundary' in self.tools:
+            menuItems.append((self.icons["addBoundary"], self.OnAddBoundary))
+        if not self.tools or 'addCentroid' in self.tools:
+            menuItems.append((self.icons["addCentroid"],  self.OnAddCentroid))
+        
+        self._onMenu(menuItems)
+
     def OnExit (self, event = None):
         """!Quit digitization tool"""
         # stop editing of the currently selected map layer

Modified: grass/trunk/gui/wxpython/vdigit/wxdigit.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/wxdigit.py	2013-08-13 09:51:46 UTC (rev 57450)
+++ grass/trunk/gui/wxpython/vdigit/wxdigit.py	2013-08-13 21:14:53 UTC (rev 57451)
@@ -1307,6 +1307,9 @@
         if not self._checkMap():
             return
         
+        # print extra line before building message
+        sys.stdout.write(os.linesep)
+        # build topology, close map
         self._display.CloseMap()
 
     def InitCats(self):



More information about the grass-commit mailing list