[GRASS-SVN] r32574 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 6 09:53:51 EDT 2008


Author: martinl
Date: 2008-08-06 09:53:50 -0400 (Wed, 06 Aug 2008)
New Revision: 32574

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
Log:
wxGUI/vdidit: allow to hide currently edited map layer (item checkbox), remember map layer even its position in layer tree is changed
various render-related fixes


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -62,12 +62,13 @@
         self.title = title
         
     def __str__(self):
-        wx.MessageBox(parent=self.parent,
-                      caption=self.title,
-                      message=self.message,
-                      style=wx.ICON_ERROR | wx.CENTRE)
-
-        # return 'GException: %s' % self.message
+        dlg = wx.MessageDialog(parent=self.parent,
+                               caption=self.title,
+                               message=self.message,
+                               style=wx.ICON_ERROR | wx.CENTRE)
+        dlg.SetIcon(wx.Icon(os.path.join(globalvar.ETCDIR, 'grass_error.ico'), wx.BITMAP_TYPE_ICO))
+        dlg.ShowModal()
+        
         return ''
 
 class GStdError(GException):
@@ -429,7 +430,7 @@
                     content = ""
                 
                 if type:
-                    content += line.split(':')[1].strip()
+                    content += line.split(':', 1)[1].strip()
             else: # stderr
                 msg.append((None, line.strip()))
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -681,7 +681,7 @@
         #
         digitToolbar = self.parent.toolbars['vdigit']
         if renderVector and digitToolbar and \
-                digitToolbar.layerSelectedID != None:
+                digitToolbar.GetLayer():
             # set region
             self.parent.digit.driver.UpdateRegion()
             # re-calculate threshold for digitization tool
@@ -689,7 +689,9 @@
             # draw map
             self.pdcVector.Clear()
             self.pdcVector.RemoveAll()
-            self.parent.digit.driver.DrawMap()
+            item = self.tree.FindItemByData('maplayer', digitToolbar.GetLayer())
+            if self.tree.IsItemChecked(item):
+                self.parent.digit.driver.DrawMap()
 
         #
         # render overlays
@@ -1075,13 +1077,12 @@
             east, north = self.Pixel2Cell(self.mouse['begin'])
 
             try:
-                map = digitToolbar.layers[digitToolbar.layerSelectedID].name
+                map = digitToolbar.GetLayer().GetName()
             except:
                 map = None
