[GRASS-SVN] r64687 - in grass/trunk: general/g.gui gui/wxpython/core lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 19 09:49:45 PST 2015


Author: martinl
Date: 2015-02-19 09:49:45 -0800 (Thu, 19 Feb 2015)
New Revision: 64687

Modified:
   grass/trunk/general/g.gui/main.c
   grass/trunk/gui/wxpython/core/render.py
   grass/trunk/lib/init/grass.py
Log:
revert r64686 (wrong commit)


Modified: grass/trunk/general/g.gui/main.c
===================================================================
--- grass/trunk/general/g.gui/main.c	2015-02-19 17:46:41 UTC (rev 64686)
+++ grass/trunk/general/g.gui/main.c	2015-02-19 17:49:45 UTC (rev 64687)
@@ -8,7 +8,7 @@
  *
  * PURPOSE:      Start GRASS GUI from command line.
  *
- * COPYRIGHT:    (C) 2008-2015 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2008-2014 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
@@ -25,7 +25,7 @@
 int main(int argc, char *argv[])
 {
     struct Option *type, *rc_file;
-    struct Flag *update_ui, *nolaunch;
+    struct Flag *update, *nolaunch;
     struct GModule *module;
     const char *gui_type_env;
     char progname[GPATH_MAX];
@@ -45,16 +45,15 @@
     type = G_define_option();
     type->key = "ui";
     type->type = TYPE_STRING;
-    type->description = _("User interface");
+    type->label = _("User interface");
+    type->description = _("Default value: GRASS_GUI if defined otherwise wxpython");
     desc = NULL;
     G_asprintf(&desc,
-               "wxpython;%s;text;%s;gtext;%s;",
-               _("wxPython based GUI (wxGUI)"),
-               _("command line interface only"),
-               _("command line interface with GUI startup screen"));
+	        "wxpython;%s;text;%s",
+	        _("wxPython based GUI (wxGUI)"),
+	        _("command line interface only"));
     type->descriptions = desc;
-    type->options = "wxpython,text,gtext";
-    type->answer = "wxpython";
+    type->options = "wxpython,text";
     type->guisection = _("Type");
     
     rc_file = G_define_standard_option(G_OPT_F_INPUT);
@@ -63,10 +62,10 @@
     rc_file->key_desc = "name.gxw";
     rc_file->description = _("Name of workspace file to load on start-up (valid only for wxGUI)");
 
-    update_ui = G_define_flag();
-    update_ui->key = 'd';
-    update_ui->description = _("Update default user interface settings");
-    update_ui->guisection = _("Default");
+    update = G_define_flag();
+    update->key = 'd';
+    update->description = _("Update default user interface settings");
+    update->guisection = _("Default");
 
     nolaunch = G_define_flag();
     nolaunch->key = 'n';
@@ -77,34 +76,58 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+
+    if (type->answer && strcmp(type->answer, "text") == 0 &&
+	!nolaunch->answer)
+	nolaunch->answer = TRUE;
+    
+    if (nolaunch->answer && !update->answer)
+	update->answer = TRUE;
+    
     gui_type_env = G_getenv_nofatal("GUI");
-    G_debug(1, "GUI: %s", gui_type_env ? gui_type_env : "unset");
-    if (update_ui->answer) {
-        if (!gui_type_env || strcmp(type->answer, gui_type_env)) {
-            G_setenv("GUI", type->answer);
-            G_message(_("<%s> is now the default GUI"), type->answer);
-        }
+
+    if (!type->answer) {
+	if (gui_type_env && strcmp(gui_type_env, "text")) {
+	    type->answer = G_store(gui_type_env);
+	}
+	else {
+	    type->answer = "wxpython";
+	}
     }
 
-    if(strcmp(type->answer, "wxpython") != 0 || nolaunch->answer)
-        if (!update_ui->answer)
-            G_warning(_("Nothing to do. For setting up <%s> as default UI use -%c flag."),
-                      type->answer, update_ui->key);
+    if (((gui_type_env && update->answer) &&
+	 strcmp(gui_type_env, type->answer) != 0) || !gui_type_env) {
+	G_setenv("GUI", type->answer);
+	G_message(_("<%s> is now the default GUI"), type->answer);
+    }
+    else {
+	if(update->answer)
+	    if(gui_type_env) {
+		G_debug(1, "No change: old gui_type_env=[%s], new type->ans=[%s]",
+			gui_type_env, type->answer);
+	    }
+    }
+
+    if(nolaunch->answer)
 	exit(EXIT_SUCCESS);
 
+
     G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);
-    sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
-    if (rc_file->answer) {
-        G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                   "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
+
+    if (strcmp(type->answer, "wxpython") == 0) {
+	sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
+	if (rc_file->answer) {
+	    G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
+		    "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
+	}
+	else {
+	    G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
+		    SF_BACKGROUND, NULL);
+	}
     }
