[GRASS-SVN] r67731 - in grass/branches/releasebranch_7_0: gui/wxpython gui/wxpython/core lib/init
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 6 02:57:37 PST 2016
Author: martinl
Date: 2016-02-06 02:57:36 -0800 (Sat, 06 Feb 2016)
New Revision: 67731
Modified:
grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py
grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py
grass/branches/releasebranch_7_0/lib/init/grass.py
Log:
Close wxGUI on GRASS CLI exit (#770)
(merge r67306 from trunk)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py 2016-02-05 14:37:19 UTC (rev 67730)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/utils.py 2016-02-06 10:57:36 UTC (rev 67731)
@@ -3,7 +3,7 @@
@brief Misc utilities for wxGUI
-(C) 2007-2013 by the GRASS Development Team
+(C) 2007-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.
@@ -1175,6 +1175,32 @@
do_doctest_gettext_workaround()
return doctest.testmod().failed
+def registerPid(pid):
+ """Register process id as GUI_PID GRASS variable
+ :param: pid process id
+ """
+ env = grass.gisenv()
+ guiPid = []
+ if 'GUI_PID' in env:
+ guiPid = env['GUI_PID'].split(',')
+ guiPid.append(str(pid))
+ grass.run_command('g.gisenv', set='GUI_PID={}'.format(','.join(guiPid)))
+
+def unregisterPid(pid):
+ """Unregister process id from GUI_PID GRASS variable
+
+ :param: pid process id
+ """
+ env = grass.gisenv()
+ if 'GUI_PID' not in env:
+ return
+
+ guiPid = env['GUI_PID'].split(',')
+ pid = str(os.getpid())
+ if pid in guiPid:
+ guiPid.remove(pid)
+ grass.run_command('g.gisenv', set='GUI_PID={}'.format(','.join(guiPid)))
+
if __name__ == '__main__':
sys.exit(doc_test())
Modified: grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py 2016-02-05 14:37:19 UTC (rev 67730)
+++ grass/branches/releasebranch_7_0/gui/wxpython/wxgui.py 2016-02-06 10:57:36 UTC (rev 67731)
@@ -21,9 +21,10 @@
import os
import sys
import getopt
+import atexit
from core import globalvar
-from core.utils import _
+from core.utils import _, registerPid, unregisterPid
from grass.exceptions import Usage
from grass.script.core import set_raise_on_error
@@ -112,7 +113,9 @@
return workspaceFile
-
+def cleanup():
+ unregisterPid(os.getpid())
+
def main(argv = None):
if argv is None:
@@ -135,7 +138,11 @@
q = wx.LogNull()
set_raise_on_error(True)
+ # register GUI PID
+ registerPid(os.getpid())
+
app.MainLoop()
if __name__ == "__main__":
+ atexit.register(cleanup)
sys.exit(main())
Modified: grass/branches/releasebranch_7_0/lib/init/grass.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/init/grass.py 2016-02-05 14:37:19 UTC (rev 67730)
+++ grass/branches/releasebranch_7_0/lib/init/grass.py 2016-02-06 10:57:36 UTC (rev 67731)
@@ -92,8 +92,9 @@
env_curr = read_gisrc()
env_new = {}
for k,v in env_curr.iteritems():
- if 'MONITOR' not in k:
- env_new[k] = v
+ if 'MONITOR' in k or k.endswith('PID'):
+ continue
+ env_new[k] = v
write_gisrc(env_new)
@@ -999,6 +1000,20 @@
Popen([os.getenv('GRASS_PYTHON'), gfile(wxpython_base, "wxgui.py")])
+def close_gui():
+ """Close GUI if running"""
+ if gfile('etc', 'python') not in sys.path:
+ sys.path.append(gfile('etc', 'python'))
+ from grass.script import core as gcore # pylint: disable=E0611
+ env = gcore.gisenv()
+ if 'GUI_PID' not in env:
+ return
+ import signal
+ for pid in env['GUI_PID'].split(','):
+ if grass_debug:
+ message("Exiting GUI with pid={}".format(pid))
+ os.kill(int(pid), signal.SIGTERM)
+
def clear_screen():
if windows:
pass
@@ -1491,6 +1506,9 @@
exit_val = shell_process.wait()
if exit_val != 0:
warning(_("Failed to start shell '%s'") % os.getenv('SHELL'))
+
+# close GUI if running
+close_gui()
clear_screen()
More information about the grass-commit
mailing list