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/table.tcl

    r1342 r1929  
    3636itcl::body Rappture::Table::constructor {xmlobj path} {
    3737    if {![Rappture::library isvalid $xmlobj]} {
    38         error "bad value \"$xmlobj\": should be Rappture::library"
     38        error "bad value \"$xmlobj\": should be Rappture::library"
    3939    }
    4040    set _table [$xmlobj element -as object $path]
     
    4545    set _tuples [Rappture::Tuples ::#auto]
    4646    foreach cname [$_table children -type column] {
    47         set label [$_table get $cname.label]
    48         $_tuples column insert end -name $cname -label $label
     47        set label [$_table get $cname.label]
     48        $_tuples column insert end -name $cname -label $label
    4949    }
    5050
     
    5252    set nline 1
    5353    foreach line [split [$_table get data] \n] {
    54         if {[llength $line] == 0} {
    55             continue
    56         }
    57         if {[llength $line] != $cols} {
    58             error "bad data at line $nline: expected $cols columns but got \"[string trim $line]\""
    59         }
    60         $_tuples insert end $line
    61         incr nline
     54        if {[llength $line] == 0} {
     55            continue
     56        }
     57        if {[llength $line] != $cols} {
     58            error "bad data at line $nline: expected $cols columns but got \"[string trim $line]\""
     59        }
     60        $_tuples insert end $line
     61        incr nline
    6262    }
    6363}
     
    8888itcl::body Rappture::Table::columns {args} {
    8989    Rappture::getopts args params {
    90         flag switch -component
    91         flag switch -label default
    92         flag switch -units
     90        flag switch -component
     91        flag switch -label default
     92        flag switch -units
    9393    }
    9494    if {[llength $args] == 0} {
    95         set cols [llength [$_tuples column names]]
    96         set plist ""
    97         for {set i 0} {$i < $cols} {incr i} {
    98             lappend plist $i
    99         }
     95        set cols [llength [$_tuples column names]]
     96        set plist ""
     97        for {set i 0} {$i < $cols} {incr i} {
     98            lappend plist $i
     99        }
    100100    } elseif {[llength $args] == 1} {
    101         set p [lindex $args 0]
    102         if {[string is integer $p]} {
    103             lappend plist $p
    104         } else {
    105             set pos [lsearch -exact [$_tuples column names] $p]
    106             if {$pos < 0} {
    107                 error "bad column \"$p\": should be column name or integer index"
    108             }
    109             lappend plist $pos
    110         }
     101        set p [lindex $args 0]
     102        if {[string is integer $p]} {
     103            lappend plist $p
     104        } else {
     105            set pos [lsearch -exact [$_tuples column names] $p]
     106            if {$pos < 0} {
     107                error "bad column \"$p\": should be column name or integer index"
     108            }
     109            lappend plist $pos
     110        }
    111111    } else {
    112         error "wrong # args: should be \"columns ?-component|-label|-units? ?pos?\""
     112        error "wrong # args: should be \"columns ?-component|-label|-units? ?pos?\""
    113113    }
    114114
    115115    set rlist ""
    116116    switch -- $params(switch) {
    117         -component {
    118             set names [$_tuples column names]
    119             foreach p $plist {
    120                 lappend rlist [lindex $names $p]
    121             }
    122         }
    123         -label {
    124             set names [$_tuples column names]
    125             foreach p $plist {
    126                 set name [lindex $names $p]
    127                 catch {unset opts}
    128                 array set opts [$_tuples column info $name]
    129                 lappend rlist $opts(-label)
    130             }
    131         }
    132         -units {
    133             set names [$_tuples column names]
    134             foreach p $plist {
    135                 set comp [lindex $names $p]
    136                 lappend rlist [$_table get $comp.units]
    137             }
    138         }
     117        -component {
     118            set names [$_tuples column names]
     119            foreach p $plist {
     120                lappend rlist [lindex $names $p]
     121            }
     122        }
     123        -label {
     124            set names [$_tuples column names]
     125            foreach p $plist {
     126                set name [lindex $names $p]
     127                catch {unset opts}
     128                array set opts [$_tuples column info $name]
     129                lappend rlist $opts(-label)
     130            }
     131        }
     132        -units {
     133            set names [$_tuples column names]
     134            foreach p $plist {
     135                set comp [lindex $names $p]
     136                lappend rlist [$_table get $comp.units]
     137            }
     138        }
    139139    }
    140140    return $rlist
     
    152152itcl::body Rappture::Table::values {args} {
    153153    Rappture::getopts args params {
    154         value -row ""
    155         value -column ""
     154        value -row ""
     155        value -column ""
    156156    }
    157157    if {[llength $args] > 0} {
    158         error "wrong # args: should be \"values ?-row r? ?-column c?\""
     158        error "wrong # args: should be \"values ?-row r? ?-column c?\""
    159159    }
    160160    if {"" == $params(-row) && "" == $params(-column)} {
    161         return [$_tuples get]
     161        return [$_tuples get]
    162162    } elseif {"" == $params(-column)} {
    163         return [lindex [$_tuples get $params(-row)] 0]
     163        return [lindex [$_tuples get $params(-row)] 0]
    164164    }
    165165
    166166    if {[string is integer $params(-column)]} {
    167         set col [lindex [$_tuples column names] $params(-column)]
     167        set col [lindex [$_tuples column names] $params(-column)]
    168168    } else {
    169         set col $params(-column)
    170         if {"" == [$_tuples column names $col]} {
    171             error "bad column name \"$col\": should be [join [$_tuples column names] {, }]"
    172         }
     169        set col $params(-column)
     170        if {"" == [$_tuples column names $col]} {
     171            error "bad column name \"$col\": should be [join [$_tuples column names] {, }]"
     172        }
    173173    }
    174174
    175175    if {"" == $params(-row)} {
    176         # return entire column
    177         return [$_tuples get -format $col]
     176        # return entire column
     177        return [$_tuples get -format $col]
    178178    }
    179179    # return a particular cell
     
    192192    set max ""
    193193    foreach v [values -column $column] {
    194         if {"" == $min} {
    195             set min $v
    196             set max $v
    197         } else {
    198             if {$v < $min} { set min $v }
    199             if {$v > $max} { set max $v }
    200         }
     194        if {"" == $min} {
     195            set min $v
     196            set max $v
     197        } else {
     198            if {$v < $min} { set min $v }
     199            if {$v > $max} { set max $v }
     200        }
    201201    }
    202202    return [list $min $max]
     
    212212itcl::body Rappture::Table::hints {{keyword ""}} {
    213213    foreach {key path} {
    214         label   about.label
    215         color   about.color
    216         style   about.style
     214        label   about.label
     215        color   about.color
     216        style   about.style
    217217    } {
    218         set str [$_table get $path]
    219         if {"" != $str} {
    220             set hints($key) $str
    221         }
     218        set str [$_table get $path]
     219        if {"" != $str} {
     220            set hints($key) $str
     221        }
    222222    }
    223223
    224224    if {$keyword != ""} {
    225         if {[info exists hints($keyword)]} {
    226             return $hints($keyword)
    227         }
    228         return ""
     225        if {[info exists hints($keyword)]} {
     226            return $hints($keyword)
     227        }
     228        return ""
    229229    }
    230230    return [array get hints]
Note: See TracChangeset for help on using the changeset viewer.