[GRASS-SVN] r65300 - grass/trunk/display/d.mon
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu May 21 10:39:23 PDT 2015
Author: martinl
Date: 2015-05-21 10:39:23 -0700 (Thu, 21 May 2015)
New Revision: 65300
Modified:
grass/trunk/display/d.mon/render_cmd.py
grass/trunk/display/d.mon/start.c
Log:
d.mon: avoid doubled rendering for standalone wx monitors
Modified: grass/trunk/display/d.mon/render_cmd.py
===================================================================
--- grass/trunk/display/d.mon/render_cmd.py 2015-05-21 16:34:20 UTC (rev 65299)
+++ grass/trunk/display/d.mon/render_cmd.py 2015-05-21 17:39:23 UTC (rev 65300)
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
import sys
+import tempfile
from grass.script import core as grass
from grass.script import task as gtask
@@ -29,14 +30,16 @@
return width, height
# run display command
-def render(cmd):
+def render(cmd, mapfile):
+ env = os.environ.copy()
+ env['GRASS_RENDER_FILE'] = mapfile
try:
- grass.run_command(cmd[0], **cmd[1])
+ grass.run_command(cmd[0], env=env, **cmd[1])
except Exception as e:
grass.fatal("Unable to render: {}".format(e))
# update cmd file
-def update_cmd_file(cmd_file, cmd):
+def update_cmd_file(cmd_file, cmd, mapfile):
if cmd[0] in ('d.colorlist', 'd.font', 'd.fontlist',
'd.frame', 'd.info', 'd.mon', 'd.out.file',
'd.redraw', 'd.to.rast', 'd.what.rast',
@@ -49,6 +52,7 @@
if fd is None:
grass.fatal("Unable to open file '{}'".format(cmd_file))
if mode == 'a':
+ fd.write('# GRASS_RENDER_FILE={}\n'.format(mapfile))
fd.write(' '.join(gtask.cmdtuple_to_list(cmd)))
fd.write('\n')
else:
@@ -95,8 +99,9 @@
width, height = read_env_file(os.path.join(path, 'env'))
if not mon.startswith('wx'):
adjust_region(width, height)
-
- render(cmd)
- update_cmd_file(os.path.join(path, 'cmd'), cmd)
+
+ mapfile = tempfile.NamedTemporaryFile(dir=path).name + '.ppm'
+ render(cmd, mapfile)
+ update_cmd_file(os.path.join(path, 'cmd'), cmd, mapfile)
sys.exit(0)
Modified: grass/trunk/display/d.mon/start.c
===================================================================
--- grass/trunk/display/d.mon/start.c 2015-05-21 16:34:20 UTC (rev 65299)
+++ grass/trunk/display/d.mon/start.c 2015-05-21 17:39:23 UTC (rev 65300)
@@ -153,16 +153,23 @@
if (fd < 0)
G_fatal_error(_("Unable to create file <%s>"), env_file);
- if (G_strncasecmp(name, "wx", 2) == 0)
+ if (G_strncasecmp(name, "wx", 2) == 0) {
sprintf(buf, "GRASS_RENDER_IMMEDIATE=default\n"); /* TODO: read settings from wxGUI */
- else
+ write(fd, buf, strlen(buf));
+ sprintf(buf, "GRASS_RENDER_FILE_READ=FALSE\n");
+ write(fd, buf, strlen(buf));
+ sprintf(buf, "GRASS_RENDER_TRANSPARENT=TRUE\n");
+ write(fd, buf, strlen(buf));
+ }
+ else {
sprintf(buf, "GRASS_RENDER_IMMEDIATE=%s\n", name);
-
- write(fd, buf, strlen(buf));
+ write(fd, buf, strlen(buf));
+ sprintf(buf, "GRASS_RENDER_FILE_READ=TRUE\n");
+ write(fd, buf, strlen(buf));
+
+ }
sprintf(buf, "GRASS_RENDER_FILE=%s\n", out_file);
write(fd, buf, strlen(buf));
- sprintf(buf, "GRASS_RENDER_FILE_READ=TRUE\n");
- write(fd, buf, strlen(buf));
sprintf(buf, "GRASS_RENDER_WIDTH=%d\n", width);
write(fd, buf, strlen(buf));
sprintf(buf, "GRASS_RENDER_HEIGHT=%d\n", height);
More information about the grass-commit
mailing list