gnocl::list

A widget which displays items arranged in rows and columns.

Synopsis

gnocl::list [-option value...]

Screenshot


Description

The list widget is basically a tree widget where rows cannot have children. Therefore the list command has the same options as the tree command.

Example

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# change entry colour
#---------------
proc setColor { val } {
    if { $val < 0 } {
        return "-foreground red"
    }
        return "-foreground blue"
}


#---------------
# save the list contents to disk
#---------------
proc save { lst fname } {
   
    set fp [open $fname "w"]
   
    for {set row 0} {$row < [$lst rows]} {incr row} {
        set str ""
        for {set col 0} {$col < [$lst columns]} {incr col} {   
            lappend str [$lst get $row $col ]        ;# get value from single cel, ie row, col
        }
        puts $fp [list $str]
    }
   
    close $fp
}

#---------------
# create UI
#---------------
proc main {} {

set box [gnocl::box -orientation vertical]

set but1 [gnocl::button -icon "%#Save" -onClicked { save $::list lst.txt } ]

set ::list [gnocl::list \
    -titles {"bool" "string" "integer" "float"} \
    -types {boolean string integer float} \
    -children {{1 "box" 345 4.546} {0 "text" 123 5.79}}]

$box add $but1 -fill {0 0} -expand 0 -align left
$box add $::list -fill {1 1} -expand 1

gnocl::window \
    -title "List" \
    -child $box \
    -defaultWidth 250 \
    -defaultHeight 120 \
    -setSize 0.2
}



main

#---------------
# add some values
#---------------

$list add {{0 "list" -104 1.45} {1 "window" 3350 9.58}}
$list columnConfigure 2 \
    -onCellData "setColor %v"


Comments