Browse Source

wxGUI: fix and simplify raster/vector querying in 2D

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47169 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 years ago
parent
commit
bfc859408e

+ 140 - 136
gui/wxpython/gui_modules/dbm_dialogs.py

@@ -29,10 +29,10 @@ from dbm_base    import VectorDBInfo
 
 
 class DisplayAttributesDialog(wx.Dialog):
 class DisplayAttributesDialog(wx.Dialog):
     def __init__(self, parent, map,
     def __init__(self, parent, map,
-                 query=None, cats=None, line=None,
-                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
-                 pos=wx.DefaultPosition,
-                 action="add"):
+                 query = None, cats = None, line = None,
+                 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
+                 pos = wx.DefaultPosition,
+                 action = "add"):
         """!Standard dialog used to add/update/display attributes linked
         """!Standard dialog used to add/update/display attributes linked
         to the vector map.
         to the vector map.
         
         
@@ -67,39 +67,41 @@ class DisplayAttributesDialog(wx.Dialog):
             label = _("Database connection "
             label = _("Database connection "
                       "is not defined in DB file.")
                       "is not defined in DB file.")
 
 
-            wx.MessageBox(parent=self.parent,
-                          message=_("No attribute table linked to "
+            wx.MessageBox(parent = self.parent,
+                          message = _("No attribute table linked to "
                                     "vector map <%(vector)s> found. %(msg)s"
                                     "vector map <%(vector)s> found. %(msg)s"
                                     "\nYou can disable this message from digitization settings. Or "
                                     "\nYou can disable this message from digitization settings. Or "
                                     "you can create and link attribute table to the vector map "
                                     "you can create and link attribute table to the vector map "
                                     "using Attribute Table Manager.") % 
                                     "using Attribute Table Manager.") % 
                           {'vector' : self.map, 'msg' : label},
                           {'vector' : self.map, 'msg' : label},
-                          caption=_("Message"), style=wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE)
+                          caption = _("Message"), style = wx.OK | wx.ICON_EXCLAMATION | wx.CENTRE)
             self.mapDBInfo = None
             self.mapDBInfo = None
 
 
-        wx.Dialog.__init__(self, parent=self.parent, id=wx.ID_ANY,
-                           title="", style=style, pos=pos)
+        wx.Dialog.__init__(self, parent = self.parent, id = wx.ID_ANY,
+                           title = "", style = style, pos = pos)
 
 
         # dialog body
         # dialog body
         mainSizer = wx.BoxSizer(wx.VERTICAL)
         mainSizer = wx.BoxSizer(wx.VERTICAL)
 
 
         # notebook
         # notebook
-        self.notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
+        self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
 
 
-        self.closeDialog = wx.CheckBox(parent=self, id=wx.ID_ANY,
-                                       label=_("Close dialog on submit"))
+        self.closeDialog = wx.CheckBox(parent = self, id = wx.ID_ANY,
+                                       label = _("Close dialog on submit"))
         self.closeDialog.SetValue(True)
         self.closeDialog.SetValue(True)
-
+        if self.action == 'display':
+            self.closeDialog.Enable(False)
+        
         # feature id (text/choice for duplicates)
         # feature id (text/choice for duplicates)
-        self.fidMulti = wx.Choice(parent=self, id=wx.ID_ANY,
-                                  size=(150, -1))
+        self.fidMulti = wx.Choice(parent = self, id = wx.ID_ANY,
+                                  size = (150, -1))
         self.fidMulti.Bind(wx.EVT_CHOICE, self.OnFeature)
         self.fidMulti.Bind(wx.EVT_CHOICE, self.OnFeature)
-        self.fidText = wx.StaticText(parent=self, id=wx.ID_ANY)
+        self.fidText = wx.StaticText(parent = self, id = wx.ID_ANY)
 
 
-        self.noFoundMsg = wx.StaticText(parent=self, id=wx.ID_ANY,
-                                        label=_("No attributes found"))
+        self.noFoundMsg = wx.StaticText(parent = self, id = wx.ID_ANY,
+                                        label = _("No attributes found"))
         
         
-        self.UpdateDialog(query=query, cats=cats)
+        self.UpdateDialog(query = query, cats = cats)
 
 
         # set title
         # set title
         if self.action == "update":
         if self.action == "update":
@@ -113,7 +115,9 @@ class DisplayAttributesDialog(wx.Dialog):
         btnCancel = wx.Button(self, wx.ID_CANCEL)
         btnCancel = wx.Button(self, wx.ID_CANCEL)
         btnReset  = wx.Button(self, wx.ID_UNDO, _("&Reload"))
         btnReset  = wx.Button(self, wx.ID_UNDO, _("&Reload"))
         btnSubmit = wx.Button(self, wx.ID_OK, _("&Submit"))
         btnSubmit = wx.Button(self, wx.ID_OK, _("&Submit"))
-
+        if self.action == 'display':
+            btnSubmit.Enable(False)
+        
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer.AddButton(btnCancel)
         btnSizer.AddButton(btnCancel)
         btnSizer.AddButton(btnReset)
         btnSizer.AddButton(btnReset)
