[GRASS-SVN] r40164 - grass/branches/develbranch_6/gui/tcltk/gis.m

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 30 14:20:24 EST 2009


Author: marisn
Date: 2009-12-30 14:20:23 -0500 (Wed, 30 Dec 2009)
New Revision: 40164

Modified:
   grass/branches/develbranch_6/gui/tcltk/gis.m/maplabels.tcl
Log:
gis.m: Fix PS label UI. Should fix issue #819

Modified: grass/branches/develbranch_6/gui/tcltk/gis.m/maplabels.tcl
===================================================================
--- grass/branches/develbranch_6/gui/tcltk/gis.m/maplabels.tcl	2009-12-29 15:46:22 UTC (rev 40163)
+++ grass/branches/develbranch_6/gui/tcltk/gis.m/maplabels.tcl	2009-12-30 19:20:23 UTC (rev 40164)
@@ -14,19 +14,16 @@
 #	* Not all label file options are in use, also not all options are in labelfiles.
 #	(because this is TclTk text, v.label options don't exactly map onto what is available
 #	 in TclTk. AFAICT, all possible matches are implemented)
-#	* Label configuration options are not separated from displayed label options. It causes
-#	label options to change after every screen redraw. This way it was already working :)
-#	(Unless you check the "override" box, it will default to the values in the labels file.
-#	 I fixed a few that might not have been sticking also - CMB)
 #	* Ability to override single option. Like: use whatever defined in labelfile, except font size
 # 	(Agreed. A TODO if there is time. Needs substantial reconfiguration of options panel)
 #	* Label rotation. (not available in TclTk - CMB)
 #	* Somtime label enclosing box height is not calculated correctly. 