-                dlg = wx.MessageDialog(self, _("No vector map selected for editing."),
-                                       _("Error"), wx.OK | wx.ICON_ERROR)
-                dlg.ShowModal()
-                dlg.Destroy()
+                wx.MessageBox(parent=self,
+                              message=_("No vector map selected for editing."),
+                              caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
                 event.Skip()
                 return
 
@@ -1706,14 +1707,13 @@
                     digitToolbar.type in ["line", "boundary"]:
                 # -> add new line / boundary
                 try:
-                    map = digitToolbar.layers[digitToolbar.layerSelectedID].name
+                    map = digitToolbar.GetLayer().GetName()
                 except:
                     map = None
-                    dlg = wx.MessageDialog(self, _("No vector map selected for editing."),
-                                           _("Error"), wx.OK | wx.ICON_ERROR)
-                    dlg.ShowModal()
-                    dlg.Destroy()
-
+                    wx.MessageBox(parent=self,
+                                  message=_("No vector map selected for editing."),
+                                  caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+                    
                 if map:
                     # mapcoords = []
                     # xy -> EN

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -132,7 +132,8 @@
                 gcmd.Command(['d.mon',
                               'start=cairo'], stderr=None)
         else:
-            os.environ["GRASS_PNGFILE"] = self.mapfile
+            if self.mapfile:
+                os.environ["GRASS_PNGFILE"] = self.mapfile
 
         #
         # execute command
@@ -189,10 +190,22 @@
         
         return int (self.opacity * 100)
 
-    def GetName(self):
-        """Get map layer name"""
-        return self.name
-    
+    def GetName(self, fullyQualified=True):
+        """Get map layer name
+
+        @param fullyQualified if True return 'name at mapset' otherwise
+        ('name', 'mapset')
+        """
+        if fullyQualified:
+            return self.name
+        else:
+            if '@' in self.name:
+                return { 'name' : self.name.split('@')[0],
+                         'mapset' : self.name.split('@')[1] }
+            else:
+                return { 'name' : self.name,
+                         'mapset' : '' }
+        
     def IsActive(self):
         """Check if layer is activated for rendering"""
         return self.active

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -358,9 +358,10 @@
         self.parent        = parent    # MapFrame
         self.layerTree     = layerTree # reference to layer tree associated to map display
 
-        # selected map to digitize
-        self.layerSelectedID  = None
-        self.layers     = []
+        # currently selected map layer for editing (reference to MapLayer instance)
+        self.mapLayer = None
+        # list of vector layers from Layer Manager (only in the current mapset)
+        self.layers   = [] 
 
         # default action (digitize new point, line, etc.)
         self.action     = "addLine"
@@ -536,10 +537,8 @@
     def OnExit (self, event=None):
         """Quit digitization tool"""
         # stop editing of the currently selected map layer
-        try:
-            self.StopEditing(self.layers[self.layerSelectedID])
-        except:
-            pass
+        if self.mapLayer:
+            self.StopEditing()
 
         # close dialogs if still open
         if self.settingsDialog:
@@ -765,8 +764,8 @@
         selected map layer activated for editing.
         """
         if event.GetSelection() == 0: # create new vector map layer
-            if self.layerSelectedID is not None:
-                openVectorMap = self.layers[self.layerSelectedID].name.split('@')[0]
+            if self.mapLayer:
+                openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
             else:
                 openVectorMap = None
             mapName = gdialogs.CreateNewVector(self.parent,
@@ -790,115 +789,110 @@
         else:
             selection = event.GetSelection() - 1 # first option is 'New vector map'
 
-        if self.layerSelectedID == selection:
+        # skip currently selected map
+        if self.layers[selection] == self.mapLayer:
             return False
 
-        if self.layerSelectedID != None: # deactive map layer for editing
-            self.StopEditing(self.layers[self.layerSelectedID])
+        if self.mapLayer:
+            # deactive map layer for editing
+            self.StopEditing()
 
         # select the given map layer for editing
-        self.layerSelectedID = selection
-        self.StartEditing(self.layers[self.layerSelectedID])
+        self.StartEditing(self.layers[selection])
 
         event.Skip()
 
         return True
-    def StartEditing (self, layerSelected):
+    
+    def StartEditing (self, mapLayer):
         """
-        Start editing of selected vector map layer.
+        Start editing selected vector map layer.
 
-        @param layerSelectedId id of layer to be edited
-        
-        @return True on success
-        @return False on error
+        @param mapLayer reference to MapLayer instance
         """
+        # reload vdigit module
         reload(vdigit)
         from vdigit import Digit as Digit
         self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
+        
+        self.mapLayer = mapLayer
+        
+        # open vector map
         try:
-            self.layerSelectedID = self.layers.index(layerSelected)
-            mapLayer = self.layers[self.layerSelectedID]
-        except:
-            return False
-
-        try:
-            self.parent.digit.SetMapName(mapLayer.name)
+            self.parent.digit.SetMapName(mapLayer.GetName())
         except gcmd.DigitError, e:
-            self.layerSelectedID = None
+            self.mapLayer = None
             print >> sys.stderr, e # wxMessageBox
             return False
-
+        
         # update toolbar
-        self.combo.SetValue (layerSelected.name)
+        self.combo.SetValue(mapLayer.GetName())
         self.parent.toolbars['map'].combo.SetValue ('Digitize')
-        # set initial category number for new features (layer=1), etc.
-
-        Debug.msg (4, "VDigitToolbar.StartEditing(): layerSelectedID=%d layer=%s" % \
-                   (self.layerSelectedID, mapLayer.name))
-
-
+        
+        Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
+        
         # deactive layer
         self.mapcontent.ChangeLayerActive(mapLayer, False)
 
         # change cursor
         if self.parent.MapWindow.mouse['use'] == 'pointer':
             self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
-
+        
         # create pseudoDC for drawing the map
         self.parent.MapWindow.pdcVector = wx.PseudoDC()
         self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
         # self.parent.MapWindow.UpdateMap()
         if not self.parent.MapWindow.resize:
             self.parent.MapWindow.UpdateMap(render=True)
-
+        
         return True
 
-    def StopEditing (self, layerSelected):
-        """
-        Stop editing of selected vector map layer.
-        """
+    def StopEditing (self):
+        """Stop editing of selected vector map layer.
 
-        if self.layers[self.layerSelectedID] == layerSelected:
-            self.layerSelectedID = None
-            Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % \
-                       (layerSelected.name))
-            self.combo.SetValue (_('Select vector map'))
-
-            # save changes (only for vdigit)
-            if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
-                if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
-                    if self.parent.digit.GetUndoLevel() > 0:
-                        dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
-                                                                             "in vector map <%s>?") % layerSelected.name,
-                                               caption=_("Save changes?"),
-                                               style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
-                        if dlg.ShowModal() == wx.ID_NO:
-                            # revert changes
-                            self.parent.digit.Undo(0)
-                        dlg.Destroy()
-
-            self.parent.digit.SetMapName(None) # -> close map
-
-            # re-active layer 
-            item = self.parent.tree.FindItemByData('maplayer', layerSelected)
-            if item and self.parent.tree.IsItemChecked(item):
-                self.mapcontent.ChangeLayerActive(layerSelected, True)
-
-            # change cursor
-            self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
-
-            # disable pseudodc for vector map layer
-            self.parent.MapWindow.pdcVector = None
-            self.parent.digit.driver.SetDevice(None)
-
-            self.parent.digit.__del__() # FIXME: destructor is not called here (del)
-            self.parent.digit = None
-
-            return True
-
+        @return True on success
+        @return False on failure
+        """
+        if not self.mapLayer:
+            return False
         
-        return False
-
+        Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
+        self.combo.SetValue (_('Select vector map'))
+        
+        # save changes (only for vdigit)
+        if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
+            if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
+                if self.parent.digit.GetUndoLevel() > 0:
+                    dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
+                                                                         "in vector map <%s>?") % self.mapLayer.GetName(),
+                                           caption=_("Save changes?"),
+                                           style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+                    if dlg.ShowModal() == wx.ID_NO:
+                        # revert changes
+                        self.parent.digit.Undo(0)
+                    dlg.Destroy()
+        
+        self.parent.digit.SetMapName(None) # -> close map
+        
+        # re-active layer 
+        item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
+        if item and self.parent.tree.IsItemChecked(item):
+            self.mapcontent.ChangeLayerActive(self.mapLayer, True)
+        
+        # change cursor
+        self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
+        
+        # disable pseudodc for vector map layer
+        self.parent.MapWindow.pdcVector = None
+        self.parent.digit.driver.SetDevice(None)
+        
+        self.parent.digit.__del__() # FIXME: destructor is not called here (del)
+        self.parent.digit = None
+        
+        self.mapLayer = None
+        
+        return True
+    
     def UpdateListOfLayers (self, updateTool=False):
         """
         Update list of available vector map layers.
