Ignore:
Timestamp:
Oct 22, 2010, 4:06:10 PM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/dropdownlist.tcl

    r1342 r1929  
    5050itcl::body Rappture::Dropdownlist::constructor {args} {
    5151    itk_component add scroller {
    52         Rappture::Scroller $itk_interior.sc \
    53             -xscrollmode off -yscrollmode auto
     52        Rappture::Scroller $itk_interior.sc \
     53            -xscrollmode off -yscrollmode auto
    5454    }
    5555    pack $itk_component(scroller) -expand yes -fill both
    5656
    5757    itk_component add list {
    58         listbox $itk_component(scroller).list \
    59             -selectmode single -exportselection no \
    60             -highlightthickness 0
     58        listbox $itk_component(scroller).list \
     59            -selectmode single -exportselection no \
     60            -highlightthickness 0
    6161    } {
    62         usual
    63         rename -background -textbackground textBackground Background
    64         rename -foreground -textforeground textForeground Foreground
    65         ignore -highlightthickness -highlightbackground -highlightcolor
    66         keep -relief
     62        usual
     63        rename -background -textbackground textBackground Background
     64        rename -foreground -textforeground textForeground Foreground
     65        ignore -highlightthickness -highlightbackground -highlightcolor
     66        keep -relief
    6767    }
    6868    $itk_component(scroller) contents $itk_component(list)
     
    7777    set i [lsearch $btags [winfo class $itk_component(list)]]
    7878    if {$i < 0} {
    79         set i end
     79        set i end
    8080    }
    8181    set btags [linsert $btags [expr {$i+1}] RapptureDropdownlist-$this]
     
    9595itcl::body Rappture::Dropdownlist::insert {pos args} {
    9696    if {"end" == $pos} {
    97         set pos [llength $_values]
     97        set pos [llength $_values]
    9898    } elseif {![string is integer -strict $pos]} {
    99         error "bad index \"$pos\": should be integer or \"end\""
     99        error "bad index \"$pos\": should be integer or \"end\""
    100100    }
    101101
    102102    if {[llength $args] == 1} {
    103         set args [lindex $args 0]
     103        set args [lindex $args 0]
    104104    }
    105105    if {[llength $args] % 2 != 0} {
    106         error "wrong # args: should be \"insert pos ?value label ...?\""
     106        error "wrong # args: should be \"insert pos ?value label ...?\""
    107107    }
    108108
    109109    foreach {val label} $args {
    110         if {$label == "--"} {
    111             set label $val
    112         }
    113         set _values [linsert $_values $pos $val]
    114         set _labels [linsert $_labels $pos $label]
    115         $itk_component(list) insert $pos $label
    116         incr pos
     110        if {$label == "--"} {
     111            set label $val
     112        }
     113        set _values [linsert $_values $pos $val]
     114        set _labels [linsert $_labels $pos $label]
     115        $itk_component(list) insert $pos $label
     116        incr pos
    117117    }
    118118}
     
    127127itcl::body Rappture::Dropdownlist::delete {first {last ""}} {
    128128    if {$last == ""} {
    129         set last $first
     129        set last $first
    130130    }
    131131    if {![regexp {^[0-9]+|end$} $first]} {
    132         error "bad index \"$first\": should be integer or \"end\""
     132        error "bad index \"$first\": should be integer or \"end\""
    133133    }
    134134    if {![regexp {^[0-9]+|end$} $last]} {
    135         error "bad index \"$last\": should be integer or \"end\""
     135        error "bad index \"$last\": should be integer or \"end\""
    136136    }
    137137
     
    151151    set first [lindex $args 0]
    152152    if {$first == "-value" || $first == "-label"} {
    153         set format $first
    154         set args [lrange $args 1 end]
     153        set format $first
     154        set args [lrange $args 1 end]
    155155    } elseif {[llength $args] > 1} {
    156         error "bad option \"$first\": should be -value or -label"
     156        error "bad option \"$first\": should be -value or -label"
    157157    }
    158158    if {[llength $args] != 1} {
    159         error "wrong # args: should be \"index ?-value? ?-label? string\""
     159        error "wrong # args: should be \"index ?-value? ?-label? string\""
    160160    }
    161161    set value [lindex $args 0]
    162162
    163163    switch -- $format {
    164         -value { return [lsearch -exact $_values $value] }
    165         -label { return [lsearch -exact $_labels $value] }
     164        -value { return [lsearch -exact $_values $value] }
     165        -label { return [lsearch -exact $_labels $value] }
    166166    }
    167167    return -1
     
    180180    set first [lindex $args 0]
    181181    if {[string index $first 0] == "-"} {
    182         set choices {-value -label -both}
    183         if {[lsearch $choices $first] < 0} {
    184             error "bad option \"$first\": should be [join [lsort $choices] {, }]"
    185         }
    186         set format $first
    187         set args [lrange $args 1 end]
     182        set choices {-value -label -both}
     183        if {[lsearch $choices $first] < 0} {
     184            error "bad option \"$first\": should be [join [lsort $choices] {, }]"
     185        }
     186        set format $first
     187        set args [lrange $args 1 end]
    188188    }
    189189
    190190    # return the whole list or just a single value
    191191    if {[llength $args] > 1} {
    192         error "wrong # args: should be \"get ?-value|-label|-both? ?index?\""
     192        error "wrong # args: should be \"get ?-value|-label|-both? ?index?\""
    193193    }
    194194    if {[llength $args] == 0} {
    195         set vlist $_values
    196         set llist $_labels
    197         set op lappend
     195        set vlist $_values
     196        set llist $_labels
     197        set op lappend
    198198    } else {
    199         set i [lindex $args 0]
    200         set vlist [list [lindex $_values $i]]
    201         set llist [list [lindex $_labels $i]]
    202         set op set
     199        set i [lindex $args 0]
     200        set vlist [list [lindex $_values $i]]
     201        set llist [list [lindex $_labels $i]]
     202        set op set
    203203    }
    204204
     
    206206    set rlist ""
    207207    foreach v $vlist l $llist {
    208         switch -- $format {
    209             -value { $op rlist $v }
    210             -label { $op rlist $l }
    211             -both  { lappend rlist $v $l }
    212         }
     208        switch -- $format {
     209            -value { $op rlist $v }
     210            -label { $op rlist $l }
     211            -both  { lappend rlist $v $l }
     212        }
    213213    }
    214214    return $rlist
     
    232232itcl::body Rappture::Dropdownlist::select {option args} {
    233233    if {$option == "set"} {
    234         $itk_component(list) activate [lindex $args 0]
     234        $itk_component(list) activate [lindex $args 0]
    235235    }
    236236    eval $itk_component(list) selection $option $args
     
    246246    set i [$itk_component(list) curselection]
    247247    if {$i != ""} {
    248         switch -- $what {
    249             -value { return [lindex $_values $i] }
    250             -label { return [lindex $_labels $i] }
    251             -both  { return [list [lindex $_values $i] [lindex $_labels $i]] }
    252             default {
    253                 error "bad option \"$what\": should be -value, -label, -both"
    254             }
    255         }
     248        switch -- $what {
     249            -value { return [lindex $_values $i] }
     250            -label { return [lindex $_labels $i] }
     251            -both  { return [list [lindex $_values $i] [lindex $_labels $i]] }
     252            default {
     253                error "bad option \"$what\": should be -value, -label, -both"
     254            }
     255        }
    256256    }
    257257    return ""
     
    271271    set maxw 0
    272272    foreach str $_labels {
    273         set w [font measure $fnt $str]
    274         if {$w > $maxw} { set maxw $w }
     273        set w [font measure $fnt $str]
     274        if {$w > $maxw} { set maxw $w }
    275275    }
    276276    if {$widget != ""} {
    277         if {$maxw < [winfo width $widget]} { set maxw [winfo width $widget] }
     277        if {$maxw < [winfo width $widget]} { set maxw [winfo width $widget] }
    278278    }
    279279    set avg [font measure $fnt "n"]
     
    281281
    282282    if {$widget != ""} {
    283         set y [expr {[winfo rooty $widget]+[winfo height $widget]}]
    284         set h [font metrics $fnt -linespace]
    285         set lines [expr {double([winfo screenheight $widget]-$y)/$h}]
    286         if {[llength $_labels] < $lines} {
    287             $itk_component(list) configure -height [llength $_labels]
    288         } else {
    289             $itk_component(list) configure -height 10
    290         }
     283        set y [expr {[winfo rooty $widget]+[winfo height $widget]}]
     284        set h [font metrics $fnt -linespace]
     285        set lines [expr {double([winfo screenheight $widget]-$y)/$h}]
     286        if {[llength $_labels] < $lines} {
     287            $itk_component(list) configure -height [llength $_labels]
     288        } else {
     289            $itk_component(list) configure -height 10
     290        }
    291291    }
    292292
Note: See TracChangeset for help on using the changeset viewer.