[GRASS-SVN] r48425 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 23 13:18:44 EDT 2011


Author: martinl
Date: 2011-09-23 10:18:44 -0700 (Fri, 23 Sep 2011)
New Revision: 48425

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/dbm.py
Log:
wxGUI: #1007 (WxGUI should provide visual feedback when adding new db column)
      (merge r48423 from trunk)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/dbm.py	2011-09-23 17:16:04 UTC (rev 48424)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/dbm.py	2011-09-23 17:18:44 UTC (rev 48425)
@@ -18,7 +18,7 @@
  - VirtualAttributeList
  - AttributeManager
 
-(C) 2007-2009 by the GRASS Development Team
+(C) 2007-2009, 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
@@ -1742,47 +1742,46 @@
         """!Add new column to the table"""
 	table = self.mapDBInfo.layers[self.layer]['table']
         name = self.FindWindowById(self.layerPage[self.layer]['addColName']).GetValue()
-
+        
         if not name:
-            wx.MessageBox(parent=self,
-                          message=_("Unable to add column to the table. "
-                                    "No column name defined."),
-                          caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            gcmd.GError(parent = self,
+                        message = _("Unable to add column to the table. "
+                                    "No column name defined."))
             return
-
-        type = self.FindWindowById(self.layerPage[self.layer]['addColType']). \
+        
+        ctype = self.FindWindowById(self.layerPage[self.layer]['addColType']). \
             GetStringSelection()
         
         # cast type if needed
-        if type == 'double':
-            type = 'double precision'
-        if type == 'varchar':
+        if ctype == 'double':
+            ctype = 'double precision'
+        if ctype == 'varchar':
             length = int(self.FindWindowById(self.layerPage[self.layer]['addColLength']). \
                              GetValue())
         else:
             length = '' # FIXME
-
+        
         # add item to the list of table columns
-        list = self.FindWindowById(self.layerPage[self.layer]['tableData'])
+        tlist = self.FindWindowById(self.layerPage[self.layer]['tableData'])
         # check for duplicate items
-        if list.FindItem(start=-1, str=name) > -1:
-            wx.MessageBox(parent=self,
-                          message=_("Column <%(column)s> already exists in table <%(table)s>.") % \
-                              {'column' : name, 'table' : self.mapDBInfo.layers[self.layer]["table"]},
-                          caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+        if tlist.FindItem(start=-1, str=name) > -1:
+            gcmd.GError(parent = self,
+                        message = _("Column <%(column)s> already exists in table <%(table)s>.") % \
+                            {'column' : name, 'table' : self.mapDBInfo.layers[self.layer]["table"]}
+                        )
             return
-        index = list.InsertStringItem(sys.maxint, str(name))
-        list.SetStringItem(index, 0, str(name))
-        list.SetStringItem(index, 1, str(type))
-        list.SetStringItem(index, 2, str(length))
+        index = tlist.InsertStringItem(sys.maxint, str(name))
+        tlist.SetStringItem(index, 0, str(name))
+        tlist.SetStringItem(index, 1, str(ctype))
+        tlist.SetStringItem(index, 2, str(length))
         
         # add v.db.addcol command to the list
-        if type == 'varchar':
-            type += ' (%d)' % length
+        if ctype == 'varchar':
+            ctype += ' (%d)' % length
         self.listOfCommands.append(('v.db.addcol',
-                                    { 'map' : self.vectorName,
-                                      'layer' : self.layer,
-                                      'columns' : '%s %s' % (name, type) }
+                                    { 'map'     : self.vectorName,
+                                      'layer'   : self.layer,
+                                      'columns' : '%s %s' % (name, ctype) }
                                     ))
         # apply changes
         self.ApplyCommands()
@@ -1857,6 +1856,8 @@
     def ApplyCommands(self):
         """!Apply changes"""
         # perform GRASS commands (e.g. v.db.addcol)
+        wx.BeginBusyCursor()
+        
         if len(self.listOfCommands) > 0:
             for cmd in self.listOfCommands:
                 gcmd.RunCommand(prog = cmd[0],
@@ -1879,7 +1880,7 @@
 
             # reset list of commands
             self.listOfCommands = []
-
+        
         # perform SQL non-select statements (e.g. 'delete from table where cat=1')
         if len(self.listOfSQLStatements) > 0:
             sqlFile = tempfile.NamedTemporaryFile(mode="wt")
@@ -1896,10 +1897,10 @@
 
             driver   = self.mapDBInfo.layers[self.layer]["driver"]
             database = self.mapDBInfo.layers[self.layer]["database"]
-
+            
             Debug.msg(3, 'AttributeManger.ApplyCommands(): %s' %
                       ';'.join(["%s" % s for s in self.listOfSQLStatements]))
-
+            
             gcmd.RunCommand('db.execute',
                             parent = self,
                             input = sqlFile.name,
@@ -1908,13 +1909,17 @@
             
             # reset list of statements
             self.listOfSQLStatements = []
-
+            
+        wx.EndBusyCursor()
+        
     def OnApplySqlStatement(self, event):
         """!Apply simple/advanced sql statement"""
         keyColumn = -1 # index of key column
         listWin = self.FindWindowById(self.layerPage[self.layer]['data'])
         sql = None
         
+        wx.BeginBusyCursor()
+        
         if self.FindWindowById(self.layerPage[self.layer]['simple']).GetValue():
             # simple sql statement
             whereCol = self.FindWindowById(self.layerPage[self.layer]['whereColumn']).GetStringSelection()
@@ -1962,6 +1967,8 @@
             else:
                 listWin.SortListItems(col=0, ascending=True) 
         
+        wx.EndBusyCursor()
+        
         # update statusbar
         self.log.write(_("Number of loaded records: %d") % \
                            self.FindWindowById(self.layerPage[self.layer]['data']).GetItemCount())



More information about the grass-commit mailing list