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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 25 09:24:10 PST 2015


Author: martinl
Date: 2015-11-25 09:24:10 -0800 (Wed, 25 Nov 2015)
New Revision: 66920

Modified:
   grass/trunk/general/g.gui/main.c
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/wxgui.py
   grass/trunk/lib/init/grass.py
Log:
simplify GRASS exiting from GUI (see r66917:8)


Modified: grass/trunk/general/g.gui/main.c
===================================================================
--- grass/trunk/general/g.gui/main.c	2015-11-24 22:55:46 UTC (rev 66919)
+++ grass/trunk/general/g.gui/main.c	2015-11-25 17:24:10 UTC (rev 66920)
@@ -29,7 +29,7 @@
     struct Option *type, *rc_file;
     struct Flag *update_ui, *fglaunch, *nolaunch;
     struct GModule *module;
-    const char *gui_type_env, *shell_pid;
+    const char *gui_type_env;
     char progname[GPATH_MAX];
     char *desc;
 
@@ -103,8 +103,6 @@
 	exit(EXIT_SUCCESS);
     }
 
-    shell_pid = G_getenv_nofatal("PID");
-    
     sprintf(progname, "%s/gui/wxpython/wxgui.py", G_gisbase());
     if (access(progname, F_OK) == -1)
         G_fatal_error(_("Your installation doesn't include GUI, exiting."));
@@ -113,22 +111,22 @@
         G_message(_("Launching <%s> GUI, please wait..."), type->answer);
         if (rc_file->answer) {
             G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                       "--workspace", rc_file->answer, "--pid", shell_pid, NULL);
+                       "--workspace", rc_file->answer, NULL);
         }
         else {
             G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                       "--pid", shell_pid, NULL);
+                       NULL);
         }
     }
     else {
         G_message(_("Launching <%s> GUI in the background, please wait..."), type->answer);
         if (rc_file->answer) {
             G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                       "--workspace", rc_file->answer, "--pid", shell_pid, SF_BACKGROUND, NULL);
+                       "--workspace", rc_file->answer, SF_BACKGROUND, NULL);
         }
         else {
             G_spawn_ex(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), progname,
-                       "--pid", shell_pid, SF_BACKGROUND, NULL);
+                       SF_BACKGROUND, NULL);
         }
         /* stop the impatient from starting it again
            before the splash screen comes up */

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2015-11-24 22:55:46 UTC (rev 66919)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2015-11-25 17:24:10 UTC (rev 66920)
@@ -84,10 +84,9 @@
     commands, tree widget page for managing map layers.
     """
     def __init__(self, parent, id = wx.ID_ANY, title = None,
-                 workspace = None, shellPid = None,
+                 workspace = None,
                  size = globalvar.GM_WINDOW_SIZE, style = wx.DEFAULT_FRAME_STYLE, **kwargs):
         self.parent    = parent
-        self._shellPid = shellPid         # process id of shell running on the background
         if title:
             self.baseTitle = title
         else:
@@ -2260,12 +2259,16 @@
     def OnCloseWindowExitGRASS(self, event):
         """Close wxGUI and exit GRASS shell."""
         self._closeWindow()
-        if self._shellPid:
-            Debug.msg(1, "Exiting shell with pid={}".format(self._shellPid))
-            import signal
-            os.kill(self._shellPid, signal.SIGTERM)
-        else:
+        try:
+            shellPid = int(grass.gisenv()['PID'])
+            print >> sys.stderr, grass.gisenv()
+        except:
             grass.warning(_("Unable to exit GRASS shell: unknown PID"))
+            return
+
+        Debug.msg(1, "Exiting shell with pid={}".format(shellPid))
+        import signal
+        os.kill(shellPid, signal.SIGTERM)
         
     def MsgNoLayerSelected(self):
         """Show dialog message 'No layer selected'"""

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2015-11-24 22:55:46 UTC (rev 66919)
+++ grass/trunk/gui/wxpython/wxgui.py	2015-11-25 17:24:10 UTC (rev 66920)
@@ -35,14 +35,12 @@
 
 
 class GMApp(wx.App):
-    def __init__(self, workspace=None, shellPid=None):
+    def __init__(self, workspace=None):
         """ Main GUI class.
 
         :param workspace: path to the workspace file
-        :param shellPid: process id of shell running on background
         """
         self.workspaceFile = workspace
-        self._shellPid = shellPid
         
         # call parent class initializer
         wx.App.__init__(self, False)
@@ -80,7 +78,7 @@
         # create and show main frame
         from lmgr.frame import GMFrame
         mainframe = GMFrame(parent=None, id=wx.ID_ANY,
-                            workspace=self.workspaceFile, shellPid=self._shellPid)
+                            workspace=self.workspaceFile)
 
         mainframe.Show()
         self.SetTopWindow(mainframe)
@@ -99,7 +97,7 @@
 
 def process_opt(opts, args):
     """ Process command-line arguments"""
-    workspaceFile = shellPid = None
+    workspaceFile = None
     for o, a in opts:
         if o in ("-h", "--help"):
             printHelp()
@@ -110,15 +108,9 @@
             else:
                 workspaceFile = args.pop(0)
 
-        elif o in ("-p", "--pid"):
-            if a != '':
-                shellPid = int(a)
-            else:
-                shellPid = int(args.pop(0))
+    return workspaceFile
 
-    return (workspaceFile, shellPid)
 
-
 def main(argv = None):
 
     if argv is None:
@@ -134,8 +126,8 @@
         print >> sys.stderr, "for help use --help"
         printHelp()
     
-    workspaceFile, shellPid = process_opt(opts, args)
-    app = GMApp(workspaceFile, shellPid)
+    workspaceFile = process_opt(opts, args)
+    app = GMApp(workspaceFile)
     
     # suppress wxPython logs
     q = wx.LogNull()

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2015-11-24 22:55:46 UTC (rev 66919)
+++ grass/trunk/lib/init/grass.py	2015-11-25 17:24:10 UTC (rev 66920)
@@ -133,7 +133,7 @@
     env_curr = read_gisrc(gisrc)
     env_new = {}
     for k,v in env_curr.items():
-        if 'MONITOR' not in k:
+        if k not in ('MONITOR', 'PID'):
             env_new[k] = v
 
     write_gisrc(env_new, gisrc)
@@ -1338,7 +1338,7 @@
     return returncode
 
 
-def start_gui(grass_gui, shell_pid=None):
+def start_gui(grass_gui):
     """Start specified GUI
 
     :param grass_gui: GUI name (allowed values: 'wxpython')
@@ -1348,14 +1348,9 @@
     
     # Check for gui interface
     if grass_gui == "wxpython":
-        cmd = [os.getenv('GRASS_PYTHON'), wxpath("wxgui.py")]
-        if shell_pid:
-            cmd.append('--pid')
-            cmd.append(str(shell_pid))
-        
-        Popen(cmd)
+        Popen([os.getenv('GRASS_PYTHON'), wxpath("wxgui.py")])
 
-    
+
 def clear_screen():
     """Clear terminal"""
     if windows:
@@ -1900,7 +1895,8 @@
             shell_process = default_startup(mapset_settings.full_mapset,
                                             mapset_settings.location)
 
-        start_gui(grass_gui, shell_process.pid)
+        # start GUI and register shell PID in rc file
+        start_gui(grass_gui)
         kv = read_gisrc(gisrc)
         kv['PID'] = str(shell_process.pid)
         write_gisrc(kv, gisrc)



More information about the grass-commit mailing list