[GRASS-SVN] r64686 - 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:46:41 PST 2015


Author: martinl
Date: 2015-02-19 09:46:41 -0800 (Thu, 19 Feb 2015)
New Revision: 64686

Modified:
   grass/trunk/general/g.gui/main.c
   grass/trunk/gui/wxpython/core/render.py
   grass/trunk/lib/init/grass.py
Log:
grass.py: r64684 cosmetics


Modified: grass/trunk/general/g.gui/main.c
===================================================================
--- grass/trunk/general/g.gui/main.c	2015-02-19 16:56:57 UTC (rev 64685)
+++ grass/trunk/general/g.gui/main.c	2015-02-19 17:46:41 UTC (rev 64686)
@@ -8,7 +8,7 @@
  *
  * PURPOSE:      Start GRASS GUI from command line.
  *
- * COPYRIGHT:    (C) 2008-2014 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2008-2015 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, *nolaunch;
+    struct Flag *update_ui, *nolaunch;
     struct GModule *module;
     const char *gui_type_env;
     char progname[GPATH_MAX];
@@ -45,15 +45,16 @@
     type = G_define_option();
     type->key = "ui";
     type->type = TYPE_STRING;
-    type->label = _("User interface");
-    type->description = _("Default value: GRASS_GUI if defined otherwise wxpython");
+    type->description = _("User interface");
     desc = NULL;
     G_asprintf(&desc,
-	        "wxpython;%s;text;%s",
-	        _("wxPython based GUI (wxGUI)"),
-	        _("command line interface only"));
+               "wxpython;%s;text;%s;gtext;%s;",
+               _("wxPython based GUI (wxGUI)"),
+               _("command line interface only"),
+               _("command line interface with GUI startup screen"));
     type->descriptions = desc;
-    type->options = "wxpython,text";
+    type->options = "wxpython,text,gtext";
+    type->answer = "wxpython";
     type->guisection = _("Type");
     
     rc_file = G_define_standard_option(G_OPT_F_INPUT);
@@ -62,10 +63,10 @@
     rc_file->key_desc = "name.gxw";
     rc_file->description = _("Name of workspace file to load on start-up (valid only for wxGUI)");
 
-    update = G_define_flag();
-    update->key = 'd';
-    update->description = _("Update default user interface settings");
-    update->guisection = _("Default");
+    update_ui = G_define_flag();
+    update_ui->key = 'd';
+    update_ui->description = _("Update default user interface settings");
+    update_ui->guisection = _("Default");
 
     nolaunch = G_define_flag();
     nolaunch->key = 'n';
@@ -76,58 +77,34 @@
     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");
-
-    if (!type->answer) {
-	if (gui_type_env && strcmp(gui_type_env, "text")) {
-	    type->answer = G_store(gui_type_env);
-	}
-	else {
-	    type->answer = "wxpython";
-	}
+    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 (((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)
+    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);
 	exit(EXIT_SUCCESS);
 
-
     G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);
-
-    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);
-	}
+    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);
+    }
+    
     /* 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 16:56:57 UTC (rev 64685)
+++ grass/trunk/gui/wxpython/core/render.py	2015-02-19 17:46:41 UTC (rev 64686)
@@ -17,7 +17,7 @@
  - render::Overlay
  - render::Map
 
-(C) 2006-2014 by the GRASS Development Team
+(C) 2006-2015 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,29 +156,24 @@
             if self.type == 'command':
                 read = False
                 for c in self.cmd:
-                    ret, msg = self._runCommand(c)
-                    if ret != 0:
-                        break
+                    self._runCommand(c)
                     if not read:
                         self.environ["GRASS_RENDER_FILE_READ"] = "TRUE"
 
                 self.environ["GRASS_RENDER_FILE_READ"] = "FALSE"
             else:
-                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:
+                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)
+            
             # 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
@@ -186,19 +181,8 @@
     def _runCommand(self, cmd):
         """Run command to render data
         """
-        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])
+        self.renderMgr.Render(cmd, env=self.environ)
 
-        return ret, msg
-
     def GetCmd(self, string = False):
         """Get GRASS command as list of string.
 
@@ -275,13 +259,16 @@
         if ltype not in utils.command2ltype.values() + ['overlay', 'command']:
             raise GException(_("Unsupported map layer type '%s'") % ltype)
 
-        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
-
+        if not self.renderMgr:
+            if ltype == 'wms':
+                renderMgr = RenderWMSMgr
+            else:
+                renderMgr = RenderMgr
+                
+            self.renderMgr = renderMgr(layer=self,
+                                       mapfile=self.mapfile,
+                                       maskfile=self.maskfile)
+        
         self.type = ltype
 
     def SetName(self, name):
@@ -1402,3 +1389,21 @@
         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 16:56:57 UTC (rev 64685)
+++ grass/trunk/lib/init/grass.py	2015-02-19 17:46:41 UTC (rev 64686)
@@ -907,10 +907,11 @@
             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