[GRASS-SVN] r31221 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 3 05:29:57 EDT 2008


Author: martinl
Date: 2008-05-03 05:29:57 -0400 (Sat, 03 May 2008)
New Revision: 31221

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
Log:
wxGUI: better handling non-GRASS commands (or wrongly typed commands)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-05-03 09:29:28 UTC (rev 31220)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-05-03 09:29:57 UTC (rev 31221)
@@ -62,7 +62,8 @@
                       message=self.message,
                       style=wx.ICON_ERROR | wx.CENTRE)
 
-        return 'GException: %s' % self.message
+        # return 'GException: %s' % self.message
+        return ''
 
 class GStdError(GException):
     """Generic exception"""
@@ -337,11 +338,14 @@
         # start thread
         #
         self.cmdThread.start()
-
+            
         if wait:
             self.cmdThread.join()
-            self.cmdThread.module.wait()
-            self.returncode = self.cmdThread.module.returncode
+            if self.cmdThread.module:
+                self.cmdThread.module.wait()
+                self.returncode = self.cmdThread.module.returncode
+            else:
+                self.returncode = 1
         else:
             self.cmdThread.join(0.5)
             self.returncode = None
@@ -513,8 +517,10 @@
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
         except OSError, e:
-            raise CmdError(self.cmd[0], str(e))
-        
+            self.rerr = str(e)
+            return
+            # raise CmdError(self.cmd[0], str(e))
+
         if self.stdin: # read stdin if requested ...
             self.module.stdin.write(self.stdin)
             self.module.stdin.close()

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-05-03 09:29:28 UTC (rev 31220)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-05-03 09:29:57 UTC (rev 31221)
@@ -161,7 +161,7 @@
             wx.Yield()
             time.sleep(3)
             busy.Destroy()
-            return 
+            return  None
 
         # command given as a string ?
         try:
@@ -172,7 +172,10 @@
         if cmdlist[0] in globalvar.grassCmd['all']:
             # send GRASS command without arguments to GUI command interface
             # except display commands (they are handled differently)
-            if cmdlist[0][0:2] == "d.": # display GRASS commands
+            if cmdlist[0][0:2] == "d.":
+                #
+                # display GRASS commands
+                #
                 try:
                     layertype = {'d.rast'         : 'raster',
                                  'd.rgb'          : 'rgb',
@@ -190,13 +193,16 @@
                                  'd.labels'       : 'labels'}[cmdlist[0]]
                 except KeyError:
                     wx.MessageBox(message=_("Command '%s' not yet implemented.") % cmdlist[0])
-                    return False
+                    return None
 
                 # add layer into layer tree
                 self.parent.curr_page.maptree.AddLayer(ltype=layertype,
                                                        lcmd=cmdlist)
 
-            else: # other GRASS commands (r|v|g|...)
+            else:
+                #
+                # other GRASS commands (r|v|g|...)
+                #
                 if hasattr(self.parent, "curr_page"):
                     # change notebook page only for Layer Manager
                     if self.parent.notebook.GetSelection() != 1:
@@ -233,18 +239,16 @@
                 if self.parent.notebook.GetSelection() != 1:
                     self.parent.notebook.SetSelection(1)
 
-            print "$ " + ' '.join(cmdlist)
-            
             # if command is not a GRASS command, treat it like a shell command
-            generalCmd = subprocess.Popen(cmdlist,
-                                          stdout=subprocess.PIPE,
-                                          stderr=subprocess.PIPE)
-            
-            for outline in generalCmd.stdout:
-                print outline
-                   
-            return None
+            try:
+                generalCmd = gcmd.Command(cmdlist,
+                                          stdout=self.cmd_stdout,
+                                          stderr=self.cmd_stderr)
+            except gcmd.CmdError, e:
+                print >> sys.stderr, e
 
+        return None
+
     def ClearHistory(self, event):
         """Clear history of commands"""
         self.cmd_output.ClearAll()
@@ -299,10 +303,14 @@
             self.WriteCmdLog(_('Command aborted'),
                              pid=self.cmdThreads[event.cmdThread]['cmdPID'])
         else:
-            # Process results here
-            self.WriteCmdLog(_('Command finished (%d sec)') % (time.time() - event.cmdThread.startTime),
-                             pid=self.cmdThreads[event.cmdThread]['cmdPID'])
-
+            try:
+                # Process results here
+                self.WriteCmdLog(_('Command finished (%d sec)') % (time.time() - event.cmdThread.startTime),
+                                 pid=self.cmdThreads[event.cmdThread]['cmdPID'])
+            except KeyError:
+                # stopped deamon
+                pass
+                
         self.console_progressbar.SetValue(0) # reset progress bar on '0%'
 
         # updated command dialog



More information about the grass-commit mailing list