-#	* Ability to display label point and configure it. (I don't understand this)
+#	* Ability to display label point (coordinates as site) and configure it.
 #
 
 namespace eval GmCLabels {
-    variable array opt ;# labels current options
+    variable array opt ;# labels current global options
+    variable array ropt;# labels resulting options (global or read from file)
     variable count 1
     variable array tree ;# mon    
     variable optlist
@@ -68,7 +65,8 @@
 	-window    $frm \
 	-drawcross auto 
 
-    set opt($count,1,_check) 1 
+    set opt($count,1,_check) 1
+    set ropt($count,1,_check) 1
     set dup($count) 0
 
     set opt($count,1,xcoord) 1.0 
@@ -90,8 +88,9 @@
     set opt($count,1,ltxt) ""
     set opt($count,1,lhoffset) 2 ;# space between label and enclosing box
     set opt($count,1,lvoffset) 2 ;# space between label and enclosing box
-    set opt($count,1,lopaque) "yes"
-    set opt($count,1,lboxbenable) "yes"
+    set opt($count,1,lopaque) 1
+    set opt($count,1,lboxenable) 1
+    set opt($count,1,lboxbenable) 1
     set opt($count,1,lborder) "black"
     set opt($count,1,lbackground) "yellow"
     set opt($count,1,lbwidth) 1
@@ -100,7 +99,7 @@
 
 	set optlist { _check xcoord ycoord xoffset yoffset labels lfont lfontfamily lfontsize \
 		lfontweight lfontslant lfontunderline lfontoverstrike lfill lwidth \
-		lanchor ljust ltxt lhoffset lvoffset lopaque lboxbenable lborder lbackground \
+		lanchor ljust ltxt lhoffset lvoffset lopaque lboxenable lboxbenable lborder lbackground \
 		lbwidth lboxlenable override }
 
     foreach key $optlist {
@@ -119,7 +118,7 @@
 }
 
 proc GmCLabels::select_labels { id } {
-    set m [GSelect paint/labels title "Label file"]
+    set m [GSelect paint/labels title [G_msg "Label file"]]
     if { $m != "" } { 
         set GmCLabels::opt($id,1,labels) $m
         GmTree::autonamel $m
@@ -219,13 +218,10 @@
     
 # labels options3
     set row [ frame $frm.lbltopt3 ]
-    Label $row.a -text [G_msg "Enclose label in box: "] 
+    Label $row.a -text [G_msg "Enclose label in box: "]
     checkbutton $row.b -variable GmCLabels::opt($id,1,lboxenable)
-    	$row.b select
     Label $row.c -text [G_msg "Draw label background: "] 
-    checkbutton $row.d -variable GmCLabels::opt($id,1,lopaque) \
-   	-command " if { $opt($id,1,lopaque) } { set opt($id,1,lboxenable) 1 } else { set opt($id,1,lboxenable) 0 }"
-    	$row.d select
+    checkbutton $row.d -variable GmCLabels::opt($id,1,lopaque)
     Label $row.e -text [G_msg "Background color:"] 
     SelectColor $row.f -type menubutton -variable GmCLabels::opt($id,1,lbackground)
     pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
@@ -233,14 +229,12 @@
         
 # labels options4
     set row [ frame $frm.lbltopt4 ]
-    Label $row.a -text [G_msg "Draw box outline: "] 
-    checkbutton $row.b -variable GmCLabels::opt($id,1,lboxbenable) \
-    -command " if { $opt($id,1,lboxbenable) } { set opt($id,1,lboxenable) 1 } else { set opt($id,1,lboxenable) 0 }"
-    	$row.b select
+    Label $row.a -text [G_msg "Draw box outline: "]
+    checkbutton $row.b -variable GmCLabels::opt($id,1,lboxbenable) 
     Label $row.c -text [G_msg "Border width:"]
     Entry $row.d -width 3 -text "$opt($id,1,lbwidth)" \
 	    -textvariable GmCLabels::opt($id,1,lbwidth)
-    Label $row.e -text [G_msg "Border color:"] 
+    Label $row.e -text [G_msg "Border color:"]
     SelectColor $row.f -type menubutton -variable GmCLabels::opt($id,1,lborder)
     pack $row.a $row.b $row.c $row.d $row.e $row.f -side left
     pack $row -side top -fill both -expand yes
@@ -269,7 +263,7 @@
     Label $row.e -text [G_msg "size:"]
     Entry $row.f -width 5 -text GmCLabels::opt($id,1,lfontsize) \
 	    -textvariable GmCLabels::opt($id,1,lfontsize)
-    Label $row.g -text [G_msg "  color"] 
+    Label $row.g -text [G_msg "  color"]
     SelectColor $row.h -type menubutton -variable GmCLabels::opt($id,1,lfill)
     pack $row.a $row.b $row.c $row.d  $row.e $row.f $row.g $row.h -side left
     pack $row -side top -fill both -expand yes
@@ -340,55 +334,57 @@
 		switch $key {
 			"east" {
 				set east $val
-				set opt($id,1,xcoord) [MapCanvas::mape2scrx $mon $east]
+				set ropt($id,1,xcoord) [MapCanvas::mape2scrx $mon $east]
 			}
 			"north" {
 				set north $val
-				set opt($id,1,ycoord) [MapCanvas::mapn2scry $mon $north]
+				set ropt($id,1,ycoord) [MapCanvas::mapn2scry $mon $north]
 			}
 			"xoffset" {
 				if { $opt($id,1,override) == 0 } {
-					set opt($id,1,xoffset) $val
+					set ropt($id,1,xoffset) $val
+					set ropt($id,1,xcoord) [expr $ropt($id,1,xcoord) + $ropt($id,1,xoffset)]
+				} else { 
+					set ropt($id,1,xcoord) [expr $ropt($id,1,xcoord) + $opt($id,1,xoffset)]
 				}
-				if { $opt($id,1,xoffset) != "" } {
-					set opt($id,1,xcoord) [expr $opt($id,1,xcoord) + $opt($id,1,xoffset)]
-				}
 			}
 			"yoffset" {
 				if { $opt($id,1,override) == 0 } {
-					set opt($id,1,yoffset) $val
+					set ropt($id,1,yoffset) $val
+					set ropt($id,1,ycoord) [expr $ropt($id,1,ycoord) + $ropt($id,1,yoffset)]
+				} else {
+					set ropt($id,1,ycoord) [expr $ropt($id,1,ycoord) + $opt($id,1,yoffset)]
 				}
-				if { $opt($id,1,yoffset) != "" } {
-					set opt($id,1,ycoord) [expr $opt($id,1,ycoord) + $opt($id,1,yoffset)]
-				}
 			}
 			"ref" {
 				if { $opt($id,1,override) == 0 } {
-					set opt($id,1,lanchor) $val
+					set ropt($id,1,lanchor) $val
+				} else {
+					set ropt($id,1,lanchor) $opt($id,1,lanchor)
 				}
-				switch $opt($id,1,lanchor) {
-					"lower left" 	{ set opt($id,1,anchor) "ne"}
-					"left lower" 	{ set opt($id,1,anchor) "ne"}
-					"lower" 		{ set opt($id,1,anchor) "n" }
-					"lower center" 	{ set opt($id,1,anchor) "n" }
-					"center lower" 	{ set opt($id,1,anchor) "n" }
-					"lower right" 	{ set opt($id,1,anchor) "nw"}
-					"right lower" 	{ set opt($id,1,anchor) "nw"}
-					"left" 			{ set opt($id,1,anchor) "e" }
-					"center left" 	{ set opt($id,1,anchor) "e" }
-					"left center" 	{ set opt($id,1,anchor) "e" }
-					"center" 		{ set opt($id,1,anchor) "center" }
-					"right" 		{ set opt($id,1,anchor) "w" }
-					"center right" 	{ set opt($id,1,anchor) "w" }
-					"right center" 	{ set opt($id,1,anchor) "w" }
-					"upper left" 	{ set opt($id,1,anchor) "se"}
-					"left upper" 	{ set opt($id,1,anchor) "se"}
-					"upper" 		{ set opt($id,1,anchor) "s" }
-					"upper center" 	{ set opt($id,1,anchor) "s" }
-					"center upper" 	{ set opt($id,1,anchor) "s" }
-					"upper right" 	{ set opt($id,1,anchor) "sw"}
-					"right upper" 	{ set opt($id,1,anchor) "sw"}
-					default 		{ set opt($id,1,anchor) "w" }
+				switch $ropt($id,1,lanchor) {
+					"lower left" 	{ set ropt($id,1,anchor) "ne"}
+					"left lower" 	{ set ropt($id,1,anchor) "ne"}
+					"lower" 	{ set ropt($id,1,anchor) "n" }
+					"lower center" 	{ set ropt($id,1,anchor) "n" }
+					"center lower" 	{ set ropt($id,1,anchor) "n" }
+					"lower right" 	{ set ropt($id,1,anchor) "nw"}
+					"right lower" 	{ set ropt($id,1,anchor) "nw"}
+					"left" 		{ set ropt($id,1,anchor) "e" }
+					"center left" 	{ set ropt($id,1,anchor) "e" }
+					"left center" 	{ set ropt($id,1,anchor) "e" }
+					"center" 	{ set ropt($id,1,anchor) "center" }
+					"right" 	{ set ropt($id,1,anchor) "w" }
+					"center right" 	{ set ropt($id,1,anchor) "w" }
+					"right center" 	{ set ropt($id,1,anchor) "w" }
+					"upper left" 	{ set ropt($id,1,anchor) "se"}
+					"left upper" 	{ set ropt($id,1,anchor) "se"}
+					"upper" 	{ set ropt($id,1,anchor) "s" }
+					"upper center" 	{ set ropt($id,1,anchor) "s" }
+					"center upper" 	{ set ropt($id,1,anchor) "s" }
+					"upper right" 	{ set ropt($id,1,anchor) "sw"}
+					"right upper" 	{ set ropt($id,1,anchor) "sw"}
+					default 	{ set ropt($id,1,anchor) "w" }
 				}
 			}
 			"font" {
@@ -397,17 +393,21 @@
 			}
 			"color" {
 				if { $opt($id,1,override) == 0 } {
-					set opt($id,1,lfill)  [color_grass_to_tcltk $val]
+					set ropt($id,1,lfill)  [color_grass_to_tcltk $val]
+				} else {
+					set ropt($id,1,lfill) $opt($id,1,lfill)
 				}
-				if { $opt($id,1,lfill) == "" } {
-					set opt($id,1,lfill) "#000000"
+				if { $ropt($id,1,lfill) == "" } {
+					set ropt($id,1,lfill) "#000000"
 				}
 			}
 			"fontsize" {
-				if { $opt($id,1,override) == 0 } {set opt($id,1,lfontsize) $val}
+				if { $opt($id,1,override) == 0 } { set ropt($id,1,lfontsize) $val 
+				} else { set ropt($id,1,lfontsize) $opt($id,1,lfontsize) }
 			}
 			"width" {
-				if { $opt($id,1,override) == 0 } {set opt($id,1,lbwidth) $val}
+				if { $opt($id,1,override) == 0 } { set ropt($id,1,lbwidth) $val
+				} else { set ropt($id,1,lbwidth) $opt($id,1,lbwidth) }
 			}
 			"hcolor" {
 				# not available in TclTk
@@ -419,103 +419,112 @@
 			}
 			"background" {
 				if { $opt($id,1,override) == 0 } {
-				    if {$val != "none"} {
-    					set opt($id,1,lbackground) [color_grass_to_tcltk $val]
-    				} else {
-    				    set opt($id,1,lbackground) ""
-    				}
+					if {$val != "none"} {
+						set ropt($id,1,lbackground) [color_grass_to_tcltk $val]
+					} else {
+						set ropt($id,1,lbackground) ""
+					}
+				} else {
+					set ropt($id,1,lbackground) $opt($id,1,lbackground)
 				}
 			}
 			"border" {
 				if { $opt($id,1,override) == 0 } {
-				    if {$val != "none"} {
-    					set opt($id,1,lborder) [color_grass_to_tcltk $val]
-    				} else {
-    				    set opt($id,1,lborder) ""
-    				}
+					if {$val != "none"} {
+						set ropt($id,1,lborder) [color_grass_to_tcltk $val]
+					} else {
+						set ropt($id,1,lborder) ""
+					}
+				} else {
+					set ropt($id,1,lborder) $opt($id,1,lborder)
 				}
 			}
 			"opaque" {
-				if { $opt($id,1,override) == 0 } {set opt($id,1,lopaque) $val}
+				if { $opt($id,1,override) == 0 } { set ropt($id,1,lopaque) $val
+				} else { set ropt($id,1,lopaque) $opt($id,1,lopaque) }
 			}
 			"rotate" {
 				# not available in TclTk
 				set x ""
 			}
 			"size"   {
-				if { $opt($id,1,override) == 0 } {set opt($id,1,lwidth) $val}
+				if { $opt($id,1,override) == 0 } { set ropt($id,1,lwidth) $val
+				} else { set ropt($id,1,lwidth) $opt($id,1,lwidth) }
 			}
 			"text" {
-				set opt($id,1,ltxt) [subst -nocommands -novariables $val]
+				set ropt($id,1,ltxt) [subst -nocommands -novariables $val]
+				set ropt($id,1,lfont) $opt($id,1,lfont)
 				
 				# check to see if there are line breaks in the text
-				set newlines [llength [split $opt($id,1,ltxt) "\n"]]
+				set newlines [llength [split $ropt($id,1,ltxt) "\n"]]
 				
 				# create each label when loop gets to a text line in the labels file
 				# Here should be set all font related options, that come from labelfile
-				if {[info exists opt($id,1,lfontsize)]} {
-					font configure $opt($id,1,lfont) -size $opt($id,1,lfontsize)
+				if {[info exists ropt($id,1,lfontsize)]} {
+					font configure $ropt($id,1,lfont) -size $ropt($id,1,lfontsize)
 				}
 				
 				# set the label width and height
-				set linelen [font measure $opt($id,1,lfont) $opt($id,1,ltxt)]
-				if {$linelen < $opt($id,1,lwidth)} {
+				set linelen [font measure $ropt($id,1,lfont) $ropt($id,1,ltxt)]
+				if {$linelen < $ropt($id,1,lwidth)} {
 					set wid [expr $linelen + 2]
-					set lineh [expr $newlines * [font metrics $opt($id,1,lfont) -linespace]]
+					set lineh [expr $newlines * [font metrics $ropt($id,1,lfont) -linespace]]
 				} else {
 					set wid $opt($id,1,lwidth); # This is too wide as wrapped text lines might be shorter.
-					set lineh [expr $newlines * (ceil($linelen/($opt($id,1,lwidth)-15.0)))\
-					 * [font metrics $opt($id,1,lfont) -linespace]]; # Somtimes font measure gives wrong length. -15.0 is a hack.
+					set lineh [expr $newlines * (ceil($linelen/($ropt($id,1,lwidth)-15.0)))\
+					 * [font metrics $ropt($id,1,lfont) -linespace]]; # Somtimes font measure gives wrong length. -15.0 is a hack.
 				}
-				if {!$opt($id,1,lopaque)} {
+				# transparent background
+				if {!$ropt($id,1,lopaque)} {
 					set lbackground ""
-				} else { set lbackground $opt($id,1,lbackground) }
+				} else { set lbackground $ropt($id,1,lbackground) }
+				# no box line
 				if {!$opt($id,1,lboxbenable)} {
 					set wdth 0
-				} else { set wdth $opt($id,1,lbwidth) }
+				} else { set wdth $ropt($id,1,lbwidth) }
 
 				# create box around text
 				
-				switch $opt($id,1,anchor) {
+				switch $ropt($id,1,anchor) {
 					"ne" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}] 
-						set boxcenter_y [expr {$opt($id,1,ycoord) + ($lineh+4) / 2}]
+						set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}] 
+						set boxcenter_y [expr {$ropt($id,1,ycoord) + ($lineh+4) / 2}]
 						}
 					"n" { 
-						set boxcenter_x $opt($id,1,xcoord)
-						set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
+						set boxcenter_x $ropt($id,1,xcoord)
+						set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
 						}
 					"nw" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
-						set boxcenter_y [expr {$opt($id,1,ycoord) + ($lineh+4) / 2}]
+						set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+						set boxcenter_y [expr {$ropt($id,1,ycoord) + ($lineh+4) / 2}]
 						}
 					"e" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}]
-						set boxcenter_y $opt($id,1,ycoord)
+						set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}]
+						set boxcenter_y $ropt($id,1,ycoord)
 						}
 					"center" { 
-						set boxcenter_x $opt($id,1,xcoord)
-						set boxcenter_y $opt($id,1,ycoord)
+						set boxcenter_x $ropt($id,1,xcoord)
+						set boxcenter_y $ropt($id,1,ycoord)
 						}
 					"w" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
