|
@@ -7,38 +7,30 @@
|
|
|
#include "proto.h"
|
|
|
|
|
|
static void start(const char *, const char *);
|
|
|
-static void start_wx(const char *);
|
|
|
+static void start_wx(const char *, const char *, const char *,
|
|
|
+ const char *, const char *);
|
|
|
|
|
|
+/* start file-based monitor */
|
|
|
void start(const char *name, const char *output)
|
|
|
{
|
|
|
- char *tempfile;
|
|
|
- char *env_name, *env_value;
|
|
|
-
|
|
|
- tempfile = G_tempfile();
|
|
|
+ char *env_name;
|
|
|
|
|
|
+ if (!output)
|
|
|
+ return;
|
|
|
+
|
|
|
env_name = NULL;
|
|
|
- G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
|
|
|
- G_asprintf(&env_value, "%s.env", tempfile);
|
|
|
- G_setenv(env_name, env_value);
|
|
|
- close(creat(env_value, 0666));
|
|
|
-
|
|
|
G_asprintf(&env_name, "MONITOR_%s_MAPFILE", name);
|
|
|
G_setenv(env_name, output);
|
|
|
}
|
|
|
|
|
|
-void start_wx(const char *name)
|
|
|
+/* start wxGUI display monitor */
|
|
|
+void start_wx(const char *name, const char *tempfile, const char *env_value,
|
|
|
+ const char *width, const char *height)
|
|
|
{
|
|
|
char progname[GPATH_MAX];
|
|
|
- char *tempfile;
|
|
|
- char *env_name, *map_value, *cmd_value, *env_value;
|
|
|
-
|
|
|
- tempfile = G_tempfile();
|
|
|
+ char *env_name, *map_value, *cmd_value;
|
|
|
|
|
|
- G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
|
|
|
- G_asprintf(&env_value, "%s.env", tempfile);
|
|
|
- G_setenv(env_name, env_value);
|
|
|
- close(creat(env_value, 0666));
|
|
|
-
|
|
|
+ env_name = NULL;
|
|
|
G_asprintf(&env_name, "MONITOR_%s_CMDFILE", name);
|
|
|
G_asprintf(&cmd_value, "%s.cmd", tempfile);
|
|
|
G_setenv(env_name, cmd_value);
|
|
@@ -49,29 +41,62 @@ void start_wx(const char *name)
|
|
|
G_setenv(env_name, map_value);
|
|
|
/* close(creat(map_value, 0666)); */
|
|
|
|
|
|
- G_debug(1, "start: name=%s ", name);
|
|
|
- G_debug(1, " cmdfile = %s", cmd_value);
|
|
|
- G_debug(1, " mapfile = %s", map_value);
|
|
|
- G_debug(1, " envfile = %s", env_value);
|
|
|
+ G_debug(3, " cmdfile = %s", cmd_value);
|
|
|
+ G_debug(3, " mapfile = %s", map_value);
|
|
|
|
|
|
sprintf(progname, "%s/etc/gui/wxpython/gui_modules/mapdisp.py", G_gisbase());
|
|
|
G_spawn_ex(getenv("GRASS_PYTHON"), progname, progname,
|
|
|
- name, map_value, cmd_value, env_value, SF_BACKGROUND, NULL);
|
|
|
+ name, map_value, cmd_value, env_value, width ? width : "", height ? height : "", SF_BACKGROUND, NULL);
|
|
|
}
|
|
|
|
|
|
-int start_mon(const char *name, const char *output, int select)
|
|
|
+int start_mon(const char *name, const char *output, int select,
|
|
|
+ const char *width, const char *height, const char *bgcolor)
|
|
|
{
|
|
|
const char *curr_mon;
|
|
|
-
|
|
|
+ char *env_name, *env_value;
|
|
|
+ char *tempfile, buf[1024];
|
|
|
+ int env_fd;
|
|
|
+
|
|
|
curr_mon = G__getenv("MONITOR");
|
|
|
if (curr_mon && strcmp(curr_mon, name) == 0 && check_mon(curr_mon))
|
|
|
G_fatal_error(_("Monitor <%s> already running"), name);
|
|
|
|
|
|
+ tempfile = G_tempfile();
|
|
|
+
|
|
|
+ env_name = env_value = NULL;
|
|
|
+ G_asprintf(&env_name, "MONITOR_%s_ENVFILE", name);
|
|
|
+ G_asprintf(&env_value, "%s.env", tempfile);
|
|
|
+ G_setenv(env_name, env_value);
|
|
|
+ env_fd = creat(env_value, 0666);
|
|
|
+ if (env_fd < 0)
|
|
|
+ G_fatal_error(_("Unable to create file '%s'"), env_value);
|
|
|
+ if (width) {
|
|
|
+ sprintf(buf, "GRASS_WIDTH=%s\n", width);
|
|
|
+ write(env_fd, buf, strlen(buf));
|
|
|
+ }
|
|
|
+ if (height) {
|
|
|
+ sprintf(buf, "GRASS_HEIGHT=%s\n", height);
|
|
|
+ write(env_fd, buf, strlen(buf));
|
|
|
+ }
|
|
|
+ if (bgcolor) {
|
|
|
+ if (strcmp(bgcolor, "none") == 0)
|
|
|
+ sprintf(buf, "GRASS_TRANSPARENT=TRUE\n");
|
|
|
+ else
|
|
|
+ sprintf(buf, "GRASS_BACKGROUNDCOLOR=%s\n", bgcolor);
|
|
|
+ write(env_fd, buf, strlen(buf));
|
|
|
+ }
|
|
|
+ close(env_fd);
|
|
|
+
|
|
|
+ G_verbose_message(_("Staring monitor <%s> with env file '%s'"), name, env_value);
|
|
|
+
|
|
|
+ G_debug(1, "start: name=%s ", name);
|
|
|
+ G_debug(3, " envfile = %s", env_value);
|
|
|
+
|
|
|
if (select)
|
|
|
G_setenv("MONITOR", name);
|
|
|
|
|
|
if (strncmp(name, "wx", 2) == 0) /* use G_strncasecmp() instead */
|
|
|
- start_wx(name);
|
|
|
+ start_wx(name, tempfile, env_value, width, height);
|
|
|
else
|
|
|
start(name, output);
|
|
|
|