[GRASS-SVN] r67228 - in grass/branches/releasebranch_7_0: gui/wxpython gui/wxpython/lmgr gui/wxpython/xml lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 18 10:16:34 PST 2015


Author: martinl
Date: 2015-12-18 10:16:34 -0800 (Fri, 18 Dec 2015)
New Revision: 67228

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
   grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py
   grass/branches/releasebranch_7_0/gui/wxpython/xml/toolboxes.xml
   grass/branches/releasebranch_7_0/gui/wxpython/xml/wxgui_items.xml
   grass/branches/releasebranch_7_0/lib/init/grass.py
Log:
Exit GRASS from GUI backported from trunk
     (merge r66917:8, r66920, r66982, r67226:7 from trunk)


Modified: grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py	2015-12-18 17:35:14 UTC (rev 67227)
+++ grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py	2015-12-18 18:16:34 UTC (rev 67228)
@@ -176,7 +176,7 @@
             
         self._auimgr.GetPane('toolbarNviz').Hide()
         # bindings
-        self.Bind(wx.EVT_CLOSE,    self.OnCloseWindow)
+        self.Bind(wx.EVT_CLOSE,    self.OnCloseWindowOrExit)
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
 
         self._giface.mapCreated.connect(self.OnMapCreated)
@@ -2190,6 +2190,31 @@
 
     def OnCloseWindow(self, event):
         """Cleanup when wxGUI is quitted"""
+        self._closeWindow()
+
+    def OnCloseWindowOrExit(self, event):
+        """Cleanup when wxGUI is quitted
+
+        Ask user also to quit GRASS including terminal
+        """
+        dlg = wx.MessageDialog(self,
+                               message = _("Do you want to quit GRASS GIS?\n\n"
+                                           "Press 'Yes' to quit GRASS GUI and shell.\n"
+                                           "Press 'No' to close only GRASS GUI.\n"
+                                           "Press 'Cancel' to cancel this operation."),
+                               caption = _("Quit GRASS GIS?"),
+                               style = wx.YES_NO | wx.YES_DEFAULT |
+                               wx.CANCEL | wx.ICON_QUESTION | wx.CENTRE)
+        ret = dlg.ShowModal()
+        dlg.Destroy()
+
+        if ret != wx.ID_CANCEL:
+            self._closeWindow()
+            if ret == wx.ID_YES:
+                self._quitGRASS()
+        
+    def _closeWindow(self):
+        """Close wxGUI"""
         # save command protocol if actived
         if self.goutput.btnCmdProtocol.GetValue():
             self.goutput.CmdProtocolSave()
@@ -2237,10 +2262,22 @@
         self.OnDisplayCloseAll()
         
         self.notebookLayers.DeleteAllPages()
-        
         self._auimgr.UnInit()
         self.Destroy()
         
+    def _quitGRASS(self):
+        """Quit GRASS terminal"""
+        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'"""
         wx.MessageBox(parent = self,

Modified: grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py	2015-12-18 17:35:14 UTC (rev 67227)
+++ grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py	2015-12-18 18:16:34 UTC (rev 67228)
@@ -38,13 +38,13 @@
 
 
 class GMApp(wx.App):
-    def __init__(self, workspace = None):
+    def __init__(self, workspace=None):
         """ Main GUI class.
 
         :param workspace: path to the workspace file
         """
         self.workspaceFile = workspace
-
+        
         # call parent class initializer
         wx.App.__init__(self, False)
 
@@ -79,8 +79,8 @@
         wx.Yield()
 
         # create and show main frame
-        mainframe = GMFrame(parent = None, id = wx.ID_ANY,
-                            workspace = self.workspaceFile)
+        mainframe = GMFrame(parent=None, id=wx.ID_ANY,
+                            workspace=self.workspaceFile)
 
         mainframe.Show()
         self.SetTopWindow(mainframe)
@@ -104,13 +104,13 @@
         if o in ("-h", "--help"):
             printHelp()
 
-        if o in ("-w", "--workspace"):
+        elif o in ("-w", "--workspace"):
             if a != '':
                 workspaceFile = str(a)
             else:
                 workspaceFile = args.pop(0)
 
-    return (workspaceFile,)
+    return workspaceFile
 
 
 def main(argv = None):
@@ -123,15 +123,14 @@
                                        ["help", "workspace"])
         except getopt.error as msg:
             raise Usage(msg)
-
     except Usage as err:
         print >> sys.stderr, err.msg
         print >> sys.stderr, "for help use --help"
         printHelp()
-
-    workspaceFile = process_opt(opts, args)[0]
-
+    
+    workspaceFile = process_opt(opts, args)
     app = GMApp(workspaceFile)
