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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 26 08:39:45 EDT 2011


Author: annakrat
Date: 2011-08-26 05:39:45 -0700 (Fri, 26 Aug 2011)
New Revision: 47891

Modified:
   grass/trunk/gui/wxpython/gui_modules/colorrules.py
   grass/trunk/gui/wxpython/gui_modules/layertree.py
Log:
wxGUI: fix apply in vector color rules dialog when attribute column is used

Modified: grass/trunk/gui/wxpython/gui_modules/colorrules.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/colorrules.py	2011-08-26 12:04:55 UTC (rev 47890)
+++ grass/trunk/gui/wxpython/gui_modules/colorrules.py	2011-08-26 12:39:45 UTC (rev 47891)
@@ -528,8 +528,10 @@
         @return True on success otherwise False
         """
         ret = self.CreateColorTable()
-        if not self.colorTable:
-            self.UseAttrColumn()
+        if self.colorTable:
+            self.UseAttrColumn(False)
+        else:
+            self.UseAttrColumn(True)            
         if ret:
             display = self.parent.GetLayerTree().GetMapDisplay()
             if display and display.IsAutoRendered():
@@ -1529,27 +1531,29 @@
         cmd = 'v.colors'
         ColorTable.RunHelp(self, cmd = cmd)
         
-    def UseAttrColumn(self, useAttrColumn = True):
-        """!Use attribute column to render map"""
-        # TODO switch back to table, not only selected map
-        layer = self.parent.curr_page.maptree.layer_selected
-        if layer and self.parent.curr_page.maptree.GetPyData(layer)[0]['maplayer'].GetName() == self.inmap:
-##            cmd = self.parent.curr_page.maptree.GetPyData(layer)[0]['maplayer'].GetCmd()
-##            if useAttrColumn:
-##                cmd[1].update({'flags': 'a', })
-            cmdlist = ['d.vect',
-                        '-a',
-                       'map=%s' % self.inmap,
-                       'type=point,line,boundary,area']
-                
+    def UseAttrColumn(self, useAttrColumn):
+        """!Find layers and apply the changes in d.vect command"""
+        layers = self.parent.curr_page.maptree.FindItemByData(key = 'name', value = self.inmap)
+        if not layers:
+            return
+        for layer in layers:
+            if self.parent.curr_page.maptree.GetPyData(layer)[0]['type'] != 'vector':
+                continue
+            cmdlist = self.parent.curr_page.maptree.GetPyData(layer)[0]['maplayer'].GetCmd()
+            
             if self.attributeType == 'color':
-                cmdlist.append('rgb_column=%s' % self.properties['storeColumn'])
+                if useAttrColumn:
+                    cmdlist[1].update({'flags': 'a'})
+                    cmdlist[1].update({'rgb_column': self.properties['storeColumn']})
+                else:
+                    if 'flags' in cmdlist[1]:
+                        cmdlist[1]['flags'] = cmdlist[1]['flags'].replace('a', '')
+                    cmdlist[1].pop('rgb_column', None)
             elif self.attributeType == 'size':
-                cmdlist.append('size_column=%s' % self.properties['storeColumn'])
+                cmdlist[1].update({'size_column': self.properties['storeColumn']})
             elif self.attributeType == 'width':
-                cmdlist.append('width_column=%s' % self.properties['storeColumn'])
-            
-            self.parent.curr_page.maptree.GetPyData(layer)[0]['maplayer'].SetCmd(cmdlist)
+                cmdlist[1].update({'width_column' :self.properties['storeColumn']})
+            self.parent.curr_page.maptree.GetPyData(layer)[0]['cmd'] = cmdlist
         
     def CreateColorTable(self, tmp = False):
         """!Create color rules (color table or color column)"""

Modified: grass/trunk/gui/wxpython/gui_modules/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/layertree.py	2011-08-26 12:04:55 UTC (rev 47890)
+++ grass/trunk/gui/wxpython/gui_modules/layertree.py	2011-08-26 12:39:45 UTC (rev 47891)
@@ -1561,13 +1561,18 @@
         # self.Map.Clean()
 
     def FindItemByData(self, key, value):
-        """!Find item based on key and value (see PyData[0])
+        """!Find item based on key and value (see PyData[0]).
         
+        If key is 'name', finds item(s) of given maplayer name.
+        
         @return item instance
         @return None not found
         """
         item = self.GetFirstChild(self.root)[0]
-        return self.__FindSubItemByData(item, key, value)
+        if key == 'name':
+            return self.__FindSubItemByName(item, value)
+        else:
+            return self.__FindSubItemByData(item, key, value)
 
     def FindItemByIndex(self, index):
         """!Find item by index (starting at 0)
@@ -1597,7 +1602,7 @@
             item = self.GetNextSibling(item)
         
     def __FindSubItemByData(self, item, key, value):
-        """!Support method for FindItemByValue"""
+        """!Support method for FindItemByData"""
         while item and item.IsOk():
             try:
                 itemValue = self.GetPyData(item)[0][key]
@@ -1615,3 +1620,24 @@
 
         return None
 
+    def __FindSubItemByName(self, item, value):
+        """!Support method for FindItemByData for searching by name"""
+        items = []
+        while item and item.IsOk():
+            try:
+                itemLayer = self.GetPyData(item)[0]['maplayer']
+            except KeyError:
+                return None
+            
+            if value == itemLayer.GetName():
+                items.append(item)
+            if self.GetPyData(item)[0]['type'] == 'group':
+                subItem = self.GetFirstChild(item)[0]
+                found = self.__FindSubItemByName(subItem, name)
+                if found:
+                    items.extend(found)
+            item = self.GetNextSibling(item)
+        
+        if items:
+            return items
+        return None



More information about the grass-commit mailing list