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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 28 08:12:49 EST 2011


Author: martinl
Date: 2011-01-28 05:12:49 -0800 (Fri, 28 Jan 2011)
New Revision: 45233

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: fix histogram dialog when raster map is not found
(merge r45230 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -15,7 +15,7 @@
  - EditGCP
  - GrSettingsDialog
 
-(C) 2006-2010 by the GRASS Development Team
+(C) 2006-2011 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.
 
@@ -209,9 +209,9 @@
                 cmdlist = ['d.vect', 'map=%s' % src_map]
             
             self.SwitchEnv('source')
+            name, found = utils.GetLayerNameFromCmd(cmdlist)
             self.SrcMap.AddLayer(type=rendertype, command=cmdlist, l_active=True,
-                              name=utils.GetLayerNameFromCmd(cmdlist),
-                              l_hidden=False, l_opacity=1.0, l_render=False)
+                                 name=name, l_hidden=False, l_opacity=1.0, l_render=False)
 
             if tgt_map:
                 #
@@ -225,9 +225,9 @@
                     cmdlist = ['d.vect', 'map=%s' % tgt_map]
                 
                 self.SwitchEnv('target')
+                name, found = utils.GetLayerNameFromCmd(cmdlist)
                 self.TgtMap.AddLayer(type=rendertype, command=cmdlist, l_active=True,
-                                  name=utils.GetLayerNameFromCmd(cmdlist),
-                                  l_hidden=False, l_opacity=1.0, l_render=False)
+                                     name=name, l_hidden=False, l_opacity=1.0, l_render=False)
             
             #
             # start GCP Manager
@@ -2740,9 +2740,9 @@
             src_map = self.new_src_map
             cmdlist = ['d.rast', 'map=%s' % src_map]
             self.parent.grwiz.SwitchEnv('source')
+            name, found = utils.GetLayerNameFromCmd(cmdlist),
             self.parent.grwiz.SrcMap.AddLayer(type='raster', command=cmdlist, l_active=True,
-                              name=utils.GetLayerNameFromCmd(cmdlist),
-                              l_hidden=False, l_opacity=1.0, l_render=False)
+                              name=name, l_hidden=False, l_opacity=1.0, l_render=False)
 
             self.parent.grwiz.SwitchEnv('target')
             srcrender = True
@@ -2756,9 +2756,9 @@
 
             if tgt_map != '':
                 cmdlist = ['d.rast', 'map=%s' % tgt_map]
+                name, found = utils.GetLayerNameFromCmd(cmdlist)
                 self.parent.grwiz.TgtMap.AddLayer(type='raster', command=cmdlist, l_active=True,
-                                  name=utils.GetLayerNameFromCmd(cmdlist),
-                                  l_hidden=False, l_opacity=1.0, l_render=False)
+                                  name=name, l_hidden=False, l_opacity=1.0, l_render=False)
 
                 tgtrender = True
                 if self.parent.show_target == False:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -462,13 +462,13 @@
         self._CreateOverlay()
 
         if len(self.parent.MapWindow.overlays[self.ovlId]['cmd']) > 1:
-            mapName = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.ovlId]['cmd'])
+            mapName, found = utils.GetLayerNameFromCmd(self.parent.MapWindow.overlays[self.ovlId]['cmd'])
             if self.parent.MapWindow.overlays[self.ovlId]['propwin'] is None and mapName:
                 # build properties dialog
                 menuform.GUI().ParseCommand(cmd=self.cmd,
                                             completed=(self.GetOptData, self.name, ''),
                                             parentframe=self.parent, show=False)
-            if mapName:
+            if found:
                 # enable 'OK' button
                 self.btnOK.Enable()
                 if name == 'legend':

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -483,11 +483,11 @@
                 
                 # add layer into layer tree
                 if command[0] == 'd.rast':