+    
     # suppress wxPython logs
     q = wx.LogNull()
     set_raise_on_error(True)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/xml/toolboxes.xml
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/xml/toolboxes.xml	2015-12-18 17:35:14 UTC (rev 67227)
+++ grass/branches/releasebranch_7_0/gui/wxpython/xml/toolboxes.xml	2015-12-18 18:16:34 UTC (rev 67228)
@@ -41,6 +41,7 @@
       <separator/>
       <wxgui-item name="LaunchScript"/>
       <separator/>
+      <wxgui-item name="CloseGUI"/>
       <wxgui-item name="Quit"/>
     </items>
   </toolbox>

Modified: grass/branches/releasebranch_7_0/gui/wxpython/xml/wxgui_items.xml
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/xml/wxgui_items.xml	2015-12-18 17:35:14 UTC (rev 67227)
+++ grass/branches/releasebranch_7_0/gui/wxpython/xml/wxgui_items.xml	2015-12-18 18:16:34 UTC (rev 67228)
@@ -62,10 +62,16 @@
     <handler>OnRunScript</handler>
     <description>Launches script file.</description>
   </wxgui-item>
+  <wxgui-item name="CloseGUI">
+    <label>Close GUI</label>
+    <handler>OnCloseWindow</handler>
+    <description>Quit wxGUI session.</description>
+    <shortcut>Ctrl+W</shortcut>
+  </wxgui-item>
   <wxgui-item name="Quit">
-    <label>Exit GUI</label>
-    <handler>OnCloseWindow</handler>
-    <description>Quit the GRASS wxGUI session.</description>
+    <label>Quit GRASS GIS</label>
+    <handler>OnCloseWindowOrExit</handler>
+    <description>Quit wxGUI session and exit GRASS shell.</description>
     <shortcut>Ctrl+Q</shortcut>
     <wx-id>ID_EXIT</wx-id>
   </wxgui-item>

Modified: grass/branches/releasebranch_7_0/lib/init/grass.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/init/grass.py	2015-12-18 17:35:14 UTC (rev 67227)
+++ grass/branches/releasebranch_7_0/lib/init/grass.py	2015-12-18 18:16:34 UTC (rev 67228)
@@ -1055,8 +1055,6 @@
 
 
 def csh_startup():
-    global exit_val
-
     userhome = os.getenv('HOME')      # save original home
     home = location
     os.environ['HOME'] = home
@@ -1100,14 +1098,13 @@
     f.close()
     writefile(tcshrc, readfile(cshrc))
 
-    exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
+    process = Popen([gfile("etc", "run"), os.getenv('SHELL')])
 
     os.environ['HOME'] = userhome
 
+    return process
 
 def bash_startup():
-    global exit_val
-
     # save command history in mapset dir and remember more
     os.environ['HISTFILE'] = os.path.join(location, ".bash_history")
     if not os.getenv('HISTSIZE') and not os.getenv('HISTFILESIZE'):
@@ -1163,32 +1160,29 @@
 
     f.close()
 
-    exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
+    process = Popen([gfile("etc", "run"), os.getenv('SHELL')])
 
     os.environ['HOME'] = userhome
+    
+    return process
 
-
 def default_startup():
-    global exit_val
-
     if windows:
         os.environ['PS1'] = "GRASS %s> " % (grass_version)
         # "$ETC/run" doesn't work at all???
-        exit_val = subprocess.call([os.getenv('SHELL')])
+        process = subprocess.Popen([os.getenv('SHELL')])
         cleanup_dir(os.path.join(location, ".tmp"))  # remove GUI session files from .tmp
     else:
         os.environ['PS1'] = "GRASS %s (%s):\w > " % (grass_version, location_name)
-        exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
+        process = Popen([gfile("etc", "run"), os.getenv('SHELL')])
+        
+    return process
 
-    if exit_val != 0:
-        fatal(_("Failed to start shell '%s'") % os.getenv('SHELL'))
-
-
 def done_message():
     if batch_job and os.access(batch_job, os.X_OK):
         message(_("Batch job '%s' (defined in GRASS_BATCH_JOB variable) was executed.") % batch_job)
         message(_("Goodbye from GRASS GIS"))
-        sys.exit(exit_val)
+        sys.exit(0)
     else:
         message(_("Done."))
         message("")
@@ -1482,12 +1476,20 @@
         message(_("Launching <%s> GUI in the background, please wait...") % grass_gui)
 
 if sh in ['csh', 'tcsh']:
-    csh_startup()
+    shell_process = csh_startup()
 elif sh in ['bash', 'msh', 'cygwin']:
-    bash_startup()
+    shell_process = bash_startup()
 else:
-    default_startup()
+    shell_process = default_startup()
 
+# start GUI and register shell PID in rc file
+kv = read_gisrc()
+kv['PID'] = str(shell_process.pid)
+write_gisrc(kv)
+exit_val = shell_process.wait()
+if exit_val != 0:
+    warning(_("Failed to start shell '%s'") % os.getenv('SHELL'))
+
 clear_screen()
 
 clean_env()



More information about the grass-commit mailing list