[GRASS-dev] Re: gis.m: font selection in module panels

Paul Kelly paul-grass at stjohnspoint.co.uk
Fri Jul 27 17:30:58 EDT 2007


On Fri, 27 Jul 2007, Paul Kelly wrote:

> On Fri, 27 Jul 2007, Michael Barton wrote:
>
>> OK. I'll wait for your fix. I took a quick look and noted the following
>> behavior.
>> 
>> set default display font to A
>> launch font setting dialog for the barscale panel
>> the barscale font dialog shows A selected
>> select font B for the barscale
>> open the default display font dialog
>> it shows A
>> click OK without clicking on a font in the listbox
>> reopen the default display font dialog
>> it shows B
>> 
>> This suggests to me that there is a variable that is either 1) not getting
>> updated properly when OK is pressed or 2) the list selection is not moving
>> properly to show the selected font.
>
> The attached patch fixes things a little bit (apply to latest CVS, after my 
> updates today), by presetting the dfont variable before calling the select 
> box, so it is pointing at the right font at the start. But it doesn't work 
> 100% yet and the whole thing is a bit complicated. I think binding some 
> events to the OK button instead of the select box change event is part of the 
> solution though.

I've now attached another fix which seems to solve both the problems and 
fix another couple of bugs I found along the way. It uses a further 
separate variable to pass the state of the selection box to the procedure 
that updates the actual global font variables. I hesitate to commit it as 
the syntax may be untidy etc. But if it works and nobody has anything 
better I think we should go ahead with it.

I have only implemented the fix (two extra lines) for the d.histogram and 
d.text panels - it would need to be done for the others that set fonts 
too. Also it would seem logical that these layers inherit the default font 
when initially added, rather than starting with romans, no? That would 
need a further few changes.

Paul
-------------- next part --------------
Index: dtext.tcl
===================================================================
RCS file: /home/grass/grassrepository/grass6/gui/tcltk/gis.m/dtext.tcl,v
retrieving revision 1.15
diff -u -r1.15 dtext.tcl
--- dtext.tcl	27 Jul 2007 14:28:33 -0000	1.15
+++ dtext.tcl	27 Jul 2007 21:23:11 -0000
@@ -110,9 +110,11 @@
 	variable opt
 
 	
+	set Gm::dfont $GmDtext::opt($id,1,font)
 	Gm:DefaultFont dbarscale
 	tkwait variable Gm::dfont
 	set GmDtext::opt($id,1,font) $Gm::dfont
+	set Gm::dfont ""
 
 }
 
Index: gm.tcl
===================================================================
RCS file: /home/grass/grassrepository/grass6/gui/tcltk/gis.m/gm.tcl,v
retrieving revision 1.61
diff -u -r1.61 gm.tcl
--- gm.tcl	27 Jul 2007 14:28:33 -0000	1.61
+++ gm.tcl	27 Jul 2007 21:23:12 -0000
@@ -112,9 +112,8 @@
     variable moncount
     variable prgtext
     variable mainwindow
-    variable dfont 
-    variable fonttype
-    variable fontpath
+    variable dfont
+    variable selectedfont
     variable encoding
 	global array filename # mon
 
@@ -232,8 +231,6 @@
     variable gm_mainframe
     variable tree
 	variable moncount
-	variable fontpath
-	variable fonttype
 	variable dfont
 	variable ecoding
     global gmpath
@@ -246,9 +243,7 @@
     global env
     
     set env(GRASS_RENDER_IMMEDIATE) "TRUE"
-	set fontpath ""
-	set Gm::fonttype "grassfont"
-	set Gm::dfont "romans"
+	set Gm::dfont ""
 	set Gm::encoding "ISO-8859-1"
 
 	set moncount 1
@@ -479,6 +474,7 @@
 	global env iconpath
 	variable dfont
 	variable encoding
+	variable selectedfont
 
 	# create a dialog with selector for stroke font and true type font, and
 	# text entry for character encoding
@@ -502,9 +498,19 @@
     foreach item $fontlist {
     	$fontlb insert end $item
     }
-    
-    if {![catch {set env(GRASS_FONT)}] && $env(GRASS_FONT) != ""} {
-    	set fontindex [lsearch $fontlist $env(GRASS_FONT)]
+
+    # If $Gm::dfont is empty then it hasn't been set by a layer module
+    # before calling this procedure, so we should read the current
+    # default font from the GRASS_FONT environment variable
+    if {$Gm::dfont == ""} {    
+        if {![catch {set env(GRASS_FONT)}] && $env(GRASS_FONT) != ""} {
+	    set Gm::dfont $env(GRASS_FONT)
+	}
+    }
+    set selectedfont $Gm::dfont
+     
+    if {$Gm::dfont != ""} {
+    	set fontindex [lsearch $fontlist $Gm::dfont]
     	if {$fontindex > -1} {
     		$fontlb selection set $fontindex
     		$fontlb see $fontindex
@@ -533,10 +539,10 @@
     pack $row -side bottom -pady 3  -padx 5 -expand 0 -fill x 
     
     bind $fontlb <<ListboxSelect>> {
-    	set Gm::dfont [%W get [%W curselection]]
+	set Gm::selectedfont [%W get [%W curselection]]
     }
-	    
-    
+
+
 };
 
 
@@ -544,6 +550,7 @@
 	global env
 	variable dfont
 	variable encoding
+	variable selectedfont
 
 	# Set GRASS environmental variables for default display font and
 	# character encoding
@@ -551,9 +558,12 @@
 	if { $encoding != "" && $encoding != "ISO-8859-1"} {
 		set env(GRASS_ENCODING) $encoding
 	}
+	
+	set dfont $selectedfont
 
 	if { $source == "menu" && $dfont != "" } {
 		set env(GRASS_FONT) $dfont
+		set dfont ""
 	}
 
 };
Index: histogram.tcl
===================================================================
RCS file: /home/grass/grassrepository/grass6/gui/tcltk/gis.m/histogram.tcl,v
retrieving revision 1.21
diff -u -r1.21 histogram.tcl
--- histogram.tcl	27 Jul 2007 14:28:33 -0000	1.21
+++ histogram.tcl	27 Jul 2007 21:23:13 -0000
@@ -114,9 +114,11 @@
 	variable opt
 
 	
+	set Gm::dfont $GmHist::opt($id,1,font)
 	Gm:DefaultFont dhist
 	tkwait variable Gm::dfont
 	set GmHist::opt($id,1,font) $Gm::dfont
+	set Gm::dfont ""
 
 }
 


More information about the grass-dev mailing list