main.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /****************************************************************************
  2. *
  3. * MODULE: g.gui
  4. *
  5. * AUTHOR(S): Martin Landa <landa.martin gmail.com>
  6. * Hamish Bowman <hamish_b yahoo com> (fine tuning)
  7. *
  8. * PURPOSE: Start GRASS GUI from command line.
  9. *
  10. * COPYRIGHT: (C) 2008 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. *****************************************************************************/
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. #include <grass/spawn.h>
  22. int main(int argc, char *argv[])
  23. {
  24. struct Option *type, *rc_file;
  25. struct Flag *oneoff;
  26. struct GModule *module;
  27. char *gui_type_env;
  28. char progname[GPATH_MAX];
  29. G_gisinit(argv[0]);
  30. module = G_define_module();
  31. module->keywords = _("general, gui");
  32. module->description =
  33. _("Launches a GRASS graphical user interface (GUI) session.");
  34. type = G_define_option();
  35. type->key = "gui";
  36. type->type = TYPE_STRING;
  37. type->label = _("GUI type");
  38. type->description = _("Default value: GRASS_GUI if defined otherwise wxpython");
  39. type->descriptions = _("wxpython;wxPython based GUI");
  40. type->options = "wxpython";
  41. rc_file = G_define_standard_option(G_OPT_F_INPUT);
  42. rc_file->key = "workspace";
  43. rc_file->required = NO;
  44. rc_file->description = _("Name of workspace file");
  45. oneoff = G_define_flag();
  46. oneoff->key = 'u';
  47. oneoff->description = _("Update default GUI setting");
  48. if (G_parser(argc, argv))
  49. exit(EXIT_FAILURE);
  50. gui_type_env = G__getenv("GRASS_GUI");
  51. if (!type->answer) {
  52. if (gui_type_env && strcmp(gui_type_env, "text")) {
  53. type->answer = G_store(gui_type_env);
  54. }
  55. else {
  56. type->answer = "wxpython";
  57. }
  58. }
  59. if (((gui_type_env && oneoff->answer) &&
  60. strcmp(gui_type_env, type->answer) != 0) || !gui_type_env) {
  61. G_message(_("<%s> is now the default GUI"), type->answer);
  62. G_setenv("GRASS_GUI", type->answer);
  63. }
  64. if (strcmp(type->answer, "wxpython") == 0) {
  65. sprintf(progname, "%s/etc/wxpython/wxgui.py", G_gisbase());
  66. if (rc_file->answer) {
  67. G_spawn("python", "wxgui", progname, "--workspace",
  68. rc_file->answer, NULL);
  69. }
  70. else {
  71. G_spawn("python", "wxgui", progname, NULL);
  72. }
  73. }
  74. exit(EXIT_SUCCESS);
  75. }