Changeset 429 for trunk/gui/scripts
- Timestamp:
- May 4, 2006, 7:37:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/choiceentry.tcl
r115 r429 30 30 private variable _owner "" ;# thing managing this control 31 31 private variable _path "" ;# path in XML to this number 32 private variable _str2val ;# maps option label => option value 32 33 } 33 34 … … 94 95 } 95 96 set newval [lindex $args 0] 96 $itk_component(choice) value $newval 97 if {[info exists _str2val($newval)]} { 98 # this is a label -- use it directly 99 $itk_component(choice) value $newval 100 set newval $_str2val($newval) ;# report the actual value 101 } else { 102 # this is a value -- search for corresponding label 103 foreach str [array names _str2val] { 104 if {$_str2val($str) == $newval} { 105 $itk_component(choice) value $str 106 break 107 } 108 } 109 } 97 110 return $newval 98 111 … … 104 117 # Query the value and return. 105 118 # 106 return [$itk_component(choice) value] 119 set str [$itk_component(choice) value] 120 if {[info exists _str2val($str)]} { 121 return $_str2val($str) 122 } 123 return $str 107 124 } 108 125 … … 145 162 # get rid of any existing choices 146 163 $itk_component(choice) choices delete 0 end 164 catch {unset _str2val} 147 165 148 166 # … … 202 220 # Add the label as-is into the list of choices. 203 221 # 222 set val [string trim [$_owner xml get $_path.$cname.value]] 204 223 set str [string trim [$_owner xml get $_path.$cname.about.label]] 224 if {"" == $val} { 225 set val $str 226 } 205 227 if {"" != $str} { 228 set _str2val($str) $val 206 229 $itk_component(choice) choices insert end $_path.$cname $str 207 230 set len [string length $str] … … 215 238 # Assign the default value to this widget, if there is one. 216 239 # 217 set str [$_owner xml get $_path.default] 218 if {"" != $str} { $itk_component(choice) value $str } 240 set defval [$_owner xml get $_path.default] 241 if {"" != $defval} { 242 if {[info exists _str2val($defval)]} { 243 $itk_component(choice) value $defval 244 } else { 245 foreach str [array names _str2val] { 246 if {$_str2val($str) == $defval} { 247 $itk_component(choice) value $str 248 break 249 } 250 } 251 } 252 } 219 253 } 220 254 … … 242 276 set str [$itk_component(choice) value] 243 277 set path [$itk_component(choice) translate $str] 244 245 if {"" != $str} { 246 append tip "\n\n$str:" 247 248 if {$path != ""} { 249 set desc [$_owner xml get $path.description] 250 if {[string length $desc] > 0} { 251 append tip "\n$desc" 252 } 253 } 278 set desc "" 279 if {$path != ""} { 280 set desc [$_owner xml get $path.about.description] 281 } 282 283 if {[string length $str] > 0 && [string length $desc] > 0} { 284 append tip "\n\n$str:\n$desc" 254 285 } 255 286 return $tip
Note: See TracChangeset
for help on using the changeset viewer.