@@ -911,8 +905,9 @@
                    updateTool)
 
         layerNameSelected = None
-        if self.layerSelectedID != None: # name of currently selected layer
-            layerNameSelected = self.layers[self.layerSelectedID].name
+         # name of currently selected layer
+        if self.mapLayer:
+            layerNameSelected = self.mapLayer.GetName()
 
         # select vector map layer in the current mapset
         layerNameList = []
@@ -920,10 +915,10 @@
                                                       l_mapset=grassenv.GetGRASSVariable('MAPSET'))
         for layer in self.layers:
             if not layer.name in layerNameList: # do not duplicate layer
-                layerNameList.append (layer.name)
+                layerNameList.append (layer.GetName())
 
         if updateTool: # update toolbar
-            if self.layerSelectedID == None:
+            if not self.mapLayer:
                 value = _('Select vector map')
             else:
                 value = layerNameSelected
@@ -937,16 +932,14 @@
             else:
                 self.combo.SetItems([_('New vector map'), ] + layerNameList)
             
-            # update layer index
-            try:
-                self.layerSelectedID = layerNameList.index(value)
-            except ValueError:
-                self.layerSelectedID = None
-
             self.toolbar[self.numOfRows-1].Realize()
 
         return layerNameList
 
+    def GetLayer(self):
+        """Get selected layer for editing -- MapLayer instance"""
+        return self.mapLayer
+    
 class ProfileToolbar(AbstractToolbar):
     """
     Toolbar for profiling raster map
@@ -1018,7 +1011,7 @@
              wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
              self.parent.OnQuit),
             )
-
+    
 class NvizToolbar(AbstractToolbar):
     """
     Nviz toolbar

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -836,32 +836,32 @@
         """
         if len(coords) < 2:
             return
-
+        
         if UserSettings.Get(group='vdigit', key="categoryMode", subkey='selection') == 2:
             layer = -1 # -> no category
             cat   = -1
         else:
             layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
             cat   = self.SetCategory()
-
+        
         if line:
             type = wxvdigit.GV_LINE
         else:
             type = wxvdigit.GV_BOUNDARY
-
+        
         listCoords = []
         for c in coords:
             for x in c:
                 listCoords.append(x)
-
+        
         snap, thresh = self.__getSnapThreshold()
-
+        
         ret = self.digit.AddLine(type, listCoords, layer, cat,
                                  str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
-
+        
         if ret == -1:
             raise gcmd.DigitError, _("Adding new feature to vector map <%s> failed.") % map
-
+        
         self.toolbar.EnableUndo()
         
     def DeleteSelectedLines(self):
@@ -870,7 +870,7 @@
         @return number of deleted lines
         """
         nlines = self.digit.DeleteLines(UserSettings.Get(group='vdigit', key='delRecord', subkey='enabled'))