-    else {
-        G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                   SF_BACKGROUND, NULL);
-    }
-    
+
     /* stop the impatient from starting it again
-       before the splash screen comes up */
+        before the splash screen comes up */
     G_sleep(3);
 
     exit(EXIT_SUCCESS);

Modified: grass/trunk/gui/wxpython/core/render.py
===================================================================
--- grass/trunk/gui/wxpython/core/render.py	2015-02-19 17:46:41 UTC (rev 64686)
+++ grass/trunk/gui/wxpython/core/render.py	2015-02-19 17:49:45 UTC (rev 64687)
@@ -17,7 +17,7 @@
  - render::Overlay
  - render::Map
 
-(C) 2006-2015 by the GRASS Development Team
+(C) 2006-2014 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -156,24 +156,29 @@
             if self.type == 'command':
                 read = False
                 for c in self.cmd:
-                    self._runCommand(c)
+                    ret, msg = self._runCommand(c)
+                    if ret != 0:
+                        break
                     if not read:
                         self.environ["GRASS_RENDER_FILE_READ"] = "TRUE"
 
                 self.environ["GRASS_RENDER_FILE_READ"] = "FALSE"
             else:
-                self._runCommand(self.cmd)
-        except GException as e:
-            sys.stderr.write(_("Command '%s' failed\n") % self.GetCmd(string = True))
-            sys.stderr.write(_("Details: %s\n") % e)
-            
+                ret, msg = self._runCommand(self.cmd)
+            if ret != 0:
+                sys.stderr.write(_("Command '%s' failed\n") % self.GetCmd(string = True))
+                if msg:
+                    sys.stderr.write(_("Details: %s\n") % msg)
+                raise GException()
+
+        except GException:
             # clean up after problems
             for f in [self.mapfile, self.maskfile]:
                 if not f:
                     continue
                 try_remove(f)
                 f = None
-        
+
         self.forceRender = False
 
         return self.mapfile
@@ -181,8 +186,19 @@
     def _runCommand(self, cmd):
         """Run command to render data
         """
-        self.renderMgr.Render(cmd, env=self.environ)
+        if self.type == 'wms':
+            ret = 0
+            msg = ''
+            self.renderMgr.Render(cmd, env=self.environ)
+        else:
+            ret, msg = RunCommand(cmd[0],
+                                  getErrorMsg = True,
+                                  quiet = True,
+                                  env=self.environ,
+                                  **cmd[1])
 
+        return ret, msg
+
     def GetCmd(self, string = False):
         """Get GRASS command as list of string.
 
@@ -259,16 +275,13 @@
         if ltype not in utils.command2ltype.values() + ['overlay', 'command']:
             raise GException(_("Unsupported map layer type '%s'") % ltype)
 
-        if not self.renderMgr:
-            if ltype == 'wms':
-                renderMgr = RenderWMSMgr
-            else:
-                renderMgr = RenderMgr
-                
-            self.renderMgr = renderMgr(layer=self,
-                                       mapfile=self.mapfile,
-                                       maskfile=self.maskfile)
-        
+        if ltype == 'wms' and not isinstance(self.renderMgr, RenderWMSMgr):
+            self.renderMgr = RenderWMSMgr(layer=self,
+                                          mapfile=self.mapfile,
+                                          maskfile=self.maskfile)
+        elif self.type == 'wms' and ltype != 'wms':
+            self.renderMgr = None
+
         self.type = ltype
 
     def SetName(self, name):
@@ -1389,21 +1402,3 @@
         self.updateProgress.emit(range=self.progressInfo['range'],
                                  value=self.progressInfo['progresVal'],
                                  text=stText)
-
-class RenderMgr(wx.EvtHandler):
-    def __init__(self, layer, mapfile, maskfile):
-         self.layer = layer
-         
-         wx.EvtHandler.__init__(self)
-         self.thread = CmdThread(self)
-         self.cmdStdErr = GStderr(self)
-         
-         self.mapfile = mapfile
-         self.maskfile = maskfile
-
-    def Render(self, cmd, env):
-        self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)
-
-    def Abort(self):
-        self.updateMap = False
-        self.thread.abort(abortall = True)        

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2015-02-19 17:46:41 UTC (rev 64686)
+++ grass/trunk/lib/init/grass.py	2015-02-19 17:49:45 UTC (rev 64687)
@@ -907,11 +907,10 @@
             sh = os.path.basename(os.getenv('SHELL'))
         except:
             sh = 'sh'
-            os.environ['SHELL'] = sh
-        
+            os.environ['SHELL'] = "sh" 
         if windows and sh:
             sh = os.path.splitext(sh)[0]
-        
+
         if sh == "ksh":
             shellname = "Korn Shell"
         elif sh == "csh":



More information about the grass-commit mailing list