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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 4 09:54:16 EDT 2008


Author: martinl
Date: 2008-09-04 09:54:16 -0400 (Thu, 04 Sep 2008)
New Revision: 33249

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
Log:
wxGUI: trac #277 - Query vector map (edit mode): does not work
	querying areas fixed


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-09-04 13:53:10 UTC (rev 33248)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-09-04 13:54:16 UTC (rev 33249)
@@ -1666,7 +1666,7 @@
                 win.SetValue("SELECT * FROM %s" % self.mapDBInfo.layers[self.layer]['table'])
                 cols = None
                 where = None
-            print cols, where
+            
             if cols or where:
                 try:
                     keyColumn = listWin.LoadData(self.layer, columns=cols,
@@ -2721,17 +2721,18 @@
                  style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
                  pos=wx.DefaultPosition,
                  action="add"):
-
         self.parent = parent # mapdisplay.BufferedWindow
         self.map    = map
         self.action = action
 
-        # id of selected line
-        self.line = None
+        # ids/cats of selected features
+        self.line = {}
+        self.line['id'] = None
+        self.line['cats'] = None
 
         # get layer/table/column information
         self.mapDBInfo = VectorDBInfo(self.map)
-
+        
         layers = self.mapDBInfo.layers.keys() # get available layers
 
         # check if db connection / layer exists
@@ -2762,7 +2763,7 @@
                                        label=_("Close dialog on submit"))
         self.closeDialog.SetValue(True)
 
-        self.UpdateDialog(query, cats, line)
+        self.UpdateDialog(query=query, cats=cats, line=line)
 
         # set title
         if self.action == "update":
@@ -2898,8 +2899,12 @@
                 for name in columns.keys():
                     type  = columns[name]['type']
                     value = columns[name]['values'][idx]
-                    id    = columns[name]['ids'][idx]
-                    if name != key:
+                    try:
+                        id = columns[name]['ids'][idx]
+                    except IndexError:
+                        id = wx.NOT_FOUND
+                    
+                    if name != key and id != wx.NOT_FOUND:
                         self.FindWindowById(id).SetValue(str(value))
 
     def OnCancel(self, event):
@@ -2928,16 +2933,29 @@
         if self.closeDialog.IsChecked():
             self.OnCancel(event)
 
-    def GetLine(self):
-        """Get id of selected vector object or 'None' if nothing selected"""
-        return self.line
+    def GetLine(self, id=True):
+        """Get id of selected vector object or 'None' if nothing selected
 
-    def UpdateDialog(self, query=None, cats=None, line=None):
+        @param id if true return ids otherwise cats
+        """
+        if id:
+            return self.line['id']
+
+        return self.line['cats']
+
+    def UpdateDialog(self, map=None, query=None, cats=None, line=None):
         """Update dialog
 
         Return True if updated otherwise False
         """
-        self.line = line
+        if map:
+            self.map = map
+            # get layer/table/column information
+            self.mapDBInfo = VectorDBInfo(self.map)
+            
+        self.line['id'] = (line, )
+        self.line['cats'] = None
+        
         if not self.mapDBInfo:
             return False
 
@@ -2947,8 +2965,27 @@
 
         # id of selected line
         if query: # select by position
-            self.line, nselected = self.mapDBInfo.SelectByPoint(query[0],
-                                                                query[1])
+            data = self.mapDBInfo.SelectByPoint(query[0],
+                                                query[1])
+            if data and data.has_key('Layer'):
+                self.line['id'] = (-1,)
+                self.line['cats'] = {}
+                idx = 0
+                for l in data['Layer']:
+                    layer = int(l)
+                    if not self.line['cats'].has_key(layer):
+                        self.line['cats'][layer] = []
+                        
+                    self.line['cats'][layer].append(int(data['Category'][idx]))
+                    idx += 1
+                
+                nselected = len(self.line['cats'].keys())
+                
+            else:
+                self.line['id'] = None
+                self.line['cats'] = None
+                nselected = 0
+        
         # reset notebook
         self.notebook.DeleteAllPages()
 
@@ -3092,33 +3129,37 @@
                                         (float(queryCoords[0]), float(queryCoords[1])),
                                     'distance=%f' % qdist], stderr=None)
 
+        data = {}
         if cmdWhat.returncode == 0:
-            read = False
+            readAttrb = False
             for item in cmdWhat.ReadStdOutput():
-                litem = item.lower()
-                if read:
+                if len(item) < 1:
+                    continue
+                
+                key, value = item.split(':')
+                
+                if key == 'Layer' and readAttrb:
+                    readAttrb = False
+                
+                if readAttrb:
                     name, value = item.split(':')
                     name = name.strip()
                     # append value to the column