@@ -122,25 +126,25 @@ class DisplayAttributesDialog(wx.Dialog):
         btnSizer.AddButton(btnSubmit)
         btnSizer.AddButton(btnSubmit)
         btnSizer.Realize()
         btnSizer.Realize()
 
 
-        mainSizer.Add(item=self.noFoundMsg, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=5)
-        mainSizer.Add(item=self.notebook, proportion=1,
-                      flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item = self.noFoundMsg, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL, border = 5)
+        mainSizer.Add(item = self.notebook, proportion = 1,
+                      flag = wx.EXPAND | wx.ALL, border = 5)
         fidSizer = wx.BoxSizer(wx.HORIZONTAL)
         fidSizer = wx.BoxSizer(wx.HORIZONTAL)
-        fidSizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY,
-                                        label=_("Feature id:")),
-                     proportion=0, border=5,
-                     flag=wx.ALIGN_CENTER_VERTICAL)
-        fidSizer.Add(item=self.fidMulti, proportion=0,
-                     flag=wx.EXPAND | wx.ALL,  border=5)
-        fidSizer.Add(item=self.fidText, proportion=0,
-                     flag=wx.EXPAND | wx.ALL,  border=5)
-        mainSizer.Add(item=fidSizer, proportion=0,
-                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
-        mainSizer.Add(item=self.closeDialog, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
-                      border=5)
-        mainSizer.Add(item=btnSizer, proportion=0,
-                      flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
+        fidSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
+                                        label = _("Feature id:")),
+                     proportion = 0, border = 5,
+                     flag = wx.ALIGN_CENTER_VERTICAL)
+        fidSizer.Add(item = self.fidMulti, proportion = 0,
+                     flag = wx.EXPAND | wx.ALL,  border = 5)
+        fidSizer.Add(item = self.fidText, proportion = 0,
+                     flag = wx.EXPAND | wx.ALL,  border = 5)
+        mainSizer.Add(item = fidSizer, proportion = 0,
+                      flag = wx.EXPAND | wx.LEFT | wx.RIGHT, border = 5)
+        mainSizer.Add(item = self.closeDialog, proportion = 0, flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
+                      border = 5)
+        mainSizer.Add(item = btnSizer, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
 
 
         # bindigs
         # bindigs
         btnReset.Bind(wx.EVT_BUTTON, self.OnReset)
         btnReset.Bind(wx.EVT_BUTTON, self.OnReset)
@@ -160,7 +164,7 @@ class DisplayAttributesDialog(wx.Dialog):
         if self.notebook.GetPageCount() == 0:
         if self.notebook.GetPageCount() == 0:
             Debug.msg(2, "DisplayAttributesDialog(): Nothing found!")
             Debug.msg(2, "DisplayAttributesDialog(): Nothing found!")
             ### self.mapDBInfo = None
             ### self.mapDBInfo = None
-
+        
     def __SelectAttributes(self, layer):
     def __SelectAttributes(self, layer):
         """!Select attributes"""
         """!Select attributes"""
         pass
         pass
@@ -169,7 +173,15 @@ class DisplayAttributesDialog(wx.Dialog):
         """!Update SQL statement"""
         """!Update SQL statement"""
         pass
         pass
 
 
-    def GetSQLString(self, updateValues=False):
+    def IsFound(self):
+        """!Check for status
+
+        @return True on attributes found
+        @return False attributes not found
+        """
+        return bool(self.notebook.GetPageCount())
+    
+    def GetSQLString(self, updateValues = False):
         """!Create SQL statement string based on self.sqlStatement
         """!Create SQL statement string based on self.sqlStatement
 
 
         If updateValues is True, update dataFrame according to values
         If updateValues is True, update dataFrame according to values
@@ -267,7 +279,8 @@ class DisplayAttributesDialog(wx.Dialog):
         """!Cancel button pressed
         """!Cancel button pressed
         """
         """
         self.parent.parent.dialogs['attributes'] = None
         self.parent.parent.dialogs['attributes'] = None
-        if self.parent.digit:
+        
+        if hasattr(self, "digit"):
             self.parent.digit.GetDisplay().SetSelected([])
             self.parent.digit.GetDisplay().SetSelected([])
             self.parent.UpdateMap(render = False)
             self.parent.UpdateMap(render = False)
         else:
         else:
@@ -277,8 +290,8 @@ class DisplayAttributesDialog(wx.Dialog):
 
 
     def OnSubmit(self, event):
     def OnSubmit(self, event):
         """!Submit records"""
         """!Submit records"""
-        for sql in self.GetSQLString(updateValues=True):
-            enc = UserSettings.Get(group='atm', key='encoding', subkey='value')
+        for sql in self.GetSQLString(updateValues = True):
+            enc = UserSettings.Get(group = 'atm', key = 'encoding', subkey = 'value')
             if not enc and 'GRASS_DB_ENCODING' in os.environ:
             if not enc and 'GRASS_DB_ENCODING' in os.environ:
                 enc = os.environ['GRASS_DB_ENCODING']
                 enc = os.environ['GRASS_DB_ENCODING']
             if enc:
             if enc:
@@ -294,7 +307,7 @@ class DisplayAttributesDialog(wx.Dialog):
 
 
     def OnFeature(self, event):
     def OnFeature(self, event):
         self.fid = int(event.GetString())
         self.fid = int(event.GetString())
-        self.UpdateDialog(cats=self.cats, fid=self.fid)
+        self.UpdateDialog(cats = self.cats, fid = self.fid)
         
         
     def GetCats(self):
     def GetCats(self):
         """!Get id of selected vector object or 'None' if nothing selected
         """!Get id of selected vector object or 'None' if nothing selected
@@ -310,11 +323,28 @@ class DisplayAttributesDialog(wx.Dialog):
         """!Get selected feature id"""
         """!Get selected feature id"""
         return self.fid
         return self.fid
     
     
-    def UpdateDialog(self, map=None, query=None, cats=None, fid=-1):
+    def UpdateDialog(self, map = None, query = None, cats = None, fid = -1,
+                     action = None):
         """!Update dialog
         """!Update dialog
-
-        Return True if updated otherwise False
+        
+        @param map name of vector map
+        @param query
+        @param cats
+        @param fid feature id
+        @param action add, update, display or None
+        
+        @return True if updated
+        @return False
         """
         """
+        if action:
+            self.action = action
+            if action == 'display':
+                enabled = False
+            else:
+                enabled = True
+            self.closeDialog.Enable(enabled)
+            self.FindWindowById(wx.ID_OK).Enable(enabled)
+        
         if map:
         if map:
             self.map = map
             self.map = map
             # get layer/table/column information
             # get layer/table/column information
@@ -322,11 +352,11 @@ class DisplayAttributesDialog(wx.Dialog):
         
         
         if not self.mapDBInfo:
         if not self.mapDBInfo:
             return False
             return False
-
+        
         self.mapDBInfo.Reset()
         self.mapDBInfo.Reset()
-
+        
         layers = self.mapDBInfo.layers.keys() # get available layers
         layers = self.mapDBInfo.layers.keys() # get available layers
-
+        
         # id of selected line
         # id of selected line
         if query: # select by position
         if query: # select by position
             data = self.mapDBInfo.SelectByPoint(query[0],
             data = self.mapDBInfo.SelectByPoint(query[0],
@@ -349,7 +379,7 @@ class DisplayAttributesDialog(wx.Dialog):
                     idx += 1
                     idx += 1
         else:
         else:
             self.cats = cats
             self.cats = cats
-
+        
         if fid > 0:
         if fid > 0:
             self.fid = fid
             self.fid = fid
         elif len(self.cats.keys()) > 0:
         elif len(self.cats.keys()) > 0:
@@ -375,21 +405,21 @@ class DisplayAttributesDialog(wx.Dialog):
         
         
         # reset notebook
         # reset notebook
         self.notebook.DeleteAllPages()
         self.notebook.DeleteAllPages()
-
+        
         for layer in layers: # for each layer
         for layer in layers: # for each layer
             if not query: # select by layer/cat
             if not query: # select by layer/cat
                 if self.fid > 0 and layer in self.cats[self.fid]:
                 if self.fid > 0 and layer in self.cats[self.fid]:
                     for cat in self.cats[self.fid][layer]:
                     for cat in self.cats[self.fid][layer]:
                         nselected = self.mapDBInfo.SelectFromTable(layer,
                         nselected = self.mapDBInfo.SelectFromTable(layer,
-                                                                   where="%s=%d" % \
+                                                                   where = "%s=%d" % \
                                                                    (self.mapDBInfo.layers[layer]['key'],
                                                                    (self.mapDBInfo.layers[layer]['key'],
                                                                     cat))
                                                                     cat))
                 else:
                 else:
                     nselected = 0
                     nselected = 0
-
+            
             # if nselected <= 0 and self.action != "add":
             # if nselected <= 0 and self.action != "add":
             #    continue # nothing selected ...
             #    continue # nothing selected ...
-
+            
             if self.action == "add":
             if self.action == "add":
                 if nselected <= 0:
                 if nselected <= 0:
                     if layer in self.cats[self.fid]:
                     if layer in self.cats[self.fid]:
@@ -416,17 +446,17 @@ class DisplayAttributesDialog(wx.Dialog):
                         break
                         break
 
 
                 # use scrolled panel instead (and fix initial max height of the window to 480px)
                 # use scrolled panel instead (and fix initial max height of the window to 480px)
-                panel = scrolled.ScrolledPanel(parent=self.notebook, id=wx.ID_ANY,
-                                               size=(-1, 150))
-                panel.SetupScrolling(scroll_x=False)
+                panel = scrolled.ScrolledPanel(parent = self.notebook, id = wx.ID_ANY,
+                                               size = (-1, 150))
+                panel.SetupScrolling(scroll_x = False)
                 
                 
-                self.notebook.AddPage(page=panel, text=" %s %d / %s %d" % (_("Layer"), layer,
+                self.notebook.AddPage(page = panel, text = " %s %d / %s %d" % (_("Layer"), layer,
                                                                            _("Category"), cat))
                                                                            _("Category"), cat))
-           
+                
                 # notebook body
                 # notebook body
                 border = wx.BoxSizer(wx.VERTICAL)
                 border = wx.BoxSizer(wx.VERTICAL)
-
-                flexSizer = wx.FlexGridSizer (cols=4, hgap=3, vgap=3)
+                
+                flexSizer = wx.FlexGridSizer (cols = 4, hgap = 3, vgap = 3)
                 flexSizer.AddGrowableCol(3)
                 flexSizer.AddGrowableCol(3)
                 # columns (sorted by index)
                 # columns (sorted by index)
                 names = [''] * len(columns.keys())
                 names = [''] * len(columns.keys())
@@ -446,34 +476,35 @@ class DisplayAttributesDialog(wx.Dialog):
                             value = columns[name]['values'][idx]
                             value = columns[name]['values'][idx]
                     else:
                     else:
                         value = ''
                         value = ''
-                        
-                    colName = wx.StaticText(parent=panel, id=wx.ID_ANY,
-                                            label=name)
-                    colType = wx.StaticText(parent=panel, id=wx.ID_ANY,
-                                            label="[" + vtype.lower() + "]")
-                    delimiter = wx.StaticText(parent=panel, id=wx.ID_ANY, label=":")
                     
                     
-                    colValue = wx.TextCtrl(parent=panel, id=wx.ID_ANY, value=value)
+                    colName = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                            label = name)
+                    colType = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                            label = "[" + vtype.lower() + "]")
+                    delimiter = wx.StaticText(parent = panel, id = wx.ID_ANY, label = ":")
                     
                     
+                    colValue = wx.TextCtrl(parent = panel, id = wx.ID_ANY, value = value)
                     colValue.SetName(name)
                     colValue.SetName(name)
                     self.Bind(wx.EVT_TEXT, self.OnSQLStatement, colValue)
                     self.Bind(wx.EVT_TEXT, self.OnSQLStatement, colValue)
+                    if self.action == 'display':
+                        colValue.SetWindowStyle(wx.TE_READONLY)
                     
                     
-                    flexSizer.Add(colName, proportion=0,
-                                  flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
-                    flexSizer.Add(colType, proportion=0,
-                                  flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
-                    flexSizer.Add(delimiter, proportion=0,
-                                  flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
-                    flexSizer.Add(colValue, proportion=1,
-                                  flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
+                    flexSizer.Add(colName, proportion = 0,
+                                  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
+                    flexSizer.Add(colType, proportion = 0,
+                                  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
+                    flexSizer.Add(delimiter, proportion = 0,
+                                  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
+                    flexSizer.Add(colValue, proportion = 1,
+                                  flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
                     # add widget reference to self.columns
                     # add widget reference to self.columns
                     columns[name]['ids'].append(colValue.GetId()) # name, type, values, id
                     columns[name]['ids'].append(colValue.GetId()) # name, type, values, id
                 # for each attribute (including category) END
                 # for each attribute (including category) END
-                border.Add(item=flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
+                border.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
                 panel.SetSizer(border)
                 panel.SetSizer(border)
             # for each category END
             # for each category END
         # for each layer END
         # for each layer END
-
+        
         if self.notebook.GetPageCount() == 0:
         if self.notebook.GetPageCount() == 0:
             self.noFoundMsg.Show(True)
             self.noFoundMsg.Show(True)
         else:
         else:
@@ -498,8 +529,8 @@ class DisplayAttributesDialog(wx.Dialog):
                 break
                 break
         
         
 class ModifyTableRecord(wx.Dialog):
 class ModifyTableRecord(wx.Dialog):
-    def __init__(self, parent, id, title, data, keyEditable=(-1, True),
-                style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
+    def __init__(self, parent, id, title, data, keyEditable = (-1, True),
+                style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
         """!Dialog for inserting/updating table record
         """!Dialog for inserting/updating table record
 
 
         Notes:
         Notes:
@@ -508,25 +539,25 @@ class ModifyTableRecord(wx.Dialog):
         is editable(True) or not.
         is editable(True) or not.
         """
         """
         # parent -> VDigitWindow
         # parent -> VDigitWindow
-        wx.Dialog.__init__(self, parent, id, title, style=style)
+        wx.Dialog.__init__(self, parent, id, title, style = style)
         
         
         self.CenterOnParent()
         self.CenterOnParent()
         
         
         self.keyId = keyEditable[0]
         self.keyId = keyEditable[0]
         
         
-        self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
+        self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
 
 
-        box = wx.StaticBox(parent=self.panel, id=wx.ID_ANY, label='')
+        box = wx.StaticBox(parent = self.panel, id = wx.ID_ANY, label = '')
 
 
-        self.dataPanel = scrolled.ScrolledPanel(parent=self.panel, id=wx.ID_ANY,
-                                            style=wx.TAB_TRAVERSAL)
-        self.dataPanel.SetupScrolling(scroll_x=False)
+        self.dataPanel = scrolled.ScrolledPanel(parent = self.panel, id = wx.ID_ANY,
+                                            style = wx.TAB_TRAVERSAL)
+        self.dataPanel.SetupScrolling(scroll_x = False)
         
         
         #
         #
         # buttons
         # buttons
         #
         #
         self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
         self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
-        self.btnSubmit = wx.Button(self.panel, wx.ID_OK, _("Submit"))
+        self.btnSubmit = wx.Button(self.panel, wx.ID_OK, _("&Submit"))
         self.btnSubmit.SetDefault()
         self.btnSubmit.SetDefault()
 
 
         #
         #
@@ -546,14 +577,14 @@ class ModifyTableRecord(wx.Dialog):
                     id += 1
                     id += 1
                     continue
                     continue
                 else:
                 else:
-                    valueWin = wx.SpinCtrl(parent=self.dataPanel, id=wx.ID_ANY,
-                                           value=value, min=-1e9, max=1e9, size=(250, -1))
+                    valueWin = wx.SpinCtrl(parent = self.dataPanel, id = wx.ID_ANY,
+                                           value = value, min = -1e9, max = 1e9, size = (250, -1))
             else:
             else:
-                valueWin = wx.TextCtrl(parent=self.dataPanel, id=wx.ID_ANY,
-                                       value=value, size=(250, -1))
+                valueWin = wx.TextCtrl(parent = self.dataPanel, id = wx.ID_ANY,
+                                       value = value, size = (250, -1))
                                 
                                 
-            label = wx.StaticText(parent=self.dataPanel, id=wx.ID_ANY,
-                                  label=column + ":")
+            label = wx.StaticText(parent = self.dataPanel, id = wx.ID_ANY,
+                                  label = column + ":")
 
 
             self.widgets.append((label.GetId(),
             self.widgets.append((label.GetId(),
                                  valueWin.GetId()))
                                  valueWin.GetId()))
@@ -561,38 +592,31 @@ class ModifyTableRecord(wx.Dialog):
             id += 1
             id += 1
             
             
         self.__Layout()
         self.__Layout()
-
-        # winSize = self.GetSize()
-        # fix height of window frame if needed
-        # if winSize[1] > 480:
-        #    winSize[1] = 480
-        #    self.SetSize(winSize)
-        # self.SetMinSize(winSize)
-
+        
     def __Layout(self):
     def __Layout(self):
         """!Do layout"""
         """!Do layout"""
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer = wx.BoxSizer(wx.VERTICAL)
 
 
         # data area
         # data area
-        dataSizer = wx.FlexGridSizer (cols=2, hgap=3, vgap=3)
+        dataSizer = wx.FlexGridSizer (cols = 2, hgap = 3, vgap = 3)
         dataSizer.AddGrowableCol(1)
         dataSizer.AddGrowableCol(1)
 
 
         for labelId, valueId in self.widgets:
         for labelId, valueId in self.widgets:
             label = self.FindWindowById(labelId)
             label = self.FindWindowById(labelId)
             value = self.FindWindowById(valueId)
             value = self.FindWindowById(valueId)
 
 
-            dataSizer.Add(label, proportion=0,
-                          flag=wx.ALIGN_CENTER_VERTICAL)
-            dataSizer.Add(value, proportion=0,
-                          flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
+            dataSizer.Add(label, proportion = 0,
+                          flag = wx.ALIGN_CENTER_VERTICAL)
+            dataSizer.Add(value, proportion = 0,
+                          flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
 
 
         self.dataPanel.SetAutoLayout(True)
         self.dataPanel.SetAutoLayout(True)
         self.dataPanel.SetSizer(dataSizer)
         self.dataPanel.SetSizer(dataSizer)
         dataSizer.Fit(self.dataPanel)
         dataSizer.Fit(self.dataPanel)
 
 
         if self.usebox:
         if self.usebox:
-            self.boxSizer.Add(item=self.dataPanel, proportion=1,
-                         flag=wx.EXPAND | wx.ALL, border=5)
+            self.boxSizer.Add(item = self.dataPanel, proportion = 1,
+                              flag = wx.EXPAND | wx.ALL, border = 5)
             
             
         # buttons
         # buttons
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer = wx.StdDialogButtonSizer()
@@ -601,15 +625,15 @@ class ModifyTableRecord(wx.Dialog):
         btnSizer.Realize()
         btnSizer.Realize()
 
 
         if not self.usebox:
         if not self.usebox:
-            sizer.Add(item=self.dataPanel, proportion=1,
-                      flag=wx.EXPAND | wx.ALL, border=5)
+            sizer.Add(item = self.dataPanel, proportion = 1,
+                      flag = wx.EXPAND | wx.ALL, border = 5)
         else:
         else:
-            sizer.Add(item=self.boxSizer, proportion=1,
-                      flag=wx.EXPAND | wx.ALL, border=5)
+            sizer.Add(item = self.boxSizer, proportion = 1,
+                      flag = wx.EXPAND | wx.ALL, border = 5)
             
             
 
 
-        sizer.Add(item=btnSizer, proportion=0,
-                 flag=wx.EXPAND | wx.ALL, border=5)
+        sizer.Add(item = btnSizer, proportion = 0,
+                 flag = wx.EXPAND | wx.ALL, border = 5)
 
 
         framewidth = self.GetSize()[0]
         framewidth = self.GetSize()[0]
         self.SetMinSize((framewidth,150))
         self.SetMinSize((framewidth,150))
@@ -622,27 +646,7 @@ class ModifyTableRecord(wx.Dialog):
 
 
         self.Layout()
         self.Layout()
         
         
-#        # set window frame size (min & max)
-#        minFrameHeight = 150
-#        maxFrameHeight = 2 * minFrameHeight
-#        if self.GetSize()[1] > minFrameHeight:
-#            print 'size ='+str(self.GetSize()[1])
-#            print 'if 1'
-#            self.SetMinSize((self.GetSize()[0], minFrameHeight))
-#        else:
-#            print 'else 1'
-#            self.SetMinSize(self.GetSize())
-
-#        if self.GetSize()[1] > maxFrameHeight:
-#            print 'if 2'
-#            self.SetSize((self.GetSize()[0], maxFrameHeight))
-#        else:
-#            print 'else 2'
-#            self.SetSize(self.panel.GetSize())
-            
-
-                
-    def GetValues(self, columns=None):
+    def GetValues(self, columns = None):
         """!Return list of values (casted to string).
         """!Return list of values (casted to string).
 
 
         If columns is given (list), return only values of given columns.
         If columns is given (list), return only values of given columns.

+ 46 - 112
gui/wxpython/gui_modules/mapdisp.py

@@ -354,12 +354,10 @@ class MapFrame(wx.Frame):
         # check for GLCanvas and OpenGL
         # check for GLCanvas and OpenGL
         if not nviz.haveNviz:
         if not nviz.haveNviz:
             self.toolbars['map'].combo.SetValue(_("2D view"))
             self.toolbars['map'].combo.SetValue(_("2D view"))
-            wx.MessageBox(parent = self,
-                          message = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
-                                      "was not found or loaded properly.\n"
-                                      "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg),
-                          caption = _("Error"),
-                          style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            gcmd.GError(parent = self,
+                        message = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
+                                    "was not found or loaded properly.\n"
+                                    "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg))
             return
             return
         
         
         # add Nviz toolbar and disable 2D display mode tools
         # add Nviz toolbar and disable 2D display mode tools
@@ -608,7 +606,7 @@ class MapFrame(wx.Frame):
                 else: # line, boundary
                 else: # line, boundary
                     self.MapWindow.mouse['box'] = 'line'
                     self.MapWindow.mouse['box'] = 'line'
             elif self.toolbars['vdigit'].GetAction() in ['addVertex', 'removeVertex', 'splitLine',
             elif self.toolbars['vdigit'].GetAction() in ['addVertex', 'removeVertex', 'splitLine',
-                                                         'editLine', 'displayCats', 'displayAttrs',
+                                                         'editLine', 'displayCats', 'queryMap',
                                                          'copyCats']:
                                                          'copyCats']:
                 self.MapWindow.mouse['box'] = 'point'
                 self.MapWindow.mouse['box'] = 'point'
             else: # moveLine, deleteLine
             else: # moveLine, deleteLine
@@ -1215,46 +1213,7 @@ class MapFrame(wx.Frame):
     def GetWindow(self):
     def GetWindow(self):
         """!Get map window"""
         """!Get map window"""
         return self.MapWindow
         return self.MapWindow
-
-    def _OnQuery(self):
-        """!Internal method used by OnQuery*() methods"""
-        if not self.IsStandalone() and  \
-                self.toolbars['map'].GetAction() == 'displayAttrb':
-            # switch to output console to show query results
-            self._layerManager.notebook.SetSelectionByName('output')
-        
-        self.MapWindow.mouse['box'] = "point"
-        self.MapWindow.zoomtype = 0
-        
-        # change the cursor
-        self.MapWindow.SetCursor(self.cursors["cross"])
-        
-    def OnQueryDisplay(self, event):
-        """!Query currrent raster/vector map layers (display mode) -
-        2D view mode
-        """
-        if self.toolbars['map'].GetAction() == 'displayAttrb': # select previous action
-            self.toolbars['map'].SelectDefault(event)
-            return
-        
-        self.toolbars['map'].action['desc'] = 'displayAttrb'
-        
-        self.MapWindow.mouse['use'] = "query"
-        self._OnQuery()
-        
-    def OnQueryModify(self, event):
-        """!Query vector map layer (edit mode) - 2D view mode
-        """
-        if self.toolbars['map'].GetAction() == 'modifyAttrb': # select previous action
-            self.toolbars['map'].SelectDefault(event)
-            return
-        
-        self.toolbars['map'].action['desc'] = 'modifyAttrb'
-        
-        self.MapWindow.mouse['use'] = "queryVector"
-        self.MapWindow.pen = wx.Pen(colour = 'Red', width = 2, style = wx.SHORT_DASH)
-        self._OnQuery()
-        
+    
     def OnNvizQuerySurface(self, event):
     def OnNvizQuerySurface(self, event):
         """!Query current surface in 3D view mode"""
         """!Query current surface in 3D view mode"""
         if self.toolbars['map'].GetAction() == 'nvizQuerySurface':
         if self.toolbars['map'].GetAction() == 'nvizQuerySurface':
@@ -1311,9 +1270,10 @@ class MapFrame(wx.Frame):
                 ltype = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
                 ltype = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
                 dcmd = self.tree.GetPyData(layer)[0]['cmd']
                 dcmd = self.tree.GetPyData(layer)[0]['cmd']
                 name, found = utils.GetLayerNameFromCmd(dcmd)
                 name, found = utils.GetLayerNameFromCmd(dcmd)
+                
                 if not found:
                 if not found:
                     continue
                     continue
-                if ltype is 'raster':
+                if ltype == 'raster':
                     rast.append(name)
                     rast.append(name)
                 elif ltype in ('rgb', 'his'):
                 elif ltype in ('rgb', 'his'):
                     for iname in name.split('\n'):
                     for iname in name.split('\n'):
@@ -1349,6 +1309,7 @@ class MapFrame(wx.Frame):
             
             
             vcmd.append('-a')
             vcmd.append('-a')
             vcmd.append('map=%s' % ','.join(vect))
             vcmd.append('map=%s' % ','.join(vect))
+            vcmd.append('layer=%s' % ','.join(['-1'] * len(vect)))
             vcmd.append('east_north=%f,%f' % (float(east), float(north)))
             vcmd.append('east_north=%f,%f' % (float(east), float(north)))
             vcmd.append('distance=%f' % float(qdist))
             vcmd.append('distance=%f' % float(qdist))
         
         
@@ -1393,23 +1354,13 @@ class MapFrame(wx.Frame):
         """
         """
         if not self.tree.layer_selected or \
         if not self.tree.layer_selected or \
                 self.tree.GetPyData(self.tree.layer_selected)[0]['type'] != 'vector':
                 self.tree.GetPyData(self.tree.layer_selected)[0]['type'] != 'vector':
-            wx.MessageBox(parent = self,
-                          message = _("No vector map selected for querying."),
-                          caption = _("Vector querying"),
-                          style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
-            return
-        
-        if self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetMapset() != \
-                grass.gisenv()['MAPSET']:
-            wx.MessageBox(parent = self,
-                          message = _("Only vector map from the current mapset can be modified."),
-                          caption = _("Vector querying"),
-                          style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+            gcmd.GMessage(parent = self,
+                          message = _("No vector map selected for querying."))
             return
             return
         
         
         posWindow = self.ClientToScreen((x + self.MapWindow.dialogOffset,
         posWindow = self.ClientToScreen((x + self.MapWindow.dialogOffset,
                                          y + self.MapWindow.dialogOffset))
                                          y + self.MapWindow.dialogOffset))
-
+        
         qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) /
         qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) /
                         self.Map.width)
                         self.Map.width)
         
         
@@ -1417,21 +1368,32 @@ class MapFrame(wx.Frame):
         
         
         mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
         mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
         
         
+        if self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetMapset() != \
+                grass.gisenv()['MAPSET']:
+            mode = 'display'
+        else:
+            mode = 'update'
+        
         if self.dialogs['attributes'] is None:
         if self.dialogs['attributes'] is None:
-            self.dialogs['attributes'] = \
-                dbm_dialogs.DisplayAttributesDialog(parent = self.MapWindow,
-                                                    map = mapName,
-                                                    query = ((east, north), qdist),
-                                                    pos = posWindow,
-                                                    action = "update")
+            dlg = dbm_dialogs.DisplayAttributesDialog(parent = self.MapWindow,
+                                                      map = mapName,
+                                                      query = ((east, north), qdist),
+                                                      pos = posWindow,
+                                                      action = mode)
+            self.dialogs['attributes'] = dlg
+        
         else:
         else:
             # selection changed?
             # selection changed?
             if not self.dialogs['attributes'].mapDBInfo or \
             if not self.dialogs['attributes'].mapDBInfo or \
                     self.dialogs['attributes'].mapDBInfo.map != mapName:
                     self.dialogs['attributes'].mapDBInfo.map != mapName:
-                self.dialogs['attributes'].UpdateDialog(map = mapName, query = ((east, north), qdist))
+                self.dialogs['attributes'].UpdateDialog(map = mapName, query = ((east, north), qdist),
+                                                        action = mode)
             else:
             else:
-                self.dialogs['attributes'].UpdateDialog(query = ((east, north), qdist))
-                
+                self.dialogs['attributes'].UpdateDialog(query = ((east, north), qdist),
+                                                        action = mode)
+        if not self.dialogs['attributes'].IsFound():
+            self._layerManager.goutput.WriteLog(_('Nothing found.'))
+        
         cats = self.dialogs['attributes'].GetCats()
         cats = self.dialogs['attributes'].GetCats()
         
         
         try:
         try:
@@ -1468,11 +1430,8 @@ class MapFrame(wx.Frame):
             self.toolbars['map'].OnTool(event)
             self.toolbars['map'].OnTool(event)
             action = self.toolbars['map'].GetAction()
             action = self.toolbars['map'].GetAction()
         
         
-        point = wx.GetMousePosition()
-        toolsmenu = wx.Menu()
-        
-        # add items to the menu
         if self.toolbars['nviz']:
         if self.toolbars['nviz']:
+            toolsmenu = wx.Menu()
             raster = wx.MenuItem(parentMenu = toolsmenu, id = wx.ID_ANY,
             raster = wx.MenuItem(parentMenu = toolsmenu, id = wx.ID_ANY,
                                  text = _("Query surface (raster map)"),
                                  text = _("Query surface (raster map)"),
                                  kind = wx.ITEM_CHECK)
                                  kind = wx.ITEM_CHECK)
@@ -1487,48 +1446,23 @@ class MapFrame(wx.Frame):
             self.Bind(wx.EVT_MENU, self.OnNvizQueryVector, vector)
             self.Bind(wx.EVT_MENU, self.OnNvizQueryVector, vector)
             if action == "nvizQueryVector":
             if action == "nvizQueryVector":
                 vector.Check(True)
                 vector.Check(True)
+
+            self.PopupMenu(toolsmenu)
+            toolsmenu.Destroy()
         else:
         else:
-            display = wx.MenuItem(parentMenu = toolsmenu, id = wx.ID_ANY,
-                                  text = _("Query raster/vector map(s) (display mode)"),
-                                  kind = wx.ITEM_CHECK)
-            toolsmenu.AppendItem(display)
-            self.Bind(wx.EVT_MENU, self.OnQueryDisplay, display)
-            numLayers = 0
-            if self.tree:
-                for layer in self.tree.GetSelections():
-                    ltype = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
-                    if ltype in ('raster', 'rgb', 'his',
-                                 'vector', 'thememap', 'themechart'):
-                        numLayers += 1
-            if not self.IsStandalone() and numLayers < 1:
-                display.Enable(False)
-            if action == "displayAttrb":
-                display.Check(True)
+            self.toolbars['map'].action['desc'] = 'queryMap'
+            self.MapWindow.mouse['use'] = "query"
             
             
-            modify = wx.MenuItem(parentMenu = toolsmenu, id = wx.ID_ANY,
-                                 text = _("Query vector map (edit mode)"),
-                                 kind = wx.ITEM_CHECK)
-            toolsmenu.AppendItem(modify)
-            self.Bind(wx.EVT_MENU, self.OnQueryModify, modify)
-            modify.Enable(False)
-            if action == "modifyAttrb":
-                modify.Check(True)
+            if not self.IsStandalone():
+                # switch to output console to show query results
+                self._layerManager.notebook.SetSelectionByName('output')
             
             
-            digitToolbar = self.toolbars['vdigit']
-            if self.tree and self.tree.layer_selected:
-                mapLayer = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer']
-                if mapLayer.GetType() == 'vector' and \
-                        mapLayer.GetMapset() == grass.gisenv()['MAPSET'] and \
-                        (not digitToolbar or (digitToolbar and \
-                             digitToolbar.GetLayer() != mapLayer)):
-                    modify.Enable(True)
-            else:
-                if action == "modifyAttrb":
-                    modify.Check(True)
+            self.MapWindow.mouse['box'] = "point"
+            self.MapWindow.zoomtype = 0
+            
+            # change the cursor
+            self.MapWindow.SetCursor(self.cursors["cross"])
         
         
-        self.PopupMenu(toolsmenu)
-        toolsmenu.Destroy()
-
     def AddTmpVectorMapLayer(self, name, cats, useId = False, addLayer = True):
     def AddTmpVectorMapLayer(self, name, cats, useId = False, addLayer = True):
         """!Add temporal vector map layer to map composition
         """!Add temporal vector map layer to map composition
 
 

+ 17 - 2
gui/wxpython/gui_modules/mapdisp_window.py

@@ -1194,8 +1194,23 @@ class BufferedWindow(MapWindow, wx.Window):
             
             
         elif self.mouse["use"] == "query":
         elif self.mouse["use"] == "query":
             # querying
             # querying
-            self.parent.QueryMap(self.mouse['begin'][0],self.mouse['begin'][1])
-        
+            layers = self.GetSelectedLayer(multi = True)
+            isRaster = False
+            nVectors = 0
+            for l in layers:
+                if l.GetType() == 'raster':
+                    isRaster = True
+                    break
+                if l.GetType() == 'vector':
+                    nVectors += 1
+            
+            if isRaster or nVectors > 1:
+                self.parent.QueryMap(self.mouse['begin'][0],self.mouse['begin'][1])
+            else:
+                self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])
+                # clear temp canvas
+                self.UpdateMap(render = False, renderVector = False)
+            
         elif self.mouse["use"] == "queryVector":
         elif self.mouse["use"] == "queryVector":
             # editable mode for vector map layers
             # editable mode for vector map layers
             self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])
             self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])

+ 1 - 1
gui/wxpython/wxgui.py

@@ -930,7 +930,7 @@ class GMFrame(wx.Frame):
 
 
         if os.path.exists(filename):
         if os.path.exists(filename):
             dlg = wx.MessageDialog(self, message = _("Workspace file <%s> already exists. "
             dlg = wx.MessageDialog(self, message = _("Workspace file <%s> already exists. "
-                                                   "Do you want to overwrite this file?") % filename,
+                                                     "Do you want to overwrite this file?") % filename,
                                    caption = _("Save workspace"), style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
                                    caption = _("Save workspace"), style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
             if dlg.ShowModal() != wx.ID_YES:
             if dlg.ShowModal() != wx.ID_YES:
                 dlg.Destroy()
                 dlg.Destroy()