-
+        
         if nlines > 0:
             self.toolbar.EnableUndo()
             
@@ -882,13 +882,13 @@
         @param move direction (x, y)
         """
         snap, thresh = self.__getSnapThreshold()
-
+        
         nlines = self.digit.MoveLines(move[0], move[1], 0.0, # TODO 3D
                                       str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
-
+        
         if nlines > 0:
             self.toolbar.EnableUndo()
-            
+        
         return nlines
 
     def MoveSelectedVertex(self, coords, move):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-08-06 11:18:16 UTC (rev 32573)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-08-06 13:53:50 UTC (rev 32574)
@@ -273,14 +273,14 @@
 
             layer = self.GetPyData(self.layer_selected)[0]['maplayer']
             # enable editing only for vector map layers available in the current mapset
-            digit = self.mapdisplay.toolbars['vdigit']
+            digitToolbar = self.mapdisplay.toolbars['vdigit']
             if layer.GetMapset() != grassenv.GetGRASSVariable("MAPSET"):
                 # only vector map in current mapset can be edited
                 self.popupMenu.Enable (self.popupID5, False)
                 self.popupMenu.Enable (self.popupID6, False)
-            elif digit and digit.layerSelectedID != None:
+            elif digitToolbar and digitToolbar.GetLayer():
                 # vector map already edited
-                if digit.layers[digit.layerSelectedID] == layer:
+                if digitToolbar.GetLayer() is layer:
                     self.popupMenu.Enable (self.popupID5, False)
                     self.popupMenu.Enable(self.popupID6, True)
                     self.popupMenu.Enable(self.popupID1, False)
@@ -535,7 +535,6 @@
             self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenu, ctrl)
         # add layer to the layer tree
         if self.layer_selected and self.layer_selected != self.GetRootItem():
-            
             if self.GetPyData(self.layer_selected)[0]['type'] == 'group' \
                 and self.IsExpanded(self.layer_selected):
                 # add to group (first child of self.layer_selected) if group expanded
@@ -550,6 +549,8 @@
                 elif lgroup is True:
                     # -> last child of group (loading from workspace)
                     parent = self.GetItemParent(self.layer_selected)
+                    if parent is self.root: # first item in group
+                        parent=self.layer_selected
                     layer = self.AppendItem(parentId=parent,
                                             text='', ct_type=1, wnd=ctrl)
                 elif lgroup is None:
@@ -573,7 +574,7 @@
         # select new item
         self.SelectItem(layer, select=True)
         self.layer_selected = layer
-
+        
         # add text and icons for each layer ltype
         if ltype == 'raster':
             self.SetItemImage(layer, self.rast_icon)
@@ -673,10 +674,12 @@
 
         # use predefined layer name if given
         if lname:
-            if ltype != 'command':
-                if opacity:
-                    name = lname + ' (opacity: ' + str(opacity) + '%)'
-                self.SetItemText(layer, name )
+            if ltype == 'group':
+                self.SetItemText(layer, lname)
+            elif ltype != 'command':
+                name = lname + ' (opacity: ' + \
+                       str(self.GetPyData(layer)[0]['maplayer'].GetOpacity()) + '%)'
+                self.SetItemText(layer, name)
             else:
                 ctrl.SetValue(lname)
 
@@ -825,17 +828,26 @@
         """Enable/disable data layer"""
         item    = event.GetItem()
         checked = item.IsChecked()
-        
+
+        digitToolbar = self.mapdisplay.toolbars['vdigit']
         if self.first == False:
             # change active parameter for item in layers list in render.Map
             if self.GetPyData(item)[0]['type'] == 'group':
                 child, cookie = self.GetFirstChild(item)
                 while child:
                     self.CheckItem(child, checked)
-                    self.Map.ChangeLayerActive(self.GetPyData(child)[0]['maplayer'], checked)
+                    mapLayer = self.GetPyData(child)[0]['maplayer']
+                    if not digitToolbar or \
+                           (digitToolbar and digitToolbar.GetLayer() != mapLayer):
+                        # ignore when map layer is edited
+                        self.Map.ChangeLayerActive(mapLayer, checked)
                     child = self.GetNextSibling(child)
             else:
-                self.Map.ChangeLayerActive(self.GetPyData(item)[0]['maplayer'], checked)
+                mapLayer = self.GetPyData(item)[0]['maplayer']
+                if not digitToolbar or \
+                       (digitToolbar and digitToolbar.GetLayer() != mapLayer):
+                    # ignore when map layer is edited
+                    self.Map.ChangeLayerActive(mapLayer, checked)
 
         # update progress bar range (mapwindow statusbar)
         self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))



More information about the grass-commit mailing list