Browse Source

wxGUI: add environment paramater to GConsole

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68398 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 9 years ago
parent
commit
58918d1997
2 changed files with 15 additions and 14 deletions
  1. 11 10
      gui/wxpython/core/gconsole.py
  2. 4 4
      gui/wxpython/core/giface.py

+ 11 - 10
gui/wxpython/core/gconsole.py

@@ -431,7 +431,7 @@ class GConsole(wx.EvtHandler):
         """Write message in error style"""
         self.writeError.emit(text=text)
 
-    def RunCmd(self, command, compReg=True, skipInterface=False,
+    def RunCmd(self, command, compReg=True, env=None, skipInterface=False,
                onDone=None, onPrepare=None, userData=None, addLayer=None,
                notification=Notification.MAKE_VISIBLE):
         """Run command typed into console command prompt (GPrompt).
@@ -542,12 +542,14 @@ class GConsole(wx.EvtHandler):
 
                         return
 
+                if env:
+                    env = env.copy()
+                else:
+                    env = os.environ.copy()
                 # activate computational region (set with g.region)
                 # for all non-display commands.
-                if compReg:
-                    tmpreg = os.getenv("GRASS_REGION")
-                    if "GRASS_REGION" in os.environ:
-                        del os.environ["GRASS_REGION"]
+                if compReg and "GRASS_REGION" in env:
+                    del env["GRASS_REGION"]
 
                 # process GRASS command with argument
                 self.cmdThread.RunCmd(command,
@@ -555,14 +557,12 @@ class GConsole(wx.EvtHandler):
                                       stderr=self.cmdStdErr,
                                       onDone=onDone, onPrepare=onPrepare,
                                       userData=userData, addLayer=addLayer,
-                                      env=os.environ.copy(),
+                                      env=env,
                                       notification=notification)
                 self.cmdOutputTimer.Start(50)
 
-                # deactivate computational region and return to display
-                # settings
-                if compReg and tmpreg:
-                    os.environ["GRASS_REGION"] = tmpreg
+                # we don't need to change computational region settings
+                # because we work on a copy
         else:
             # Send any other command to the shell. Send output to
             # console output window
@@ -609,6 +609,7 @@ class GConsole(wx.EvtHandler):
                                       stderr=self.cmdStdErr,
                                       onDone=onDone, onPrepare=onPrepare,
                                       userData=userData, addLayer=addLayer,
+                                      env=env,
                                       notification=notification)
             self.cmdOutputTimer.Start(50)
 

+ 4 - 4
gui/wxpython/core/giface.py

@@ -246,13 +246,13 @@ class StandaloneGrassInterface():
         grass.percent(event.value, 100, 1)
         event.Skip()
 
-    def RunCmd(
-            self, command, compReg=True, skipInterface=False, onDone=None,
-            onPrepare=None, userData=None,
-            notification=Notification.MAKE_VISIBLE):
+    def RunCmd(self, command, compReg=True, env=None, skipInterface=False,
+               onDone=None, onPrepare=None, userData=None,
+               notification=Notification.MAKE_VISIBLE):
         self._gconsole.RunCmd(
             command=command,
             compReg=compReg,
+            env=env,
             skipInterface=skipInterface,
             onDone=onDone,
             onPrepare=onPrepare,