[GRASS-SVN] r30697 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 22 16:29:19 EDT 2008


Author: martinl
Date: 2008-03-22 16:29:19 -0400 (Sat, 22 Mar 2008)
New Revision: 30697

Modified:
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/render.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: creating vector map (from menu or digitizer) fixed
some minor issues, sys.stderr redirected to goutput (if defined)


Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -62,7 +62,7 @@
                       message=self.message,
                       style=wx.ICON_ERROR | wx.CENTRE)
 
-        return ''
+        return 'GException: %s' % self.message
 
 class GStdError(GException):
     """Generic exception"""
@@ -358,8 +358,7 @@
                                     os.linesep, os.linesep,
                                     _("Details:"),
                                     os.linesep,
-                                    self.cmdThread.rerr))
-#                                    self.PrintModuleOutput()))
+                                    self.PrintModuleOutput()))
                 elif rerr == sys.stderr: # redirect message to sys
                     stderr.write("Execution failed: '%s'" % (' '.join(self.cmd)))
                     stderr.write("%sDetails:%s%s" % (os.linesep,
@@ -384,8 +383,6 @@
     def __ReadOutput(self, stream):
         """Read stream and return list of lines
 
-        Note: Remove os.linesep from output
-
         @param stream stream to be read
         """
         lineList = []
@@ -452,7 +449,7 @@
 
         return msg
 
-    def PrintModuleOutput(self, error=True, warning=True, message=True):
+    def PrintModuleOutput(self, error=True, warning=False, message=False):
         """Print module errors, warnings, messages to output
 
         @param error print errors
@@ -574,7 +571,7 @@
                 # line = self.__read_all(self.module.stderr)
                 line = recv_some(self.module, e=0, stderr=1)
                 self.stderr.write(line)
-                
+
         # get the last output
         if self.stdout:
             # line = self.__read_all(self.module.stdout)
@@ -585,8 +582,6 @@
             line = recv_some(self.module, e=0, stderr=1)
             self.stderr.write(line)
 
-        self.rerr = self.__parseString(line)
-       
         if hasattr(self.stderr, "gmstc"):
             # -> GMConsole
             if self._want_abort: # abort running process
@@ -598,28 +593,6 @@
         """Abort running process, used by main thread to signal an abort"""
         self._want_abort = True
 
-    def __parseString(self, string):
-        """Parse line
-
-        @param line line to parsed, all GRASS_INFO
-        messages are removed from line
-        
-        @return string with GRASS_INFO messages
-        """
-        err = ''
-        for line in string.split('%s' % os.linesep):
-            if 'GRASS_INFO_ERROR' in line:
-                err += line + '%s' % os.linesep
-            elif err != '' and 'GRASS_INFO_END' in line:
-                err += line
-            elif 'ERROR' in line:
-                err += line
-            elif err != '':
-                err += line
-                
-        return err
-        
-        
 # testing ...
 if __name__ == "__main__":
     SEP = "-----------------------------------------------------------------------------"

Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -15,6 +15,8 @@
 @author Martin Landa <landa.martin gmail.com>
 """
 
+import sys
+
 import wx
 
 import gcmd
@@ -89,11 +91,13 @@
 
     def GetName(self):
         """Return (mapName, overwrite)"""
-        return (self.mapName.GetValue() + '@' + grassenv.GetGRASSVariable('MAPSET'),
+        mapName = self.mapName.GetValue().split('@', 1)[0]
+
+        return (mapName,
                 self.overwrite.IsChecked())
 
-
-def CreateNewVector(parent, title=_('Create new vector map')):
+def CreateNewVector(parent, title=_('Create new vector map'),
+                    exceptMap=None):
     """Create new vector map layer
 
     @return name of create vector map
@@ -102,7 +106,13 @@
     dlg = NewVectorDialog(parent=parent, id=wx.ID_ANY, title=title)
     if dlg.ShowModal() == wx.ID_OK:
         outmap, overwrite = dlg.GetName()
-        
+        if outmap == exceptMap:
+            wx.MessageBox(parent=parent,
+                          message=_("Unable to create vector map <%s>.") % outmap,
+                          caption=_("Error"),
+                          style=wx.ID_OK | wx.ICON_ERROR | wx.CENTRE)
+            return False
+
         if outmap == '': # should not happen
             return False
         
@@ -113,9 +123,14 @@
         if overwrite is True:
             cmd.append('--overwrite')
             
-        p = gcmd.Command(cmd)
-            
+        try:
+            p = gcmd.Command(cmd, stderr=None)
+        except gcmd.CmdError, e:
+            print >> sys.stderr, e
+            return None
+
         if p.returncode == 0:
-            return outmap
+            # return fully qualified map name
+            return outmap + '@' + grassenv.GetGRASSVariable('MAPSET')
 
     return None

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -19,6 +19,7 @@
 """
 
 import os
+import sys
 import textwrap
 import time
 
@@ -53,9 +54,12 @@
         self.cmd_output = GMStc(parent=self, id=wx.ID_ANY, margin=margin)
         # redirect
         self.cmd_stdout = GMStdout(self.cmd_output)
+        ### sys.stdout = self.cmd_stdout
         self.cmd_stderr = GMStderr(self.cmd_output,
-                                   self.console_progressbar)
-
+                                   self.console_progressbar,
+                                   self.parent.notebook)
+        sys.stderr = self.cmd_stderr
+        
         # buttons
         self.console_clear = wx.Button(parent=self, id=wx.ID_CLEAR)
         self.console_save  = wx.Button(parent=self, id=wx.ID_SAVE)
@@ -316,11 +320,15 @@
     Copyright: (c) 2005-2007 Jean-Michel Fauth
     Licence:   GPL
     """
-    def __init__(self, gmstc, gmgauge):
-        self.gmstc   = gmstc
-        self.gmgauge = gmgauge
+    def __init__(self, gmstc, gmgauge, notebook):
+        self.gmstc    = gmstc
+        self.gmgauge  = gmgauge
+        self.notebook = notebook
 
     def write(self, s):
+        #        if self.notebook.GetSelection() != 1: # command output
+        #            self.notebook.SetSelection(1)
+
         s = s.replace('\n', os.linesep)
         # remove/replace escape sequences '\b' or '\r' from stream
         s = s.replace('\b', '').replace('\r', '%s' % os.linesep)

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -123,13 +123,14 @@
         try:
             runcmd = gcmd.Command(cmd=self.cmdlist + ['--q'],
                                   stderr=None)
+            if runcmd.returncode != 0:
+                self.mapfile = None
+                self.maskfile = None
+
         except gcmd.CmdError, e:
             print e
-        
-        if runcmd.returncode != 0:
             self.mapfile = None
             self.maskfile = None
-            return None
 
         #
         # stop monitor

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -615,7 +615,12 @@
         selected map layer activated for editing.
         """
         if event.GetSelection() == 0: # create new vector map layer
-            mapName = gdialogs.CreateNewVector(self.parent)
+            if self.layerSelectedID is not None:
+                openVectorMap = self.layers[self.layerSelectedID].name.split('@')[0]
+            else:
+                openVectorMap = None
+            mapName = gdialogs.CreateNewVector(self.parent,
+                                               exceptMap=openVectorMap)
             if mapName:
                 # add layer to map layer tree
                 if self.layerTree:
@@ -629,6 +634,9 @@
                     selection = vectLayers.index(mapName)
                 else:
                     pass # TODO (no Layer Manager)
+            else:
+                self.combo.SetValue(_('Select vector map'))
+                return 
         else:
             selection = event.GetSelection() - 1 # first option is 'New vector map'
 
@@ -667,7 +675,7 @@
             self.parent.digit.SetMapName(mapLayer.name)
         except gcmd.DigitError, e:
             self.layerSelectedID = None
-            print e # wxMessageBox
+            print >> sys.stderr, e # wxMessageBox
             return False
 
         # update toolbar
@@ -753,7 +761,7 @@
 
         if updateTool: # update toolbar
             if self.layerSelectedID == None:
-                value = 'Select vector map'
+                value = _('Select vector map')
             else:
                 value = layerNameSelected
 

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-03-22 19:51:17 UTC (rev 30696)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-03-22 20:29:19 UTC (rev 30697)
@@ -436,7 +436,9 @@
 
     def OnNewVector(self, event):
         """Create new vector map layer"""
-        gdialogs.CreateNewVector(self)
+        name = gdialogs.CreateNewVector(self)
+        if name:
+            self.goutput.WriteCmdLog('New vector map <%s> created' % name)
             
     def OnAboutGRASS(self, event):
         """Display 'About GRASS' dialog"""



More information about the grass-commit mailing list