-                    lname = utils.GetLayerNameFromCmd(command, fullyQualified = True,
-                                                      layerType = 'raster')
+                    lname, found = utils.GetLayerNameFromCmd(command, fullyQualified = True,
+                                                             layerType = 'raster')
                 elif command[0] == 'd.vect':
-                    lname = utils.GetLayerNameFromCmd(command, fullyQualified = True,
-                                                      layerType = 'vector')
+                    lname, found = utils.GetLayerNameFromCmd(command, fullyQualified = True,
+                                                             layerType = 'vector')
                 else:
                     lname = None
                 
@@ -794,7 +794,8 @@
                         if prompt in ('raster', 'vector', '3d-raster') and \
                                 p.get('age', 'old') == 'new' and \
                                 p.get('value', None):
-                            name = utils.GetLayerNameFromCmd(cmd, fullyQualified=True, param = p.get('name', ''))
+                            name, found = utils.GetLayerNameFromCmd(cmd, fullyQualified = True,
+                                                                    param = p.get('name', ''))
                             
                             if mapTree.GetMap().GetListOfLayers(l_name = name):
                                 continue

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -7,12 +7,12 @@
  - BufferedWindow
  - HistFrame
 
-COPYRIGHT: (C) 2007, 2010 by the GRASS Development Team
+COPYRIGHT: (C) 2007, 2010-2011 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.
 
 @author Michael Barton
- at author Various updates by Martin Landa
+ at author Various updates by Martin Landa <landa.martin gmail.com>
 """
 
 import os
@@ -30,6 +30,7 @@
 from preferences import DefaultFontDialog
 from debug import Debug
 from icon import Icons
+from gcmd import GError
 
 class BufferedWindow(wx.Window):
     """!A Buffered window class.
@@ -244,7 +245,7 @@
         # update statusbar
         # Debug.msg (3, "BufferedWindow.UpdateHist(%s): region=%s" % self.Map.region)
         self.Map.SetRegion()
-        self.parent.statusbar.SetStatusText("Raster/Image map layer <%s>" % self.parent.mapname)
+        self.parent.statusbar.SetStatusText("Image/Raster map <%s>" % self.parent.mapname)
         
         # set default font and encoding environmental variables
         if oldfont != "":
