[GRASS-SVN] r54008 - grass/trunk/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 24 04:03:02 PST 2012


Author: annakrat
Date: 2012-11-24 04:03:01 -0800 (Sat, 24 Nov 2012)
New Revision: 54008

Modified:
   grass/trunk/gui/wxpython/core/giface.py
Log:
wxGUI/interface: using GConsole for executing commands

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2012-11-24 11:12:27 UTC (rev 54007)
+++ grass/trunk/gui/wxpython/core/giface.py	2012-11-24 12:03:01 UTC (rev 54008)
@@ -14,39 +14,80 @@
 @author Anna Kratochvilova <kratochanna gmail.com>
 @author Vaclav Petras <wenzeslaus gmail.com>
 """
-from core.gcmd import RunCommand
-from core.utils import CmdToTuple
 
+import os
+from core.gconsole import GConsole, \
+    EVT_CMD_OUTPUT, EVT_CMD_PROGRESS, EVT_CMD_RUN, EVT_CMD_DONE, \
+    EVT_WRITE_LOG, EVT_WRITE_CMD_LOG, EVT_WRITE_WARNING, EVT_WRITE_ERROR
+
 import grass.script as grass
 
 class StandaloneGrassInterface():
-    def RunCmd(self, command,
-               onDone = None, onPrepare = None, userData = None, **kwargs):
-        if onPrepare:
-            onPrepare(userData)
+    def __init__(self):
+        self._gconsole = GConsole()
+        self._gconsole.Bind(EVT_CMD_PROGRESS, self._onCmdProgress)
+        self._gconsole.Bind(EVT_CMD_OUTPUT, self._onCmdOutput)
+        self._gconsole.Bind(EVT_WRITE_LOG,
+                            lambda event:
+                                self.WriteLog(text = event.text))
+        self._gconsole.Bind(EVT_WRITE_CMD_LOG,
+                            lambda event:
+                                self.WriteCmdLog(line = event.line))
+        self._gconsole.Bind(EVT_WRITE_WARNING,
+                            lambda event:
+                                self.WriteWarning(line = event.line))
+        self._gconsole.Bind(EVT_WRITE_ERROR,
+                            lambda event:
+                                self.WriteError(line = event.line))
 
-        cmdTuple = CmdToTuple(command)
-        returncode = RunCommand(cmdTuple[0], **cmdTuple[1])
+    def _onCmdOutput(self, event):
+        """!Print command output"""
+        message = event.text
+        style  = event.type
 
-        if onDone:
-            onDone(cmd = command, returncode = returncode)
+        if style == 'warning':
+            self.WriteWarning(message)
+        elif style == 'error':
+            self.WriteError(message)
+        else:
+            self.WriteLog(message)
+        event.Skip()
 
+    def _onCmdProgress(self, event):
+        """!Update progress message info"""
+        grass.percent(event.value, 100, 1)
+        event.Skip()
+
+    def RunCmd(self, command, compReg=True, switchPage=False, skipInterface=False,
+               onDone=None, onPrepare=None, userData=None, priority=1):
+        self._gconsole.RunCmd(command=command, compReg=compReg, switchPage=switchPage,
+                              skipInterface=skipInterface, onDone=onDone,
+                              onPrepare=onPrepare, userData=userData, priority=priority)
+
     def Help(self, entry):
-        RunCommand('g.manual', quiet = True, entry = entry)
+        self._gconsole.RunCmd(['g.manual', 'entry=%s' % entry])
 
     def WriteLog(self, text, wrap = None,
                  switchPage = False, priority = 1):
-        grass.message(text)
+        self._write(grass.message, text)
 
     def WriteCmdLog(self, line, pid = None, switchPage = True):
-        grass.message(line)
+        if pid:
+            line = '(' + str(pid) + ') ' + line
+        self._write(grass.message, line)
 
     def WriteWarning(self, line):
-        grass.warning(line)
+        self._write(grass.warning, line)
 
     def WriteError(self, line):
-        grass.error(line)
+        self._write(grass.error, line)
 
+    def _write(self, function, text):
+        orig = os.getenv("GRASS_MESSAGE_FORMAT")
+        os.environ["GRASS_MESSAGE_FORMAT"] = 'standard'
+        function(text)
+        os.environ["GRASS_MESSAGE_FORMAT"] = orig
+
     def GetLayerTree(self):
         return None
 
@@ -58,4 +99,7 @@
     def GetAllMapDisplays(self):
         """!Get list of all map displays.
         """
-        return []
\ No newline at end of file
+        return []
+
+    def GetMapWindow(self):
+        return None



More information about the grass-commit mailing list