[GRASS-SVN] r45187 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 26 05:02:46 EST 2011
Author: martinl
Date: 2011-01-26 02:02:44 -0800 (Wed, 26 Jan 2011)
New Revision: 45187
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
Log:
wxGUI: handle error when zooming
(merge r45186 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py 2011-01-26 09:57:48 UTC (rev 45186)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py 2011-01-26 10:02:44 UTC (rev 45187)
@@ -541,9 +541,45 @@
"""!Abort running process, used by main thread to signal an abort"""
self._want_abort = True
+def _formatMsg(text):
+ """!Format error messages for dialogs
+ """
+ message = ''
+ for line in text.splitlines():
+ if len(line) == 0:
+ continue
+ elif 'GRASS_INFO_MESSAGE' in line:
+ message += line.split(':', 1)[1].strip() + '\n'
+ elif 'GRASS_INFO_WARNING' in line:
+ message += line.split(':', 1)[1].strip() + '\n'
+ elif 'GRASS_INFO_ERROR' in line:
+ message += line.split(':', 1)[1].strip() + '\n'
+ elif 'GRASS_INFO_END' in line:
+ return message
+ else:
+ message += line.strip() + '\n'
+
+ return message
+
def RunCommand(prog, flags = "", overwrite = False, quiet = False, verbose = False,
parent = None, read = False, stdin = None, getErrorMsg = False, **kwargs):
- """!Run GRASS command"""
+ """!Run GRASS command
+
+ @param prog program to run
+ @param flags flags given as a string
+ @param overwrite, quiet, verbose flags
+ @param parent parent window for error messages
+ @param read fetch stdout
+ @param stdin stdin or None
+ @param getErrorMsg get error messages on failure
+ @param kwargs program parameters
+
+ @return returncode (read == False and getErrorMsg == False)
+ @return returncode, messages (read == False and getErrorMsg == True)
+ @return stdout (read == True and getErrorMsg == False)
+ @return returncode, stdout, messages (read == True and getErrorMsg == True)
+ @return stdout, stderr
+ """
Debug.msg(1, "gcmd.RunCommand(): %s" % ' '.join(grass.make_command(prog, flags, overwrite,
quiet, verbose, **kwargs)))
@@ -574,12 +610,12 @@
if not getErrorMsg:
return ret
else:
- return ret, stderr
+ return ret, _formatMsg(stderr)
if not getErrorMsg:
return stdout
if read and getErrorMsg:
- return ret, stdout, stderr
+ return ret, stdout, _formatMsg(stderr)
- return stdout, stderr
+ return stdout, _formatMsg(stderr)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py 2011-01-26 09:57:48 UTC (rev 45186)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcpmanager.py 2011-01-26 10:02:44 UTC (rev 45187)
@@ -1396,48 +1396,46 @@
msg = err = ''
ret, out, err = gcmd.RunCommand('v.transform',
- flags = '-o',
- input=vect,
- output=self.outname,
- pointsfile=self.file['points'],
- getErrorMsg=True, read=True)
-
-
+ flags = 'o',
+ input = vect,
+ output = self.outname,
+ pointsfile = self.file['points'],
+ getErrorMsg = True, read = True)
+
if ret == 0:
self.VectGRList.append(self.outname)
- print err
# note: WriteLog doesn't handle GRASS_INFO_PERCENT well, so using a print here
-# self.parent.goutput.WriteLog(text = _(err), switchPage = True)
- self.parent.goutput.WriteLog(text = _(out), switchPage = True)
+ # self.parent.goutput.WriteLog(text = _(err), switchPage = True)
+ self.parent.goutput.WriteLog(text = out, switchPage = True)
else:
self.parent.goutput.WriteError(_('Georectification of vector map <%s> failed') %
- self.outname)
- self.parent.goutput.WriteError(_(err))
-
+ self.outname)
+ self.parent.goutput.WriteError(err)
+
# FIXME
# Copying database information not working.
# Does not copy from xy location to current location
# TODO: replace $GISDBASE etc with real paths
-# xyLayer = []
-# for layer in grass.vector_db(map = vect).itervalues():
-# xyLayer.append((layer['driver'],
-# layer['database'],
-# layer['table']))
+ # xyLayer = []
+ # for layer in grass.vector_db(map = vect).itervalues():
+ # xyLayer.append((layer['driver'],
+ # layer['database'],
+ # layer['table']))
+
+
+ # dbConnect = grass.db_connection()
+ # print 'db connection =', dbConnect
+ # for layer in xyLayer:
+ # self.parent.goutput.RunCmd(['db.copy',
+ # '--q',
+ # '--o',
+ # 'from_driver=%s' % layer[0],
+ # 'from_database=%s' % layer[1],
+ # 'from_table=%s' % layer[2],
+ # 'to_driver=%s' % dbConnect['driver'],
+ # 'to_database=%s' % dbConnect['database'],
+ # 'to_table=%s' % layer[2] + '_' + self.extension])
-
-# dbConnect = grass.db_connection()
-# print 'db connection =', dbConnect
-# for layer in xyLayer:
-# self.parent.goutput.RunCmd(['db.copy',
-# '--q',
-# '--o',
-# 'from_driver=%s' % layer[0],
-# 'from_database=%s' % layer[1],
-# 'from_table=%s' % layer[2],
-# 'to_driver=%s' % dbConnect['driver'],
-# 'to_database=%s' % dbConnect['database'],
-# 'to_table=%s' % layer[2] + '_' + self.extension])
-
# copy all georectified vectors from source location to current location
for name in self.VectGRList:
xyvpath = os.path.join(self.grassdatabase,
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2011-01-26 09:57:48 UTC (rev 45186)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2011-01-26 10:02:44 UTC (rev 45187)
@@ -642,14 +642,16 @@
if vect:
cmd['vect'] = ','.join(vect)
- ret = gcmd.RunCommand('g.region',
- read = True,
- **cmd)
- if not ret:
+ ret, reg, msg = gcmd.RunCommand('g.region',
+ read = True,
+ getErrorMsg = True,
+ **cmd)
+
+ if ret != 0:
if rast:
- message = _("Unable to zoom to raster map <%s>.") % rast[0]
+ message = _("Unable to zoom to raster map <%s>.\n\nDetails: %s") % (rast[0], msg)
elif vect:
- message = _("Unable to zoom to vector map <%s>.") % vect[0]
+ message = _("Unable to zoom to vector map <%s>.\n\nDetails: %s") % (vect[0], msg)
else:
message = _("Unable to get current geographic extent. "
"Force quiting wxGUI. Please run manually g.region to "
@@ -657,8 +659,8 @@
gcmd.GError(message)
return self.region
- for reg in ret.splitlines():
- key, val = reg.split("=", 1)
+ for r in reg.splitlines():
+ key, val = r.split("=", 1)
try:
region[key] = float(val)
except ValueError:
More information about the grass-commit
mailing list