瀏覽代碼

wxGUI/iclass: better error handling when importing/exporting areas

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54496 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年之前
父節點
當前提交
f1819de769
共有 3 個文件被更改,包括 31 次插入25 次删除
  1. 7 0
      gui/wxpython/core/gcmd.py
  2. 22 23
      gui/wxpython/iclass/frame.py
  3. 2 2
      gui/wxpython/iclass/toolbars.py

+ 7 - 0
gui/wxpython/core/gcmd.py

@@ -647,6 +647,10 @@ def RunCommand(prog, flags = "", overwrite = False, quiet = False, verbose = Fal
     if stdin:
         kwargs['stdin'] = subprocess.PIPE
 
+    if parent:
+        messageFormat = os.getenv('GRASS_MESSAGE_FORMAT', 'gui')
+        os.environ['GRASS_MESSAGE_FORMAT'] = 'standard'
+    
     Debug.msg(2, "gcmd.RunCommand(): command started")
     start = time.time()
     
@@ -660,6 +664,9 @@ def RunCommand(prog, flags = "", overwrite = False, quiet = False, verbose = Fal
     Debug.msg(3, "gcmd.RunCommand(): decoding string")
     stdout, stderr = map(DecodeString, ps.communicate())
     
+    if parent: # restore previous settings
+        os.environ['GRASS_MESSAGE_FORMAT'] = messageFormat
+    
     ret = ps.returncode
     Debug.msg(1, "gcmd.RunCommand(): get return code %d (%.6f sec)" % \
                   (ret, (time.time() - start)))

+ 22 - 23
gui/wxpython/iclass/frame.py

@@ -511,6 +511,13 @@ class IClassMapFrame(DoubleMapFrame):
         """
         wx.BeginBusyCursor()
         wx.Yield()
+
+        if 0 != RunCommand('g.copy',
+                           vect = [vector, self.trainingAreaVector],
+                           overwrite = True, quiet = True,
+                           parent = self):
+            wx.EndBusyCursor()
+            return False
         
         mapLayer = self.toolbars['vdigit'].mapLayer
         # set mapLayer temporarily to None
@@ -522,14 +529,6 @@ class IClassMapFrame(DoubleMapFrame):
             wx.EndBusyCursor()
             return False
             
-        ret, msg = RunCommand('g.copy',
-                              vect = [vector, self.trainingAreaVector],
-                              overwrite = True,
-                              getErrorMsg = True)
-        if ret != 0:
-            wx.EndBusyCursor()
-            return False
-            
         ret = self.toolbars['vdigit'].StartEditing(mapLayer)
         if not ret:
             wx.EndBusyCursor()
@@ -654,15 +653,18 @@ class IClassMapFrame(DoubleMapFrame):
 
         if '@' in vectorName:
             vectorName = vectorName.split('@')[0]
-        RunCommand('g.copy',
-                    vect = ','.join([self.trainingAreaVector, vectorName]),
-                    overwrite = True)
-        # remove connection if exists:
+        if 0 != RunCommand('g.copy',
+                           vect = [self.trainingAreaVector, vectorName],
+                           overwrite = True, quiet = True, parent = self):
+            wx.EndBusyCursor()
+            return
+        
+        # remove connection if exists
         dbinfo = grass.vector_db(vectorName)
         if dbinfo:
             for layer in dbinfo.keys():
                 RunCommand('v.db.connect', flags = 'd', map = vectorName, layer = layer)
-
+        
         mapset = grass.gisenv()['MAPSET']
         self.poMapInfo = displayDriver.OpenMap(name = self.trainingAreaVector, mapset = mapset)
             
@@ -670,7 +672,7 @@ class IClassMapFrame(DoubleMapFrame):
             wx.EndBusyCursor()
             return
             
-        # add table
+        # add new table
         columns = ["class varchar(30)",
                    "color varchar(11)",
                    "n_cells integer",]
@@ -683,16 +685,13 @@ class IClassMapFrame(DoubleMapFrame):
                                                                     'stat' : statistic,
                                                                     'format' : format})
         
-        ret, msg = RunCommand('v.db.addtable',
-                         map = vectorName,
-                         columns = columns,
-                         getErrorMsg = True)
-        if ret != 0:
+        if 0 != RunCommand('v.db.addtable',
+                           map = vectorName,
+                           columns = columns,
+                           parent = self):
             wx.EndBusyCursor()
-            GMessage(parent = self, message = _("Failed to add attribute table. "
-                                                "Details:\n%s" % msg))
             return
-            
+        
         # populate table
         for cat in self.statisticsList:
             stat = self.statisticsDict[cat]
@@ -709,7 +708,7 @@ class IClassMapFrame(DoubleMapFrame):
                 self._runDBUpdate(map = vectorName, column = "band%d_min" % (i + 1), value = stat.bands[i].min, cat = cat)
                 self._runDBUpdate(map = vectorName, column = "band%d_mean" % (i + 1), value = stat.bands[i].mean, cat = cat)
                 self._runDBUpdate(map = vectorName, column = "band%d_max" % (i + 1), value = stat.bands[i].max, cat = cat)
-        
+                
         wx.EndBusyCursor()
         
     def _runDBUpdate(self, map, column, value, cat):

+ 2 - 2
gui/wxpython/iclass/toolbars.py

@@ -41,9 +41,9 @@ iClassIcons = {
         'delCmd' : MetaIcon(img = 'layer-remove',
                             label = _('Delete selected map layer')),
         'exportAreas' : MetaIcon(img = 'layer-export',
-                            label = _('Export training areas')),
+                            label = _('Export training areas to vector map')),
         'importAreas' : MetaIcon(img = 'layer-import',
-                            label = _('Import training areas')),
+                            label = _('Import training areas from vector map')),
         'addRgb' : MetaIcon(img = 'layer-rgb-add',
                             label = _('Add RGB map layer')),
         }