Changeset 875 for trunk


Ignore:
Timestamp:
Feb 9, 2008, 4:40:47 PM (17 years ago)
Author:
dkearney
Message:

fix for boolean inputs to allow the use of yes/no, true/false, on/off, 1/0.
old applications with boolean inputs may need to be be updated to check for
the proper combination instead of the previous default yes/no.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/zoo/boolean/boolean.tcl

    r115 r875  
    1414
    1515set choice [$driver get input.(iimodel).current]
     16$driver put output.boolean(outb).about.label "Echo of boolean value iimodel"
    1617$driver put output.boolean(outb).current $choice
     18
     19set choice1 [$driver get input.(iimodel1).current]
     20$driver put output.boolean(outb1).about.label "Echo of boolean value iimodel1"
     21$driver put output.boolean(outb1).current $choice1
     22
     23set choice2 [$driver get input.(iimodel2).current]
     24$driver put output.boolean(outb2).about.label "Echo of boolean value iimodel2"
     25$driver put output.boolean(outb2).current $choice2
     26
     27set choice3 [$driver get input.(iimodel3).current]
     28$driver put output.boolean(outb3).about.label "Echo of boolean value iimodel3"
     29$driver put output.boolean(outb3).current $choice3
    1730
    1831# save the updated XML describing the run...
  • trunk/examples/zoo/boolean/tool.xml

    r69 r875  
    2020      <description>Used to enable/disable the effects of impact ionization on the mobility model.</description>
    2121    </about>
     22    <default>on</default>
     23  </boolean>
     24  <boolean id="iimodel1">
     25    <about>
     26      <label>Impact Ionization Model</label>
     27      <description>Used to enable/disable the effects of impact ionization on the mobility model.</description>
     28    </about>
    2229    <default>yes</default>
    2330  </boolean>
     31  <boolean id="iimodel2">
     32    <about>
     33      <label>Impact Ionization Model</label>
     34      <description>Used to enable/disable the effects of impact ionization on the mobility model.</description>
     35    </about>
     36    <default>true</default>
     37  </boolean>
     38  <boolean id="iimodel3">
     39    <about>
     40      <label>Impact Ionization Model</label>
     41      <description>Used to enable/disable the effects of impact ionization on the mobility model.</description>
     42    </about>
     43    <default>1</default>
     44  </boolean>
    2445</input>
    25 <output>
    26   <boolean id="outb">
    27     <about><label>Echo of boolean value</label></about>
    28   </boolean>
    29 </output>
    3046</run>
  • trunk/gui/scripts/switch.tcl

    r437 r875  
    4343    protected method _hilite {comp state}
    4444    protected method _presets {option}
     45    protected method _val2boolstr {args}
    4546
    4647    private variable _value "no"  ;# value for this widget
     
    5354    }
    5455}
    55                                                                                
     56
    5657itk::usual Switch {
    5758    keep -cursor -font -foreground -background
     
    6162# ----------------------------------------------------------------------
    6263# CONSTRUCTOR
    63 # ----------------------------------------------------------------------
    64 itcl::body Rappture::Switch::constructor {args} {
     64#   the type is one of the following:
     65#       "yes", "no",
     66#       "true", "false",
     67#       "on", "off",
     68#       "1", "0",
     69#   and determines what text is used as the dropdown options.
     70#   if left empty or is a non-boolean value, type defaults to "no"
     71# ----------------------------------------------------------------------
     72itcl::body Rappture::Switch::constructor {type args} {
    6573    itk_component add icon {
    6674        canvas $itk_interior.icon -borderwidth 0 -highlightthickness 0
     
    7684    }
    7785
     86    set valNumNeg 2
     87    set valNumPos 3
     88    set valTextNeg "no"
     89    set valTextPos "yes"
     90
     91    if { ("" != $type) } {
     92        set _value $type
     93    }
     94
     95    if { ("on" == $_value) || ("off" == $_value) } {
     96        set valNumNeg 4
     97        set valNumPos 5
     98        set valTextNeg "off"
     99        set valTextPos "on"
     100    } elseif { ("true" == $_value) || ("false" == $_value) } {
     101        set valNumNeg 6
     102        set valNumPos 7
     103        set valTextNeg "false"
     104        set valTextPos "true"
     105    } elseif { ("1" == $_value) || ("0" == $_value) } {
     106        # assigning values this way avoids a
     107        # "string is integer -strict" problem in _val2boolstr
     108        set valNumNeg 0
     109        set valNumPos 1
     110        set valTextNeg "0"
     111        set valTextPos "1"
     112    } else {
     113        set _value "no"
     114    }
     115
    78116    itk_component add value {
    79117        label $itk_component(vframe).value -borderwidth 1 -width 7 \
     
    83121    }
    84122    pack $itk_component(value) -side left -expand yes -fill both
    85 
    86     bind $itk_component(value) <Enter> [itcl::code $this _hilite value on]
    87     bind $itk_component(value) <Leave> [itcl::code $this _hilite value off]
    88123
    89124    itk_component add presets {
     
    96131    }
    97132
    98     bind $itk_component(presets) <Enter> [itcl::code $this _hilite presets on]
    99     bind $itk_component(presets) <Leave> [itcl::code $this _hilite presets off]
     133    bind $itk_component(presets) <Enter> [itcl::code $this _hilite presets $valTextPos]
     134    bind $itk_component(presets) <Leave> [itcl::code $this _hilite presets $valTextNeg]
    100135
    101136    itk_component add presetlist {
     
    104139            -unpostcommand [itcl::code $this _presets unpost] \
    105140    }
    106     $itk_component(presetlist) insert end 1 yes 0 no
     141
     142    $itk_component(presetlist) insert end $valNumPos $valTextPos $valNumNeg $valTextNeg
    107143
    108144    bind $itk_component(presetlist) <<DropdownlistSelect>> \
     
    135171
    136172    if {[llength $args] == 1} {
    137         set newval [lindex $args 0]
     173
     174        set newval [_val2boolstr [lindex $args 0]]
    138175        if {![string is boolean -strict $newval]} {
    139176            error "Should be a boolean value"
    140177        }
    141         set newval [expr {($newval) ? "yes" : "no"}]
    142178
    143179        if {$onlycheck} {
     
    152188    }
    153189    return $_value
     190}
     191
     192# ----------------------------------------------------------------------
     193# USAGE: _val2boolstr <val>
     194#
     195# Clients use this to query/set the value for this widget.  With
     196# no args, it returns the current value for the widget.  If the
     197# <newval> is specified, it sets the value of the widget and
     198# sends a <<Value>> event.  If the -check flag is included, the
     199# new value is not actually applied, but just checked for correctness.
     200# ----------------------------------------------------------------------
     201itcl::body Rappture::Switch::_val2boolstr {args} {
     202    set newval ""
     203    if {[llength $args] == 1} {
     204        set val [lindex $args 0]
     205
     206        if {![string is integer -strict $val]} {
     207            return $val
     208        }
     209
     210        if { (2 == $val) || (3 == $val) } {
     211            set newval [expr {($val%2) ? "yes" : "no"}]
     212        } elseif { (4 == $val) || (5 == $val) } {
     213            set newval [expr {($val%2) ? "on" : "off"}]
     214        } elseif { (6 == $val) || (7 == $val) } {
     215            set newval [expr {($val%2) ? "true" : "false"}]
     216        } elseif { (0 == $val) || (1 == $val) } {
     217            set newval [expr {($val%2) ? "1" : "0"}]
     218        }
     219
     220    } elseif {[llength $args] != 0} {
     221        error "wrong # args: should be \"_val2boolstr val\""
     222    }
     223
     224    return $newval
    154225}
    155226
Note: See TracChangeset for help on using the changeset viewer.