-						set boxcenter_y $opt($id,1,ycoord)
+						set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+						set boxcenter_y $ropt($id,1,ycoord)
 						}
 					"se" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) - ($wid-4) / 2}]
-						set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
+						set boxcenter_x [expr {$ropt($id,1,xcoord) - ($wid-4) / 2}]
+						set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
 						}
 					"s" { 
-						set boxcenter_x $opt($id,1,xcoord)
-						set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
+						set boxcenter_x $ropt($id,1,xcoord)
+						set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
 						}
 					"sw" { 
-						set boxcenter_x [expr {$opt($id,1,xcoord) + ($wid-4) / 2}]
-						set boxcenter_y [expr {$opt($id,1,ycoord) - ($lineh+4) / 2}]
+						set boxcenter_x [expr {$ropt($id,1,xcoord) + ($wid-4) / 2}]
+						set boxcenter_y [expr {$ropt($id,1,ycoord) - ($lineh+4) / 2}]
 						}
 					default { 
-						set boxcenter_x $opt($id,1,xcoord)
-						set boxcenter_y $opt($id,1,ycoord)
+						set boxcenter_x $ropt($id,1,xcoord)
+						set boxcenter_y $ropt($id,1,ycoord)
 						}
 				}
 
@@ -527,16 +536,16 @@
 						[expr {$boxcenter_x + $opt($id,1,lhoffset) + $wid / 2}] \
 						[expr {$boxcenter_y + $opt($id,1,lvoffset) + $lineh / 2}]\
 						-width  $wdth \
-						-outline $opt($id,1,lborder) \
+						-outline $ropt($id,1,lborder) \
 						-fill $lbackground
 				}
-				$can($mon) create text $opt($id,1,xcoord) $opt($id,1,ycoord) \
-					-anchor $opt($id,1,anchor) \
+				$can($mon) create text $ropt($id,1,xcoord) $ropt($id,1,ycoord) \
+					-anchor $ropt($id,1,anchor) \
 					-justify $opt($id,1,ljust) \
 					-width $wid \
-					-fill $opt($id,1,lfill) \
-					-font $opt($id,1,lfont) \
-					-text $opt($id,1,ltxt)
+					-fill $ropt($id,1,lfill) \
+					-font $ropt($id,1,lfont) \
+					-text $ropt($id,1,ltxt)
 			} 
 			default {
 				#for anything else, just move on



More information about the grass-commit mailing list