[GRASS-SVN] r47041 - grass/trunk/display/d.mon
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 7 05:04:54 EDT 2011
Author: martinl
Date: 2011-07-07 02:04:54 -0700 (Thu, 07 Jul 2011)
New Revision: 47041
Modified:
grass/trunk/display/d.mon/main.c
grass/trunk/display/d.mon/proto.h
grass/trunk/display/d.mon/start.c
Log:
d.mon: add new options: 'width', 'height' and 'bgcolor'
Modified: grass/trunk/display/d.mon/main.c
===================================================================
--- grass/trunk/display/d.mon/main.c 2011-07-07 08:56:17 UTC (rev 47040)
+++ grass/trunk/display/d.mon/main.c 2011-07-07 09:04:54 UTC (rev 47041)
@@ -23,7 +23,8 @@
int main(int argc, char *argv[])
{
struct GModule *module;
- struct Option *start_opt, *select_opt, *stop_opt, *output_opt;
+ struct Option *start_opt, *select_opt, *stop_opt, *output_opt,
+ *width_opt, *height_opt, *bgcolor_opt;
struct Flag *list_flag, *selected_flag, *select_flag, *release_flag;
int nopts, ret;
@@ -35,7 +36,8 @@
G_add_keyword(_("display"));
G_add_keyword(_("graphics"));
G_add_keyword(_("monitors"));
- module->description = _("Controls graphics monitors.");
+ G_add_keyword(_("CLI"));
+ module->description = _("Controls graphics display monitors which can be controlled from the command line.");
start_opt = G_define_option();
start_opt->key = "start";
@@ -58,11 +60,29 @@
select_opt->options = "wx0,wx1,wx2,wx3,wx4,wx5,wx6,wx7,png,ps,html,cairo";
select_opt->guisection = _("Manage");
+ width_opt = G_define_option();
+ width_opt->key = "width";
+ width_opt->description = _("Width for display monitor if not set by GRASS_WIDTH");
+ width_opt->type = TYPE_INTEGER;
+ width_opt->key_desc = "value";
+ width_opt->guisection = _("Settings");
+
+ height_opt = G_define_option();
+ height_opt->key = "height";
+ height_opt->description = _("Height for display monitor if not set by GRASS_HEIGHT");
+ height_opt->type = TYPE_INTEGER;
+ height_opt->key_desc = "value";
+ height_opt->guisection = _("Settings");
+
+ bgcolor_opt = G_define_standard_option(G_OPT_C_BG);
+ bgcolor_opt->guisection = _("Settings");
+
output_opt = G_define_standard_option(G_OPT_F_OUTPUT);
output_opt->required = NO;
output_opt->label = _("Name for output file (when starting new monitor)");
output_opt->description = _("Ignored for 'wx' monitors");
-
+ output_opt->guisection = _("Settings");
+
list_flag = G_define_flag();
list_flag->key = 'l';
list_flag->description = _("List running monitors and exit");
@@ -91,11 +111,14 @@
G_warning(_("Flag -%c ignored"), list_flag->key);
mon = G__getenv("MONITOR");
if (selected_flag->answer) {
- if (mon)
+ if (mon) {
+ G_message(_("Currently selected monitor:"));
fprintf(stdout, "%s\n", mon);
+ }
}
- else {
+ else if (mon) {
G_unsetenv("MONITOR");
+ G_verbose_message(_("Monitor <%s> released"), mon);
}
if (!mon)
G_important_message(_("No monitor selected"));
@@ -125,7 +148,8 @@
G_warning(_("Option <%s> ignored"), output_opt->key);
if (start_opt->answer)
- ret = start_mon(start_opt->answer, output_opt->answer, !select_flag->answer);
+ ret = start_mon(start_opt->answer, output_opt->answer, !select_flag->answer,
+ width_opt->answer, height_opt->answer, bgcolor_opt->answer);
if (stop_opt->answer)
ret = stop_mon(stop_opt->answer);
Modified: grass/trunk/display/d.mon/proto.h
===================================================================
--- grass/trunk/display/d.mon/proto.h 2011-07-07 08:56:17 UTC (rev 47040)
+++ grass/trunk/display/d.mon/proto.h 2011-07-07 09:04:54 UTC (rev 47041)
@@ -1,5 +1,5 @@
/* start */
-int start_mon(const char *, const char *, int);
+int start_mon(const char *, const char *, int, const char *, const char *, const char *);
/* select.c */
int select_mon(const char *);
Modified: grass/trunk/display/d.mon/start.c
===================================================================
--- grass/trunk/display/d.mon/start.c 2011-07-07 08:56:17 UTC (rev 47040)
+++ grass/trunk/display/d.mon/start.c 2011-07-07 09:04:54 UTC (rev 47041)
@@ -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;
+ char *env_name;
+
+ if (!output)
+ return;
- tempfile = G_tempfile();
-
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 @@
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);
More information about the grass-commit
mailing list