| 1 |
|
|---|
| 2 | /****************************************************************************
|
|---|
| 3 | *
|
|---|
| 4 | * MODULE: g.gui
|
|---|
| 5 | *
|
|---|
| 6 | * AUTHOR(S): Martin Landa <landa.martin gmail.com>
|
|---|
| 7 | * Hamish Bowman <hamish_b yahoo com> (fine tuning)
|
|---|
| 8 | *
|
|---|
| 9 | * PURPOSE: Start GRASS GUI from command line.
|
|---|
| 10 | *
|
|---|
| 11 | * COPYRIGHT: (C) 2008-2015 by the GRASS Development Team
|
|---|
| 12 | *
|
|---|
| 13 | * This program is free software under the GNU General Public
|
|---|
| 14 | * License (>=v2). Read the file COPYING that comes with GRASS
|
|---|
| 15 | * for details.
|
|---|
| 16 | *
|
|---|
| 17 | *****************************************************************************/
|
|---|
| 18 |
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 | #include <unistd.h>
|
|---|
| 22 |
|
|---|
| 23 | #include <grass/gis.h>
|
|---|
| 24 | #include <grass/glocale.h>
|
|---|
| 25 | #include <grass/spawn.h>
|
|---|
| 26 |
|
|---|
| 27 | int main(int argc, char *argv[])
|
|---|
| 28 | {
|
|---|
| 29 | struct Option *type, *rc_file;
|
|---|
| 30 | struct Flag *update_ui, *fglaunch, *nolaunch;
|
|---|
| 31 | struct GModule *module;
|
|---|
| 32 | const char *gui_type_env;
|
|---|
| 33 | char progname[GPATH_MAX];
|
|---|
| 34 | char *desc;
|
|---|
| 35 |
|
|---|
| 36 | G_gisinit(argv[0]);
|
|---|
| 37 |
|
|---|
| 38 | module = G_define_module();
|
|---|
| 39 | G_add_keyword(_("general"));
|
|---|
| 40 | G_add_keyword(_("GUI"));
|
|---|
| 41 | G_add_keyword(_("user interface"));
|
|---|
| 42 |
|
|---|
| 43 | module->label =
|
|---|
| 44 | _("Launches a GRASS graphical user interface (GUI) session.");
|
|---|
| 45 | module->description = _("Optionally updates default user interface settings.");
|
|---|
| 46 |
|
|---|
| 47 | type = G_define_option();
|
|---|
| 48 | type->key = "ui";
|
|---|
| 49 | type->type = TYPE_STRING;
|
|---|
| 50 | type->description = _("User interface");
|
|---|
| 51 | desc = NULL;
|
|---|
| 52 | G_asprintf(&desc,
|
|---|
| 53 | "wxpython;%s;text;%s;gtext;%s;",
|
|---|
| 54 | _("wxPython based GUI (wxGUI)"),
|
|---|
| 55 | _("command line interface only"),
|
|---|
| 56 | _("command line interface with GUI startup screen"));
|
|---|
| 57 | type->descriptions = desc;
|
|---|
| 58 | type->options = "wxpython,text,gtext";
|
|---|
| 59 | type->answer = "wxpython";
|
|---|
| 60 | type->guisection = _("Type");
|
|---|
| 61 |
|
|---|
| 62 | rc_file = G_define_standard_option(G_OPT_F_INPUT);
|
|---|
| 63 | rc_file->key = "workspace";
|
|---|
| 64 | rc_file->required = NO;
|
|---|
| 65 | rc_file->key_desc = "name.gxw";
|
|---|
| 66 | rc_file->label = _("Name of workspace file to load on start-up");
|
|---|
| 67 | rc_file->description = _("This is valid only for wxGUI (wxpython)");
|
|---|
| 68 |
|
|---|
| 69 | fglaunch = G_define_flag();
|
|---|
| 70 | fglaunch->key = 'f';
|
|---|
| 71 | fglaunch->label = _("Start GUI in the foreground");
|
|---|
| 72 | fglaunch->description = _("By default the GUI starts in the background"
|
|---|
| 73 | " and control is immediately returned to the caller."
|
|---|
| 74 | " When GUI runs in foregreound, it blocks the command line");
|
|---|
| 75 |
|
|---|
| 76 | update_ui = G_define_flag();
|
|---|
| 77 | update_ui->key = 'd';
|
|---|
| 78 | update_ui->description = _("Update default user interface settings");
|
|---|
| 79 | update_ui->guisection = _("Default");
|
|---|
| 80 |
|
|---|
| 81 | nolaunch = G_define_flag();
|
|---|
| 82 | nolaunch->key = 'n';
|
|---|
| 83 | nolaunch->description =
|
|---|
| 84 | _("Do not launch GUI after updating the default user interface settings");
|
|---|
| 85 | nolaunch->guisection = _("Default");
|
|---|
| 86 |
|
|---|
| 87 | if (G_parser(argc, argv))
|
|---|
| 88 | exit(EXIT_FAILURE);
|
|---|
| 89 |
|
|---|
| 90 | gui_type_env = G_getenv_nofatal("GUI");
|
|---|
| 91 | G_debug(1, "GUI: %s", gui_type_env ? gui_type_env : "unset");
|
|---|
| 92 | if (update_ui->answer) {
|
|---|
| 93 | if (!gui_type_env || strcmp(type->answer, gui_type_env)) {
|
|---|
| 94 | G_setenv("GUI", type->answer);
|
|---|
| 95 | G_message(_("<%s> is now the default GUI"), type->answer);
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | if(strcmp(type->answer, "wxpython") != 0 || nolaunch->answer) {
|
|---|
| 100 | if (!update_ui->answer)
|
|---|
| 101 | G_warning(_("Nothing to do. For setting up <%s> as default UI use -%c flag."),
|
|---|
| 102 | type->answer, update_ui->key);
|
|---|
| 103 | exit(EXIT_SUCCESS);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
|
|---|
| 107 | if (access(progname, F_OK) == -1)
|
|---|
| 108 | G_fatal_error(_("Your installation doesn't include GUI, exiting."));
|
|---|
| 109 |
|
|---|
| 110 | if (fglaunch->answer) {
|
|---|
| 111 | G_message(_("Launching <%s> GUI, please wait..."), type->answer);
|
|---|
| 112 | if (rc_file->answer) {
|
|---|
| 113 | G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
|
|---|
| 114 | "--workspace", rc_file->answer, NULL);
|
|---|
| 115 | }
|
|---|
| 116 | else {
|
|---|
| 117 | G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
|
|---|
| 118 | NULL);
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 | else {
|
|---|
| 122 | G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);
|
|---|
| 123 | if (rc_file->answer) {
|
|---|
| 124 | G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
|
|---|
| 125 | "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
|
|---|
| 126 | }
|
|---|
| 127 | else {
|
|---|
| 128 | G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
|
|---|
| 129 | SF_BACKGROUND, NULL);
|
|---|
| 130 | }
|
|---|
| 131 | /* stop the impatient from starting it again
|
|---|
| 132 | before the splash screen comes up */
|
|---|
| 133 | G_sleep(3);
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | exit(EXIT_SUCCESS);
|
|---|
| 137 | }
|
|---|