@@ -325,7 +326,13 @@
         created in menuform.py
         """
         if dcmd:
-            name = utils.GetLayerNameFromCmd(dcmd, fullyQualified = True)
+            name, found = utils.GetLayerNameFromCmd(dcmd, fullyQualified = True,
+                                                    layerType = 'raster')
+            if not found:
+                GError(parent = propwin,
+                       message = _("Raster map <%s> not found") % name)
+                return
+            
             self.SetHistLayer(name)
         self.params = params
         self.propwin = propwin

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/layertree.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -789,7 +789,7 @@
             if lcmd and len(lcmd) > 1:
                 cmd = lcmd
                 render = False
-                name = utils.GetLayerNameFromCmd(lcmd)
+                name, found = utils.GetLayerNameFromCmd(lcmd)
             else:
                 cmd = []
                 if ltype == 'command' and lname:
@@ -1314,9 +1314,9 @@
         opacity  = int(mapLayer.GetOpacity(float = True) * 100)
         if not mapname:
             dcmd    = self.GetPyData(item)[0]['cmd']
-            mapname = utils.GetLayerNameFromCmd(dcmd, layerType = mapLayer.GetType(),
-                                                fullyQualified = True)
-        if not mapname:
+            mapname, found = utils.GetLayerNameFromCmd(dcmd, layerType = mapLayer.GetType(),
+                                                       fullyQualified = True)
+        if not found:
             return None
         
         return mapname + ' (%s %d' % (_('opacity:'), opacity) + '%)'
@@ -1328,16 +1328,10 @@
         if dcmd:
             self.GetPyData(layer)[0]['cmd'] = dcmd
             mapText  = self._getLayerName(layer)
-            mapName  = utils.GetLayerNameFromCmd(dcmd)
+            mapName, found = utils.GetLayerNameFromCmd(dcmd)
             mapLayer = self.GetPyData(layer)[0]['maplayer']
             self.SetItemText(layer, mapName)
             
-            found = True
-            if mapLayer and \
-                    mapLayer.GetType() in ('raster', '3d-raster', 'vector') and \
-                    not grass.find_file(name = mapName, element = mapLayer.GetElement())['fullname']:
-                found = False
-            
             if not mapText or not found:
                 propwin.Hide()
                 GWarning(parent = self,
@@ -1445,8 +1439,8 @@
                 chk = self.IsItemChecked(item)
                 hidden = not self.IsVisible(item)
                 # determine layer name
-                layerName = utils.GetLayerNameFromCmd(cmdlist, fullyQualified=True)
-                if not layerName:
+                layerName, found = utils.GetLayerNameFromCmd(cmdlist, fullyQualified = True)
+                if not found:
                     layerName = self.GetItemText(item)
         
         maplayer = self.Map.ChangeLayer(layer=self.GetPyData(item)[0]['maplayer'], type=type,

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -1284,8 +1284,8 @@
         for layer in self.tree.GetSelections():
             type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
             dcmd = self.tree.GetPyData(layer)[0]['cmd']
-            name = utils.GetLayerNameFromCmd(dcmd)
-            if name == '':
+            name, found = utils.GetLayerNameFromCmd(dcmd)
+            if not found:
                 continue
             if type in ('raster', 'rgb', 'his'):
                 raststr += "%s," % name

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2011-01-28 13:04:24 UTC (rev 45232)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2011-01-28 13:12:49 UTC (rev 45233)
@@ -42,8 +42,7 @@
         return shlex.split(s)
 
 def GetTempfile(pref=None):
-    """
-    Creates GRASS temporary file using defined prefix.
+    """!Creates GRASS temporary file using defined prefix.
 
     @todo Fix path on MS Windows/MSYS
 
@@ -78,17 +77,16 @@
     
     @param dcmd GRASS command (given as list)
     @param fullyQualified change map name to be fully qualified
-    @param force parameter otherwise 'input'/'map'
-    @param update change map name in command
+    @param param params directory
     @param layerType check also layer type ('raster', 'vector', '3d-raster', ...)
     
-    @return map name
-    @return '' if no map name found in command
+    @return tuple (name, found)
     """
     mapname = ''
+    found   = True
     
     if len(dcmd) < 1:
-        return mapname
+        return mapname, False
     
     if 'd.grid' == dcmd[0]:
         mapname = 'grid'
@@ -120,7 +118,7 @@
             if len(dcmd) > 1 and '=' not in dcmd[1]:
                 params.append((1, None, dcmd[1]))
             else:
-                return mapname
+                return mapname, False
         
         mapname = params[0][2]
         mapset = ''
@@ -131,20 +129,22 @@
                         findType = 'cell'
                     else:
                         findType = layerType
-                    mapset = grass.find_file(mapname, element=findType)['mapset']
+                    mapset = grass.find_file(mapname, element = findType)['mapset']
                 except AttributeError, e: # not found
-                    return ''
+                    return '', False
                 if not mapset:
-                    mapset = grass.gisenv()['MAPSET']
+                    found = False
             else:
                 mapset = grass.gisenv()['MAPSET']
             
             # update dcmd
             for i, p, v in params:
                 if p:
-                    dcmd[i] = p + '=' + v + '@' + mapset
+                    dcmd[i] = p + '=' + v
                 else:
-                    dcmd[i] = v + '@' + mapset
+                    dcmd[i] = v
+                if mapset:
+                    dcmd[i] += '@' + mapset
         
         maps = list()
         for i, p, v in params:
@@ -154,7 +154,7 @@
                 maps.append(dcmd[i].split('=', 1)[1])
         mapname = '\n'.join(maps)
     
-    return mapname
+    return mapname, found
 
 def GetValidLayerName(name):
     """!Make layer name SQL compliant, based on G_str_to_sql()



More information about the grass-commit mailing list