Forráskód Böngészése

wxGUI/interface: using GConsole for executing commands

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54008 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 éve
szülő
commit
0c13cab418
1 módosított fájl, 62 hozzáadás és 18 törlés
  1. 62 18
      gui/wxpython/core/giface.py

+ 62 - 18
gui/wxpython/core/giface.py

@@ -14,38 +14,79 @@ This program is free software under the GNU General Public License
 @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)
-
-        cmdTuple = CmdToTuple(command)
-        returncode = RunCommand(cmdTuple[0], **cmdTuple[1])
-
-        if onDone:
-            onDone(cmd = command, returncode = returncode)
+    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))
+
+    def _onCmdOutput(self, event):
+        """!Print command output"""
+        message = event.text
+        style  = event.type
+
+        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 @@ class StandaloneGrassInterface():
     def GetAllMapDisplays(self):
         """!Get list of all map displays.
         """
-        return []
+        return []
+
+    def GetMapWindow(self):
+        return None