[GRASS-SVN] r39350 - in grass/branches/develbranch_6: gui/tcltk/gis.m lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 30 06:57:06 EDT 2009


Author: marisn
Date: 2009-09-30 06:57:05 -0400 (Wed, 30 Sep 2009)
New Revision: 39350

Modified:
   grass/branches/develbranch_6/gui/tcltk/gis.m/gm.tcl
   grass/branches/develbranch_6/gui/tcltk/gis.m/gmmenu.tcl
   grass/branches/develbranch_6/lib/init/grass.src
   grass/branches/develbranch_6/lib/init/init.sh
Log:
Close gis.m on exit; Provide exit from GRASS in gis.m

Modified: grass/branches/develbranch_6/gui/tcltk/gis.m/gm.tcl
===================================================================
--- grass/branches/develbranch_6/gui/tcltk/gis.m/gm.tcl	2009-09-30 07:21:37 UTC (rev 39349)
+++ grass/branches/develbranch_6/gui/tcltk/gis.m/gm.tcl	2009-09-30 10:57:05 UTC (rev 39350)
@@ -513,6 +513,39 @@
 
 };
 
+# Provides remote exit call. Used by GRASS exit to close all session's gis.m instances.
+# Argument session_id is exit caller's GIS_LOCK variable.
+proc Gm::remoteExit { session_id } {
+	global env
+	if {$env(GIS_LOCK) == $session_id} Gm::quit
+}
+
+# Provides exit from gis.m. May also do some clean-up, save-settings et.al.
+proc Gm::quit { {full_exit false} } {
+	global env
+	
+	if { $full_exit } {
+		if { [catch {set spid $env(GRASS_SHELL_PID)}] == 0 } {
+			set leave [tk_dialog .leave [G_msg "End current GRASS session"] \
+			[G_msg "Do You really want to terminate current\
+GRASS session?\n\nThis action will colse all sessions gis.m instances.\n\nIf You have running some \
+GRASS module from comandline, GRASS will terminate after it\
+finishes to run."] warning 1 [G_msg "Terminate current GRASS sesion"] [G_msg "Cancel"]]
+			if { $leave == 0 } { 
+				exec kill -SIGINT $env(GRASS_SHELL_PID)
+			} else { 
+				return
+			}
+		} else {
+			tk_messageBox -type ok -title [G_msg "Not supported"] -message \
+			[G_msg "We sorry. Your shell does not support this feature. \n\
+You have to type 'exit' in terminal manualy."]
+		}
+	}
+
+	exit
+}
+
 ###############################################################################
 
 proc main {argc argv} {
@@ -538,7 +571,7 @@
 		Gm::SaveFileBox
     }
     bind . <$keycontrol-Key-q> {
-		exit
+		Gm::quit
 	}
     bind . <$keycontrol-Key-w> {
 		GmTree::FileClose {}
@@ -562,6 +595,9 @@
     }
 }
 
+wm protocol . WM_DELETE_WINDOW {
+	Gm::quit
+}
 
 main $argc $argv
 wm geom . [wm geom .]

Modified: grass/branches/develbranch_6/gui/tcltk/gis.m/gmmenu.tcl
===================================================================
--- grass/branches/develbranch_6/gui/tcltk/gis.m/gmmenu.tcl	2009-09-30 07:21:37 UTC (rev 39349)
+++ grass/branches/develbranch_6/gui/tcltk/gis.m/gmmenu.tcl	2009-09-30 10:57:05 UTC (rev 39350)
@@ -201,7 +201,8 @@
 	}}
 	{command {[G_msg "PostScript plot"]} {} "ps.map: Create cartographic PostScript plot" {} -command { execute ps.map }}
 	{separator}
-	{command {[G_msg "E&xit"]} {} "Exit GIS Manager" {} -accelerator $keyctrl-Q -command { exit } }
+	{command {[G_msg "Exit &GRASS"]} {} "End current GRASS session" {} -command { Gm::quit true } }
+	{command {[G_msg "&Quit GIS Manager"]} {} "Exit GIS Manager" {} -accelerator $keyctrl-Q -command { Gm::quit } }
  }
  {[G_msg "&Config"]} all options $tmenu {
 	{cascad {[G_msg "Region"]} {} "" $tmenu {

Modified: grass/branches/develbranch_6/lib/init/grass.src
===================================================================
--- grass/branches/develbranch_6/lib/init/grass.src	2009-09-30 07:21:37 UTC (rev 39349)
+++ grass/branches/develbranch_6/lib/init/grass.src	2009-09-30 10:57:05 UTC (rev 39350)
@@ -40,7 +40,9 @@
 		( exec xterm -e $0 "$@" ) &>/dev/null
 	else
 		# Returning user may have preffered GRASS terminal application
-		GRASS_XTERM=`awk '/GRASS_XTERM/ {print $2}' "$GISRCRC"  2>/dev/null`
+		if [ -z "$GRASS_XTERM" ]; then
+			GRASS_XTERM=`awk '/GRASS_XTERM/ {print $2}' "$GISRCRC"  2>/dev/null`
+		fi;
 		if [ -n "$GRASS_XTERM" ]; then
 			# User has preffered GRASS terminal app
 			( exec $GRASS_XTERM -e $0 "$@" ) &>/dev/null

Modified: grass/branches/develbranch_6/lib/init/init.sh
===================================================================
--- grass/branches/develbranch_6/lib/init/init.sh	2009-09-30 07:21:37 UTC (rev 39349)
+++ grass/branches/develbranch_6/lib/init/init.sh	2009-09-30 10:57:05 UTC (rev 39350)
@@ -817,7 +817,10 @@
     
     # Check for tcltk interface
     tcltk | gis.m)
-	"$GISBASE/scripts/gis.m"
+	if [ $sh -ne bash ] || [ $sh -ne msh ] || [ $sh -ne cygwin ]; then
+		# trap is not supported by csh/tcsh and rc
+		"$GISBASE/scripts/gis.m"
+	fi;
 	;;
     oldtcltk | d.m)
 	"$GISBASE/scripts/d.m"
@@ -966,6 +969,11 @@
 
     echo "export PATH=\"$PATH\"" >> "$bashrc"
     echo "export HOME=\"$USERHOME\"" >> "$bashrc" # restore user home path
+    echo 'export GRASS_SHELL_PID=$$' >> "$bashrc" # can be used to terminate GRASS session from GUI
+    if [ "$GRASS_GUI" == tcltk ] || [ "$GRASS_GUI" == gis.m ]; then
+    	echo '$GISBASE/scripts/gis.m' >> "$bashrc" # Start gis.m
+    fi;
+    echo 'trap "echo \"GUI issued an exit\"; exit" SIGINT' >> "$bashrc"
 
     "$ETC/run" "$SHELL"
     EXIT_VAL=$?
@@ -1012,6 +1020,16 @@
     d.mon stop="$MON"
 done
 
+# Attempt to close any open gis.m instances. 
+# Will work only on some systems, still has no harm to others
+if [ $TCLTKGRASSBASE ] ; then
+	echo "Closing open gis.m sessions....."
+	echo 'foreach gwin [lsearch -all -inline [winfo interps] gm_tcl*] {
+		catch {send -async $gwin Gm::remoteExit $env(GIS_LOCK)}
+	}
+	exit' | $GRASS_WISH >/dev/null 2>&1
+fi
+
 echo "Cleaning up temporary files ..."
 
 "$ETC/clean_temp" > /dev/null



More information about the grass-commit mailing list