<div dir="ltr">Hi,<div><br></div><div>I committed a change to rendering which could help to run d.mon and wxGUI together. The environment is changed only for the rendering process and not for the entire wxGUI. There is a lot of other places which should be changed like this but the rendering is the most important. Please test, I tried to test it already (d.mon, wms, georectifier) but more testing is still needed.</div>
<div><br></div><div>Anna<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 20, 2014 at 11:14 AM, <span dir="ltr"><<a href="mailto:svn_grass@osgeo.org" target="_blank">svn_grass@osgeo.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: annakrat<br>
Date: 2014-05-20 08:14:42 -0700 (Tue, 20 May 2014)<br>
New Revision: 60376<br>
<br>
Modified:<br>
grass/trunk/gui/wxpython/core/render.py<br>
grass/trunk/gui/wxpython/core/ws.py<br>
Log:<br>
wxGUI/rendering: change environment only for subprocesses; wxGUI amd d.mon should now work together<br>
<br>
Modified: grass/trunk/gui/wxpython/core/render.py<br>
===================================================================<br>
--- grass/trunk/gui/wxpython/core/render.py 2014-05-20 14:55:52 UTC (rev 60375)<br>
+++ grass/trunk/gui/wxpython/core/render.py 2014-05-20 15:14:42 UTC (rev 60376)<br>
@@ -86,10 +86,11 @@<br>
self.renderMgr = None<br>
<br>
self.Map = Map<br>
- self.type = None<br>
+ self.type = None<br>
self.SetType(ltype)<br>
- <a href="http://self.name" target="_blank">self.name</a> = name<br>
-<br>
+ <a href="http://self.name" target="_blank">self.name</a> = name<br>
+ self.environ = os.environ.copy()<br>
+<br>
if self.type == 'command':<br>
self.cmd = list()<br>
for c in cmd:<br>
@@ -136,7 +137,7 @@<br>
{'type' : self.type, 'name' : <a href="http://self.name" target="_blank">self.name</a>})<br>
<br>
if self.mapfile:<br>
- os.environ["GRASS_PNGFILE"] = self.mapfile<br>
+ self.environ["GRASS_PNGFILE"] = self.mapfile<br>
<br>
# execute command<br>
try:<br>
@@ -147,9 +148,9 @@<br>
if ret != 0:<br>
break<br>
if not read:<br>
- os.environ["GRASS_PNG_READ"] = "TRUE"<br>
+ self.environ["GRASS_PNG_READ"] = "TRUE"<br>
<br>
- os.environ["GRASS_PNG_READ"] = "FALSE"<br>
+ self.environ["GRASS_PNG_READ"] = "FALSE"<br>
else:<br>
ret, msg = self._runCommand(self.cmd)<br>
if ret != 0:<br>
@@ -165,11 +166,7 @@<br>
continue<br>
grass.try_remove(f)<br>
f = None<br>
-<br>
- # stop monitor<br>
- if self.mapfile and "GRASS_PNGFILE" in os.environ:<br>
- del os.environ["GRASS_PNGFILE"]<br>
-<br>
+<br>
self.forceRender = False<br>
<br>
return self.mapfile<br>
@@ -180,11 +177,12 @@<br>
if self.type == 'wms':<br>
ret = 0<br>
msg = ''<br>
- self.renderMgr.Render(cmd)<br>
+ self.renderMgr.Render(cmd, env=self.environ)<br>
else:<br>
ret, msg = RunCommand(cmd[0],<br>
getErrorMsg = True,<br>
quiet = True,<br>
+ env=self.environ,<br>
**cmd[1])<br>
<br>
return ret, msg<br>
@@ -301,6 +299,10 @@<br>
# for re-rendering<br>
self.forceRender = True<br>
<br>
+ def SetEnvironment(self, environ):<br>
+ """!Sets environment for rendering."""<br>
+ self.environ = environ<br>
+<br>
def IsDownloading(self):<br>
"""!Is data downloading from web server e. g. wms"""<br>
if self.renderMgr is None:<br>
@@ -385,10 +387,7 @@<br>
<br>
self.overlays = list() # stack of available overlays<br>
self.ovlookup = dict() # lookup dictionary for overlay items and overlays<br>
-<br>
- # environment settings<br>
- self.env = dict()<br>
-<br>
+<br>
# path to external gisrc<br>
self.gisrc = gisrc<br>
<br>
@@ -396,7 +395,6 @@<br>
self.mapfile = grass.tempfile(create = False) + '.ppm'<br>
<br>
# setting some initial env. variables<br>
- self._initGisEnv() # g.gisenv<br>
if not self.GetWindow():<br>
sys.stderr.write(_("Trying to recover from default region..."))<br>
RunCommand('g.region', flags='d')<br>
@@ -405,16 +403,12 @@<br>
self.progressInfo = None<br>
<br>
# GRASS environment variable (for rendering)<br>
- self.env = {"GRASS_BACKGROUNDCOLOR" : "000000",<br>
- "GRASS_PNG_COMPRESSION" : "0",<br>
- "GRASS_TRUECOLOR" : "TRUE",<br>
- "GRASS_TRANSPARENT" : "TRUE",<br>
- "GRASS_PNG_READ" : "FALSE",<br>
- }<br>
+ self.default_env = {"GRASS_BACKGROUNDCOLOR" : "000000",<br>
+ "GRASS_PNG_COMPRESSION" : "0",<br>
+ "GRASS_TRUECOLOR" : "TRUE",<br>
+ "GRASS_TRANSPARENT" : "TRUE"<br>
+ }<br>
<br>
- for k, v in self.env.iteritems():<br>
- os.environ[k] = v<br>
-<br>
# projection info<br>
self.projinfo = self._projInfo()<br>
<br>
@@ -424,30 +418,6 @@<br>
self.layerChanged = Signal('Map.layerChanged')<br>
self.updateProgress = Signal('Map.updateProgress')<br>
<br>
- def _runCommand(self, cmd, **kwargs):<br>
- """!Run command in environment defined by self.gisrc if<br>
- defined"""<br>
- # use external gisrc if defined<br>
- gisrc_orig = os.getenv("GISRC")<br>
- if self.gisrc:<br>
- os.environ["GISRC"] = self.gisrc<br>
-<br>
- ret = cmd(**kwargs)<br>
-<br>
- # back to original gisrc<br>
- if self.gisrc:<br>
- os.environ["GISRC"] = gisrc_orig<br>
-<br>
- return ret<br>
-<br>
- def _initGisEnv(self):<br>
- """!Stores GRASS variables (g.gisenv) to self.env variable<br>
- """<br>
- if not os.getenv("GISBASE"):<br>
- sys.exit(_("GISBASE not set. You must be in GRASS GIS to run this program."))<br>
-<br>
- self.env = self._runCommand(grass.gisenv)<br>
-<br>
def GetProjInfo(self):<br>
"""!Get projection info"""<br>
return self.projinfo<br>
@@ -459,10 +429,11 @@<br>
if not grass.find_program('g.proj', '--help'):<br>
sys.exit(_("GRASS module '%s' not found. Unable to start map "<br>
"display window.") % 'g.proj')<br>
-<br>
- ret = self._runCommand(RunCommand, prog = 'g.proj',<br>
- read = True, flags = 'p')<br>
-<br>
+ env = os.environ.copy()<br>
+ if self.gisrc:<br>
+ env['GISRC'] = self.gisrc<br>
+ ret = RunCommand(prog='g.proj', read=True, flags='p', env=env)<br>
+<br>
if not ret:<br>
return projinfo<br>
<br>
@@ -482,9 +453,10 @@<br>
def GetWindow(self):<br>
"""!Read WIND file and set up self.wind dictionary"""<br>
# FIXME: duplicated region WIND == g.region (at least some values)<br>
- filename = os.path.join (self.env['GISDBASE'],<br>
- self.env['LOCATION_NAME'],<br>
- self.env['MAPSET'],<br>
+ env = grass.gisenv()<br>
+ filename = os.path.join (env['GISDBASE'],<br>
+ env['LOCATION_NAME'],<br>
+ env['MAPSET'],<br>
"WIND")<br>
try:<br>
windfile = open (filename, "r")<br>
@@ -626,15 +598,10 @@<br>
@see GetCurrentRegion()<br>
"""<br>
region = {}<br>
-<br>
- tmpreg = os.getenv("GRASS_REGION")<br>
- if tmpreg:<br>
- del os.environ["GRASS_REGION"]<br>
-<br>
- # use external gisrc if defined<br>
- gisrc_orig = os.getenv("GISRC")<br>
+<br>
+ env = os.environ.copy()<br>
if self.gisrc:<br>
- os.environ["GISRC"] = self.gisrc<br>
+ env['GISRC'] = self.gisrc<br>
<br>
# do not update & shell style output<br>
cmd = {}<br>
@@ -673,6 +640,7 @@<br>
ret, reg, msg = RunCommand('g.region',<br>
read = True,<br>
getErrorMsg = True,<br>
+ env=env,<br>
**cmd)<br>
<br>
if ret != 0:<br>
@@ -698,15 +666,7 @@<br>
region[key] = float(val)<br>
except ValueError:<br>
region[key] = val<br>
-<br>
- # back to original gisrc<br>
- if self.gisrc:<br>
- os.environ["GISRC"] = gisrc_orig<br>
-<br>
- # restore region<br>
- if tmpreg:<br>
- os.environ["GRASS_REGION"] = tmpreg<br>
-<br>
+<br>
Debug.msg (3, "Map.GetRegion(): %s" % region)<br>
<br>
if update:<br>
@@ -884,7 +844,7 @@<br>
<br>
return selected<br>
<br>
- def _renderLayers(self, force = False, overlaysOnly = False):<br>
+ def _renderLayers(self, env, force = False, overlaysOnly = False):<br>
"""!Render all map layers into files<br>
<br>
@param force True to force rendering<br>
@@ -913,6 +873,7 @@<br>
<br>
# render<br>
if force or layer.forceRender:<br>
+ layer.SetEnvironment(env)<br>
if not layer.Render():<br>
continue<br>
<br>
@@ -935,13 +896,13 @@<br>
<br>
return maps, masks, opacities<br>
<br>
- def GetMapsMasksAndOpacities(self, force, windres):<br>
+ def GetMapsMasksAndOpacities(self, force, windres, env):<br>
"""!<br>
Used by Render function.<br>
<br>
@return maps, masks, opacities<br>
"""<br>
- return self._renderLayers(force)<br>
+ return self._renderLayers(force=force, env=env)<br>
<br>
def Render(self, force = False, windres = False):<br>
"""!Creates final image composite<br>
@@ -955,22 +916,21 @@<br>
@return name of file with rendered image or None<br>
"""<br>
wx.BeginBusyCursor()<br>
+ env = os.environ.copy()<br>
+ env.update(self.default_env)<br>
# use external gisrc if defined<br>
- gisrc_orig = os.getenv("GISRC")<br>
if self.gisrc:<br>
- os.environ["GISRC"] = self.gisrc<br>
-<br>
- tmp_region = os.getenv("GRASS_REGION")<br>
- os.environ["GRASS_REGION"] = self.SetRegion(windres)<br>
- os.environ["GRASS_WIDTH"] = str(self.width)<br>
- os.environ["GRASS_HEIGHT"] = str(self.height)<br>
+ env['GISRC'] = self.gisrc<br>
+ env['GRASS_REGION'] = self.SetRegion(windres)<br>
+ env['GRASS_WIDTH'] = str(self.width)<br>
+ env['GRASS_HEIGHT'] = str(self.height)<br>
driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')<br>
if driver == 'png':<br>
- os.environ["GRASS_RENDER_IMMEDIATE"] = "png"<br>
+ env['GRASS_RENDER_IMMEDIATE'] = 'png'<br>
else:<br>
- os.environ["GRASS_RENDER_IMMEDIATE"] = "cairo"<br>
+ env['GRASS_RENDER_IMMEDIATE'] = 'cairo'<br>
<br>
- maps, masks, opacities = self.GetMapsMasksAndOpacities(force, windres)<br>
+ maps, masks, opacities = self.GetMapsMasksAndOpacities(force, windres, env)<br>
<br>
# ugly hack for MSYS<br>
if sys.platform != 'win32':<br>
@@ -1000,7 +960,8 @@<br>
bgcolor = bgcolor,<br>
width = self.width,<br>
height = self.height,<br>
- output = self.mapfile)<br>
+ output = self.mapfile,<br>
+ env=env)<br>
<br>
if ret != 0:<br>
print >> sys.stderr, _("ERROR: Rendering failed. Details: %s") % msg<br>
@@ -1008,17 +969,7 @@<br>
return None<br>
<br>
Debug.msg (3, "Map.Render() force=%s file=%s" % (force, self.mapfile))<br>
-<br>
- # back to original region<br>
- if tmp_region:<br>
- os.environ["GRASS_REGION"] = tmp_region<br>
- else:<br>
- del os.environ["GRASS_REGION"]<br>
-<br>
- # back to original gisrc<br>
- if self.gisrc:<br>
- os.environ["GISRC"] = gisrc_orig<br>
-<br>
+<br>
wx.EndBusyCursor()<br>
if not maps:<br>
return None<br>
<br>
Modified: grass/trunk/gui/wxpython/core/ws.py<br>
===================================================================<br>
--- grass/trunk/gui/wxpython/core/ws.py 2014-05-20 14:55:52 UTC (rev 60375)<br>
+++ grass/trunk/gui/wxpython/core/ws.py 2014-05-20 15:14:42 UTC (rev 60376)<br>
@@ -16,8 +16,8 @@<br>
<br>
@author Stepan Turek <stepan.turek <a href="http://seznam.cz" target="_blank">seznam.cz</a>> (mentor: Martin Landa)<br>
"""<br>
-import os<br>
import sys<br>
+import copy<br>
<br>
import wx<br>
from wx.lib.newevent import NewEvent<br>
@@ -76,7 +76,7 @@<br>
def __del__(self):<br>
grass.try_remove(self.tempMap)<br>
<br>
- def Render(self, cmd):<br>
+ def Render(self, cmd, env):<br>
"""!If it is needed, download missing WMS data.<br>
<br>
@todo lmgr deletes mapfile and maskfile when order of layers<br>
@@ -85,10 +85,11 @@<br>
if not haveGdal:<br>
return<br>
<br>
- self.dstSize['cols'] = int(os.environ["GRASS_WIDTH"])<br>
- self.dstSize['rows'] = int(os.environ["GRASS_HEIGHT"])<br>
+ env = copy.copy(env)<br>
+ self.dstSize['cols'] = int(env["GRASS_WIDTH"])<br>
+ self.dstSize['rows'] = int(env["GRASS_HEIGHT"])<br>
<br>
- region = self._getRegionDict()<br>
+ region = self._getRegionDict(env)<br>
self._fitAspect(region, self.dstSize)<br>
<br>
self.updateMap = True<br>
@@ -127,23 +128,12 @@<br>
<br>
if Debug.GetLevel() < 3:<br>
cmdList.append('--quiet')<br>
-<br>
- tempPngfile = None<br>
- if "GRASS_PNGFILE" in os.environ:<br>
- tempPngfile = os.environ["GRASS_PNGFILE"]<br>
- os.environ["GRASS_PNGFILE"] = self.tempMap<br>
<br>
- tempRegion = os.environ["GRASS_REGION"]<br>
- os.environ["GRASS_REGION"] = self._createRegionStr(region)<br>
+ env["GRASS_PNGFILE"] = self.tempMap<br>
+ env["GRASS_REGION"] = self._createRegionStr(region)<br>
<br>
- self.thread.RunCmd(cmdList, env = os.environ.copy(), stderr = self.cmdStdErr)<br>
+ self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)<br>
<br>
- os.environ.pop("GRASS_PNGFILE")<br>
- if tempPngfile:<br>
- os.environ["GRASS_PNGFILE"] = tempPngfile<br>
-<br>
- os.environ["GRASS_REGION"] = tempRegion<br>
-<br>
def OnCmdOutput(self, event):<br>
"""!Print cmd output according to debug level.<br>
"""<br>
@@ -181,11 +171,11 @@<br>
<br>
self.dataFetched.emit()<br>
<br>
- def _getRegionDict(self):<br>
+ def _getRegionDict(self, env):<br>
"""!Parse string from GRASS_REGION env variable into dict.<br>
"""<br>
region = {}<br>
- parsedRegion = os.environ["GRASS_REGION"].split(';')<br>
+ parsedRegion = env["GRASS_REGION"].split(';')<br>
for r in parsedRegion:<br>
r = r.split(':')<br>
r[0] = r[0].strip()<br>
<br>
_______________________________________________<br>
grass-commit mailing list<br>
<a href="mailto:grass-commit@lists.osgeo.org">grass-commit@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-commit" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-commit</a><br>
</blockquote></div><br></div></div></div>