[GRASS-SVN] r39337 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 29 14:22:37 EDT 2009


Author: martinl
Date: 2009-09-29 14:22:37 -0400 (Tue, 29 Sep 2009)
New Revision: 39337

Modified:
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: support multi-line map names (useful for rgb, his)


Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2009-09-29 18:07:39 UTC (rev 39336)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2009-09-29 18:22:37 UTC (rev 39337)
@@ -71,7 +71,7 @@
                         layerType=None):
     """!Get map name from GRASS command
 
-    @param dcmd GRASS command (given as tuple)
+    @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
@@ -82,7 +82,7 @@
     """
     mapname = ''
 
-    if not dcmd:
+    if len(dcmd) < 1:
         return mapname
     
     if 'd.grid' == dcmd[0]:
@@ -94,41 +94,54 @@
     elif 'labels=' in dcmd[0]:
         mapname = dcmd[idx].split('=')[1]+' labels'
     else:
+        params = list()
         for idx in range(len(dcmd)):
-            if param and param in dcmd[idx]:
+            try:
+                p, v = dcmd[idx].split('=')
+            except ValueError:
+                continue
+            
+            if p == param:
+                params.append((idx, p, v))
                 break
-            elif not param:
-                if 'map=' in dcmd[idx] or \
-                        'input=' in dcmd[idx] or \
-                        'red=' in dcmd[idx] or \
-                        'h_map=' in dcmd[idx] or \
-                        'reliefmap' in dcmd[idx]:
-                    break
             
-        if idx < len(dcmd):
-            try:
-                mapname = dcmd[idx].split('=')[1]
-            except IndexError:
-                return ''
+            if p in ('map', 'input',
+                     'red', 'blue', 'green',
+                     'h_map', 's_map', 'i_map',
+                     'reliefmap'):
+                params.append((idx, p, v))
             
-            if fullyQualified and '@' not in mapname:
-                if layerType in ('raster', 'vector', '3d-raster'):
-                    try:
-                        if layerType == 'raster':
-                            findType = 'cell'
-                        else:
-                            findType = layerType
-                        result = grass.find_file(mapname, element=findType)
-                    except AttributeError, e: # not found
-                        return ''
-                    if result:
-                        mapname = result['fullname']
+        if len(params) < 1:
+            return mapname
+            
+        mapname = params[0][2]
+        mapset = ''
+        if fullyQualified and '@' not in mapname:
+            if layerType in ('raster', 'vector', '3d-raster'):
+                try:
+                    if layerType == 'raster':
+                        findType = 'cell'
                     else:
-                        mapname += '@' + grass.gisenv()['MAPSET']
+                        findType = layerType
+                    result = grass.find_file(mapname, element=findType)
+                except AttributeError, e: # not found
+                    return ''
+                if result:
+                    mapset = result['mapset']
                 else:
-                    mapname += '@' + grass.gisenv()['MAPSET']
-                dcmd[idx] = dcmd[idx].split('=')[0] + '=' + mapname
-                
+                    mapset = grass.gisenv()['MAPSET']
+            else:
+                mapset = grass.gisenv()['MAPSET']
+            
+            # update dcmd
+            for i, p, v in params:
+                dcmd[i] = p + '=' + v + '@' + mapset
+    
+        maps = list()
+        for i, p, v in params:
+            maps.append(dcmd[i].split('=')[1])
+        mapname = '\n'.join(maps)
+    
     return mapname
 
 def GetValidLayerName(name):



More information about the grass-commit mailing list