-                    try:
-                        # casting ...
-                        value = self.tables[table][name]['ctype'] (value.strip())
-                        self.tables[table][name]['values'].append(value)
-                    except:
-                        read = False
-
-                if "id:" in litem: # get line id
-                    line = int(item.split(':')[1].strip())
-                elif "key column:" in litem: # start reading attributes
-                    read = True
-                    nselected = nselected + 1
-                elif "layer:" in litem: # get layer id
-                    layer = int(item.split(':')[1].strip())
-                    table = self.layers[layer]["table"] # get table desc
-                    read = False
-
-        return (line, nselected)
-
+                    value = self.tables[table][name]['ctype'] (value.strip())
+                    self.tables[table][name]['values'].append(value)
+                else:
+                    if not data.has_key(key):
+                        data[key] = []
+                    data[key].append(value.strip())
+                    
+                    if key == 'Table':
+                        table = value.strip()
+                        
+                    if key == 'Key column': # skip attributes
+                        readAttrb = True
+        
+        return data
+    
     def SelectFromTable(self, layer, cols='*', where=None):
         """Select records from the table
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-09-04 13:53:10 UTC (rev 33248)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-09-04 13:54:16 UTC (rev 33249)
@@ -193,7 +193,7 @@
         """
         if Debug.get_level() == 0:
             # don't redirect when debugging is enabled
-            sys.stdout = self.cmd_stdout
+            # sys.stdout = self.cmd_stdout
             sys.stderr = self.cmd_stderr
             
             return True

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-04 13:53:10 UTC (rev 33248)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-04 13:54:16 UTC (rev 33249)
@@ -31,6 +31,7 @@
 import glob
 import math
 import tempfile
+import copy
 
 import wx
 import wx.aui
@@ -3396,31 +3397,35 @@
         east, north = self.MapWindow.Pixel2Cell((x, y))
 
         mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
-
+        
         if self.dialogs['attributes'] is None:
             self.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self.MapWindow,
-                                                                map=mapName,
-                                                                query=((east, north), qdist),
-                                                                pos=posWindow,
-                                                                action="update")
+                                                                     map=mapName,
+                                                                     query=((east, north), qdist),
+                                                                     pos=posWindow,
+                                                                     action="update")
         else:
-            # update currently open dialog
-            self.dialogs['attributes'].UpdateDialog(query=((east, north), qdist))
+            # selection changed?
+            if not self.dialogs['attributes'].mapDBInfo or \
+                   self.dialogs['attributes'].mapDBInfo.map != mapName:
+                self.dialogs['attributes'].UpdateDialog(map=mapName, query=((east, north), qdist))
+            else:
+                self.dialogs['attributes'].UpdateDialog(query=((east, north), qdist))
 
-        line = self.dialogs['attributes'].GetLine()
+        cats = self.dialogs['attributes'].GetLine(id=False)
         try:
             qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)[0]
         except IndexError:
             qlayer = None
-            
-        if self.dialogs['attributes'].mapDBInfo and line:
+        
+        if self.dialogs['attributes'].mapDBInfo and cats:
             # highlight feature & re-draw map
             if qlayer:
-                qlayer.SetCmd(self.AddTmpVectorMapLayer(mapName, line,
-                                                        useId=True,
+                qlayer.SetCmd(self.AddTmpVectorMapLayer(mapName, cats,
+                                                        useId=False,
                                                         addLayer=False))
             else:
-                self.AddTmpVectorMapLayer(mapName, line, useId=True)
+                self.AddTmpVectorMapLayer(mapName, cats, useId=False)
 
             self.MapWindow.UpdateMap(render=False, renderVector=False)
             # digitClass.driver.SetSelected([line])
@@ -3480,26 +3485,36 @@
         str(color[1]) + ":" + \
         str(color[2])
 
-        cmd = ["d.vect",
-               "map=%s" % name,
-               "color=%s" % colorStr,
-               "fcolor=%s" % colorStr,
-               "width=%d"  % UserSettings.Get(group='atm', key='highlight', subkey='width')]
+        pattern = ["d.vect",
+                   "map=%s" % name,
+                   "color=%s" % colorStr,
+                   "fcolor=%s" % colorStr,
+                   "width=%d"  % UserSettings.Get(group='atm', key='highlight', subkey='width')]
         
         if useId:
+            cmd = pattern
             cmd.append('-i')
             cmd.append('cats=%s' % str(cats))
         else:
-            cmd.append("cats=%s" % utils.ListOfCatsToRange(cats))
-
+            cmd = []
+            for layer in cats.keys():
+                cmd.append(copy.copy(pattern))
+                lcats = cats[layer]
+                cmd[-1].append("layer=%d" % layer)
+                cmd[-1].append("cats=%s" % utils.ListOfCatsToRange(lcats))
+        
         #     if self.icon:
         #         cmd.append("icon=%s" % (self.icon))
         #     if self.pointsize:
         #         cmd.append("size=%s" % (self.pointsize))
 
         if addLayer:
-            return self.Map.AddLayer(type='vector', name=globalvar.QUERYLAYER, command=cmd,
-                                     l_active=True, l_hidden=True, l_opacity=1.0)
+            if useId:
+                return self.Map.AddLayer(type='vector', name=globalvar.QUERYLAYER, command=cmd,
+                                         l_active=True, l_hidden=True, l_opacity=1.0)
+            else:
+                return self.Map.AddLayer(type='command', name=globalvar.QUERYLAYER, command=cmd,
+                                         l_active=True, l_hidden=True, l_opacity=1.0)
         else:
             return cmd
 



More information about the grass-commit mailing list