Changeset 429


Ignore:
Timestamp:
May 4, 2006, 7:37:34 PM (18 years ago)
Author:
mmc
Message:

Fixed the <choice> input so that each option can have a description
that shows up in a tooltip. Also, added a <value> that can be used
instead of the <label> to represent the current choice.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/zoo/choice/tool.xml

    r69 r429  
    2020      <description>Determines the model for carrier statistics used in bandgap narrowing calculations.</description>
    2121    </about>
    22     <option> <about><label>Boltzmann</label></about> </option>
    23     <option> <about><label>Fermi</label></about> </option>
    24     <option> <about><label>2D Gas</label></about> </option>
     22    <option>
     23      <about>
     24        <label>Boltzmann</label>
     25        <description>From the Boltzmann transport equation</description>
     26      </about>
     27      <value>bte</value>
     28    </option>
     29    <option>
     30      <about>
     31        <label>Fermi</label>
     32        <description>Fermi-Dirac statistics</description>
     33      </about>
     34    </option>
     35    <option>
     36      <about>
     37        <label>2D Gas</label>
     38        <description>Includes confinement at material interface</description>
     39      </about>
     40      <value>2deg</value>
     41    </option>
    2542    <default>Boltzmann</default>
    2643  </choice>
  • trunk/gui/scripts/choiceentry.tcl

    r115 r429  
    3030    private variable _owner ""    ;# thing managing this control
    3131    private variable _path ""     ;# path in XML to this number
     32    private variable _str2val     ;# maps option label => option value
    3233}
    3334
     
    9495        }
    9596        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        }
    97110        return $newval
    98111
     
    104117    # Query the value and return.
    105118    #
    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
    107124}
    108125
     
    145162    # get rid of any existing choices
    146163    $itk_component(choice) choices delete 0 end
     164    catch {unset _str2val}
    147165
    148166    #
     
    202220            # Add the label as-is into the list of choices.
    203221            #
     222            set val [string trim [$_owner xml get $_path.$cname.value]]
    204223            set str [string trim [$_owner xml get $_path.$cname.about.label]]
     224            if {"" == $val} {
     225                set val $str
     226            }
    205227            if {"" != $str} {
     228                set _str2val($str) $val
    206229                $itk_component(choice) choices insert end $_path.$cname $str
    207230                set len [string length $str]
     
    215238    # Assign the default value to this widget, if there is one.
    216239    #
    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    }
    219253}
    220254
     
    242276    set str [$itk_component(choice) value]
    243277    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"
    254285    }
    255286    return $tip
Note: See TracChangeset for help on using the changeset viewer.