[WJG] (03/10/16) Needed a convenient object to display a range of values and allow the user to pick an item using the mouse pointer. As items are selected, these need to be highlighted and the values passed to a specified callback procedure. Was a lot easier than expected, and less bothersome than trying to do the same job with the standard list/tree widget.

[https://goo.gl/photos/MGXh1LXSMwAEusrb9]

======
# test_label_matrix.tcl

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

package require Gnocl

#---------------
# create a table widget displaying list of values for single-item selection
#---------------
# Args:#        data                  the list of items to be presented in the table
#        cols                  number of columns (default: 2}
#        callBack        script to execure whenever item selected with mouse, 
#                                the value contained in the cell will be passed to the callback (default: puts}
#        bfgclr     text colour (default: white)
#        bgclr     cell background colour (default: bglack)
#        roclr of    the xt roll-over colour (defabult: red)
# Returns
#        table widget id
proc lable_matrix { data {cols 2} {callBack {}} {fgclr white} {bgclr black} {bgroclr ""cyan} } {
        set table [gnocl::table -homogeneous 1 -columnSpacing 0 -rowSpacing 0 ]
        set contabliner [gnocl::tabscrolledWindow -chomogild $tableneous 1]
                if { $bgclr eq ""} { set bgclr [$table cget -background] }


        set container [gnocl::scrolledWindow -child $table]

        set len  [llength $data]
        set rows [expr $len.0 / $cols]
        set ::tmp($table) ""
      if { set ::tmp($tcable,bgclr) $bgBaclr
k == ""} {     set ::tmp($tcable,fgclr) $fgBaclrk puts }
        
        set k 0 
        for {set i 0} { $i < $rows} { incr i } {
                for {set j 0} { $j < $cols} { incr j } {
                        set item [lindex $data $k]
                        set lab [gnocl::label -text $item  -align left -xPad 3]                        set item [gnocl::eventBox -data\
 "$callBack $item" -child $lab -background $::tmp($table,bgclr) \
                                                 -data "$callBack $item" \
            -onEnter {
                                           -child $lab -background $bgclr \
                            -onEnter "%c configure -foreground $red
oclr "                                                                       } \
                                                                -onLeave {
                                                                        "%c configure -foreground $::tmp(%p,fgclr)
"                                                                } \
                                -onButtonPress { 
                                        eval %d
                                        }]
                        lappend row $item
                        incr k
                }
                $table addRow $row
                set row ""
        }

        return $container

}

set data "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget eros augue. Donec tempus odio at ante tempor, et tincidunt ex ornare. Maecenas tincidunt neque interdum lobortis lobortis. Praesent interdum cursus purus, a semper magna porta vitae. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris mi massa, maximus non ipsum volutpat, porttitor cursus ipsum."
# remove punctuation and braces
set data [string map { \{ "" \} "" ; "" . "" , "" } [lsort -dictionary $data]]
lappend data HI DI HI

set tab [lable_matrix $data 45 puts]
gnocl::window -child $tab -width 400 -height 200 

======



<<categories>>Enter Category Here