Version 4 of A TclOO megawidget based on tablelist (tabelistbrowser)

Updated 2016-05-08 20:18:57 by JOB

JOB 2016-05-03 Playing with TclOO...

The following code implements a tablelistbrowser megawidget with the aid of TclOO.

WikiDBImage tablelistbrowser_demo.png

The tablelist operates in "browse" mode, if nothing is selected, the content of each table item is shown on the rhs window on the fly. Current selection is handled within the object (and won't get lost, in case something else is going to be selected). Horizontal / vertical view can be toggled interactively. When doing so, current selected tablelist item is kept visible. Binding for keyboard navigation within the tablelist is available (although quite slow).

Found out that:

  • performance under OSX (tablelist with images) is a bit slow ?
  • ttk::panedwindow does not allow to dynamically toggle the orientation e.g. with "<widget> configure -orient "horizontal""
  • tk::panedwindow has to be used instead ?

TclOO:

  • Looks quite promising in respect of megawidget class layout.
  • Used the A TclOO tablelist template as a starting point for the megawidget.

Here is the code - pls. enjoy. Of corse any comments are very welcome!

  * tablelistbrowser.tcl
# -----------------------------------------------------------------------------
# tablelistbrowser.tcl ---
# -----------------------------------------------------------------------------
# (c) 2016, Johann Oberdorfer - Engineering Support | CAD | Software
#     johann.oberdorfer [at] gmail.com
#     www.johann-oberdorfer.eu
# -----------------------------------------------------------------------------
# This source file is distributed under the BSD license.
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#   See the BSD License for more details.
# -----------------------------------------------------------------------------
# Purpose:
#  A TclOO class implementing the tablelistbrowser megawidget.
#  Might be usefull as a starting point.
# -----------------------------------------------------------------------------
# TclOO naming conventions:
# public methods  - starts with lower case declaration names, whereas
# private methods - starts with uppercase naming, so we are going to use CamelCase ...
# -----------------------------------------------------------------------------

# for development: try to find autoscroll, etc ...
# set this_file [file normalize [file dirname [info script]]]
# where to find required packages...
# set auto_path [linsert $auto_path 0 [file join $this_file ".."]]


package require autoscroll
package require tablelist_tile

package provide tablelistbrowser 0.1


# workaround for aqua
if { [tk windowingsystem] eq "aqua" } {
        interp alias {} ttk::scrollbar {} ::scrollbar
}


namespace eval tablelistbrowser {
        variable image_dir
        variable image_file
        
        set this_dir   [file dirname [info script]]
        set image_dir  [file join $this_dir "images"]
        set image_file [file join $this_dir "ImageLib.tcl"]
        
        proc LoadImages {image_dir {patterns {*.gif}}} {
                foreach p $patterns {
                        foreach file [glob -nocomplain -directory $image_dir $p] {
                                set img [file tail [file rootname $file]]
                                if { ![info exists images($img)] } {
                                        set images($img) [image create photo -file $file]
                                }
                        }}
                return [array get images]
        }
        
        # this is a tk-like wrapper around my... class so that
        # object creation works like other tk widgets
        
        proc tablelistbrowser {path args} {
                set obj [obj_tablelist create tmp $path {*}$args]
                # rename oldName newName
                rename $obj ::$path
                return $path
        }
        
        oo::class create obj_tablelist {
                
                variable tblwidget
                variable widgetOptions
                variable widgetCompounds
                
                constructor {path args} {
                        set image_file $::tablelistbrowser::image_file
                        set image_dir $::tablelistbrowser::image_dir
                        
                        # ---------------------------------------------------------------
                        # read images from library file or alternatively one by one
                        # ---------------------------------------------------------------
                        if { [file exists $image_file] } {
                                source $image_file
                                array set widgetCompounds [array get images]
                        } else {
                                array set widgetCompounds [::tablelistbrowser::LoadImages \
                                                [file join $image_dir] {"*.gif" "*.png"}]
                        }
                        # ---------------------------------------------------------------
                        
                        array set widgetCompounds {
                                init_bindings 0
                        }
                        
                        # declaration of all additional widget options
                        array set widgetOptions {
                                -xtabheader  {}
                                -xpaneorient "horizontal"
                                -statusmessagetype ""
                                -statusmessage ""
                        }
                        
                        # we use a frame for this specific widget class
                        set f [ttk::frame $path -class tablelistbrowser]
                        
                        # we must rename the widget command
                        # since it clashes with the object being created
                        set widget ${path}_
                        rename $path $widget
                        
                        my Build $f
                        my configure {*}$args
                }
                
                # add a destructor to clean up the widget
                destructor {
                        set w [namespace tail [self]]
                        catch {bind $w <Destroy> {}}
                        catch {destroy $w}
                }
                
                method cget { {opt "" }  } {
                        my variable tblwidget
                        my variable widgetOptions
                        
                        if { [string length $opt] == 0 } {
                                return [array get widgetOptions]
                        }
                        if { [info exists widgetOptions($opt) ] } {
                                return $widgetOptions($opt)
                        }
                        return [$tblwidget cget $opt]
                }
                
                method configure { args } {
                        my variable tblwidget
                        my variable widgetOptions
                        
                        if {[llength $args] == 0}  {
                                
                                # return all tablelist options
                                set opt_list [$tblwidget configure]
                                
                                # as well as all custom options
                                foreach xopt [array get widgetOptions] {
                                        lappend opt_list $xopt
                                }
                                return $opt_list
                                
                        } elseif {[llength $args] == 1}  {
                                
                                # return configuration value for this option
                                set opt $args
                                if { [info exists widgetOptions($opt) ] } {
                                        return $widgetOptions($opt)
                                }
                                return [$tblwidget cget $opt]
                        }
                        
                        # error checking
                        if {[expr {[llength $args]%2}] == 1}  {
                                return -code error "value for \"[lindex $args end]\" missing"
                        }
                        
                        # process the new configuration options...
                        array set opts $args
                        
                        foreach opt_name [array names opts] {
                                set opt_value $opts($opt_name)
                                
                                # overwrite with new value
                                if { [info exists widgetOptions($opt_name)] } {
                                        set widgetOptions($opt_name) $opt_value
                                }
                                
                                # some options need action from the widgets side
                                switch -- $opt_name {
                                        -xtabheader {
                                                my InitializeTabHeader $opt_value
                                                my AddTextTags
                                        }
                                        -xpaneorient {
                                                my SetPaneOrientation $opt_value
                                        }
                                        -statusmessagetype {
                                                my SetStatusMessageType $opt_value
                                        }
                                        -statusmessage {
                                                my SetStatusMessage $opt_value
                                        }
                                        default {
                                                
                                                # -------------------------------------------------------
                                                # if the configure option wasn't one of our special one's,
                                                # pass control over to the original tablelist widget
                                                # -------------------------------------------------------
                                                
                                                if {[catch {$tblwidget configure $opt_name $opt_value} result]} {
                                                        return -code error $result
                                                }
                                        }
                                }
                        }
                }
                
                # overloaded tablelist method !
                method insert {method args} {
                        my variable tblwidget
                        
                        if {[catch {$tblwidget insert $method {*}$args} result]} {
                                return -code error $result
                        }
                        my modifyColumnImage "init" "unused,0"
                        my EnableMoveoverBindings
                        # my SetStatusMessage "" "item_count"
                        # after 8000 "[namespace code {my SetStatusMessageType}]"
                }
                
                # --------------------------------------------------
                # if the command wasn't one of our special one's,
                # pass control over to the original tablelist widget
                # --------------------------------------------------
                method unknown {method args} {
                        my variable tblwidget
                        # puts ">>>>>>>> $method ::: $args <<<<<<<<<<<<"
                        
                        if {[catch {$tblwidget $method {*}$args} result]} {
                                return -code error $result
                        }
                        return $result
                }
        }
}

# works, but maybe a not so good idea - might clash in the future
# interp alias {} OOD {} oo::define ::tablelistbrowser::obj_tablelist method

# --------------------------------------------------------
# Public Functions / implementation of our new subcommands
# --------------------------------------------------------
oo::define ::tablelistbrowser::obj_tablelist {
        
        method modifyColumnImage {mode cell_reference} {
                my variable tblwidget
                my variable widgetCompounds
                
                # cell_reference is formatted as regular cell reference,
                # which is: "rownum,colnum"
                
                set tmp     [split $cell_reference ","]
                set row_num [lindex $tmp 0]
                set col_num [lindex $tmp 1]
                
                # alternatively we could use:
                # foreach {row_num col_num} [split $cell_reference ","] {}
                
                switch -- $mode {
                        "init" {
                                # setup images for the 1st time
                                set cnt 0
                                foreach item [$tblwidget get 0 end] {
                                        $tblwidget cellconfigure "$cnt,$col_num" \
                                                        -image $widgetCompounds(img_unchecked)
                                        incr cnt
                                }
                        }
                        "toggle_selection" {
                                $tblwidget selection clear 0 end
                                
                                # search for the 1st occurance of img_checked, deselect and continue...
                                set cnt 0
                                foreach item [$tblwidget get 0 end] {
                                        # puts "$cnt,0 ---- $item"
                                        
                                        if {[$tblwidget cellcget "$cnt,$col_num" -image] == $widgetCompounds(img_checked)} {
                                                
                                                $tblwidget cellconfigure "$cnt,$col_num" -image $widgetCompounds(img_unchecked)
                                                $tblwidget rowconfigure $cnt -font {} -foreground {} -background {}
                                                break
                                        }
                                        incr cnt
                                }
                        }
                        "set_selection" {
                                
                                # finally, do our own selection (which isn't lost, once
                                # another "normal" (text-)widget selection is done ...
                                # -----------------------------------------------------
                                
                                # check, if this code can be reached ??!
                                
                                # "DarkRed" / "White"
                                $tblwidget cellconfigure "$row_num,$col_num" -image $widgetCompounds(img_checked)
                                
                                $tblwidget rowconfigure $row_num \
                                                -font APP_FONT_STD_BOLD \
                                                -foreground [ttk::style configure . -selectforeground] \
                                                -background [ttk::style configure . -selectbackground]
                        }
                }
        }
        
        # -----------------------------------------------------------------------------
        # returns row number of current selection
        # or -1 if nothing is selected
        # -----------------------------------------------------------------------------
        method tablelistGetSelectedIndex {{col_num 0}} {
                my variable tblwidget
                my variable widgetCompounds
                
                set cnt 0
                foreach item [$tblwidget get 0 end] {
                        if {[$tblwidget cellcget "$cnt,$col_num" -image] == $widgetCompounds(img_checked)} {
                                return $cnt
                        }
                        incr cnt
                }
                
                return -1
        }
        
        method setSelection {row_num} {
                my variable tblwidget
                
                $tblwidget selection clear 0 end
                my modifyColumnImage "set_selection" "$row_num,0"
                my displayItemInfo "motion" $row_num
        }
        
        # -----------------------------------------------------------------------------
        # -----------------------------------------------------------------------------
        method displayItemInfo {mode rownum} {
                my variable tblwidget
                my variable widgetCompounds
                
                set txt $widgetCompounds(txtwidget)
                
                # manipulate tablelist (if required)
                
                switch -- $mode {
                        "button_pressed" {
                                my modifyColumnImage "toggle_selection" "unused,0"
                                $txt delete 0.0 end
                        }
                        "motion" {}
                }
                
                # show tablelist data item in the text widget
                
                set kwd_list [my cget -xtabheader]
                
                if {[llength $kwd_list] == 0} {
                        return
                }
                
                set maxattr_len [string length [my GetMaxAttributeString $kwd_list]]
                set data [lindex [$tblwidget get $rownum $rownum] 0]
                
                
                $txt configure -state normal
                $txt delete 0.0 end
                
                set cnt 0
                foreach d $data {
                        set descr [lindex [lindex $kwd_list $cnt] 0]
                        
                        if {[string range $descr end end] != ":"} {
                                append descr ":"
                        }
                        
                        while {[string length $descr] < $maxattr_len} {
                                append descr " "
                        }
                        
                        $txt insert end $descr ATTR_NAME
                        
                        if {$cnt == 0} {
                                $txt insert end "$d " ATTR_TXT0
                        } else {
                                $txt insert end "$d " ATTR_TXT1
                        }
                        
                        $txt insert end "\n"
                        
                        incr cnt
                }
                
                $txt configure -state disabled
        }
        
        # --------------------
        # Private Functions...
        # --------------------
        
        method EnableMoveoverBindings {} {
                my variable widgetCompounds
                my variable tblwidget
                
                if {$widgetCompounds(init_bindings) != 0} {
                        return
                }
                
                # select/deselect ButtonRelease
                bind [$tblwidget bodypath] <Button-1> {
                        set x [expr {%x + [winfo x %W]}]
                        set y [expr {%y + [winfo y %W]}]
                        set t [winfo parent %W]
                        
                        set cell [$t nearestcell $x $y]
                        set rownum [lindex [split $cell ","] 0]
                        
                        set oo_my [winfo parent $t]
                        while { [winfo exists $oo_my] } {
                                if { [winfo class $oo_my] == "tablelistbrowser" } { break }
                                set oo_my [winfo parent $oo_my]
                        }
                        
                        if {[llength [set idx [$t curselection]]] != 0 && $idx == $rownum} {
                                
                                $oo_my modifyColumnImage "toggle_selection" "unused,0"
                                
                        } else {
                                $oo_my displayItemInfo "button_pressed" $rownum
                                $oo_my modifyColumnImage "set_selection" "$rownum,0"
                        }
                }
                
                # move-over effect:
                bind [$tblwidget bodypath] <Motion> {+
                        set t [winfo parent %W]
                        set x [expr {%x + [winfo x %W]}]
                        set y [expr {%y + [winfo y %W]}]
                        
                        set cell [$t nearestcell $x $y]
                        set rownum [lindex [split $cell ","] 0]
                        
                        set oo_my [winfo parent $t]
                        
                        # move up hierachy until our own class is reached:
                        # notes:
                        #   - maybe there is a more convinient way to adress a class member function ?
                        #   - pls note that the member function needs to start with lowercase char
                        #     otherwise it's hidden in global namespace
                        
                        while { [winfo exists $oo_my] } {
                                if { [winfo class $oo_my] == "tablelistbrowser" } { break }
                                set oo_my [winfo parent $oo_my]
                        }
                        
                        if {[$oo_my tablelistGetSelectedIndex] == -1} {
                                $t selection clear 0 end
                                $oo_my displayItemInfo "motion" $rownum
                        }
                        
                        focus $t
                        $t configure -activestyle frame
                        $t activate "@$x,$y"
                }
                
                
                # works (but a bit slow):
                
                bind $tblwidget <KeyPress> {
                        set t %W
                        set key %K
                        
                        if { [lsearch {"Up" "Down"} $key] != -1 &&
                                [llength [set idx [$t curselection]]] != 0} {
                                
                                set rownum [lindex $idx 0]
                                set within_bounds 1
                                
                                if {$key == "Up" && $rownum == 0} {
                                        set within_bounds 0
                                } elseif \
                                                {$key == "Up" && $rownum > 0} {
                                                        incr rownum -1
                                                } elseif \
                                                {$key == "Down" && $rownum < [expr {[llength [$t get 0 end]] - 1}] } {
                                                        incr rownum
                                                } else {
                                                        set within_bounds 0
                                                }
                                
                                if {$within_bounds != 0} {
                                        
                                        set oo_my [winfo parent $t]
                                        while { [winfo exists $oo_my] } {
                                                if { [winfo class $oo_my] == "tablelistbrowser" } { break }
                                                set oo_my [winfo parent $oo_my]
                                        }
                                        
                                        # deselect
                                        $oo_my modifyColumnImage "toggle_selection" "unused,0"
                                        
                                        # select & zoom (if required)
                                        $t selection set $rownum $rownum
                                        $t see $rownum
                                        
                                        $oo_my modifyColumnImage "set_selection" "$rownum,0"
                                        $oo_my displayItemInfo "motion" $rownum
                                }
                        }
                }
                
                bind [$tblwidget bodypath] <Leave> {+
                        set t [winfo parent %W]
                        $t configure -activestyle none
                }
                
                set widgetCompounds(init_bindings) 1
        }
        
        
        method InitializeTabHeader {kword_list} {
                my variable tblwidget
                
                set cols ""
                set cnt 0
                foreach i $kword_list {
                        set descr  [lindex $i 0]
                        set visual [lindex $i 1]
                        set orient [lindex $i 2]
                        
                        if {[string length $orient] == 0} {
                                set orient "left"
                        }
                        
                        regsub -all " " $descr "_" descr
                        if {$descr != "..." &&
                                [string range $descr end end] != ":"} {
                                set descr "${descr}:"
                        }
                        
                        # could be either a string or an integer:
                        if {$visual == "hidden"} {
                                set width 20
                        } else {
                                set width $visual
                        }
                        
                        append cols "$width $descr $orient "
                        incr cnt
                }
                
                $tblwidget configure -columns $cols
                
                # hide specific columns as indicated with "hidden" in declaration array
                set cnt 0
                foreach i $kword_list {
                        if {[set width [lindex $i 1]] == "hidden"} {
                                $tblwidget columnconfigure $cnt -hide yes
                        }
                        incr cnt
                }
                
                # expand last *visible* column
                # ----------------------------
                set cnt 0
                set lastcol 0
                # tablelist -columns option are always 3 attributes each...
                foreach {w col pos} [$tblwidget cget -columns] {
                        if {[$tblwidget columncget $cnt -hide] == 0} {set lastcol  $cnt}
                        incr cnt
                }
                if {$lastcol > 0} {
                        $tblwidget configure -stretch $lastcol
                }
        }
        
        
        # type:
        #   controls the image to be displayed, could be one off:
        #     information / warning / error
        method SetStatusMessageType { {msgtype ""} } {
                my variable widgetCompounds
                
                set txt [$widgetCompounds(status_msg) cget -text]
                
                switch -- $msgtype {
                        "information" { set img $widgetCompounds(dialog-information) }
                        "warning"  { set img $widgetCompounds(dialog-warning-2) }
                        "error"    { set img $widgetCompounds(dialog-error-4) }
                        "" - default {
                                set img ""
                                set txt ""
                        }
                }
                
                $widgetCompounds(status_msg) configure -image $img -text $txt -compound left
        }
        
        
        method SetStatusMessage { msg {mode ""} } {
                my variable tblwidget
                my variable widgetCompounds
                
                switch -- $mode {
                        "item_count" {
                                set msg ""
                                set data [$tblwidget get 0 end]
                                
                                # update status message:
                                if {[llength $data] > 0} {
                                        set msg "There "
                                        if {[llength $data] == 1} {
                                                append msg "is [llength $data] item available."
                                        } else {
                                                append msg "are [llength $data] items available."
                                        }
                                }
                        }
                        "" - default {
                                # use msg argument value
                        }
                }
                
                set img [$widgetCompounds(status_msg) cget -image]
                $widgetCompounds(status_msg) configure -image $img -text $msg -compound left
        }
        
        method GetTime {} {
                my variable widgetCompounds
                
                set seconds [clock seconds]
                $widgetCompounds(date) configure -text [clock format $seconds -format "%A %d.%b, %H:%M:%S"]
                
                after 1000 "[namespace code {my GetTime}]"
        }
        
        method Zoom2Selection {} {
                my variable tblwidget
                
                # standard tablelist behaviour
                if {[set idx_lst [$tblwidget curselection]] != {}} {
                        $tblwidget see [lindex $idx_lst 0]
                        return
                }
                
                # 2nd approach in the case our custom selection is set
                set col_num 0
                set cnt 0
                foreach item [$tblwidget get 0 end] {
                        if {[$tblwidget cellcget "$cnt,$col_num" -image] == $widgetCompounds(img_checked)} {
                                $tblwidget see $cnt
                                break
                        }
                        incr cnt
                }
        }

        method SetPaneOrientation {orient} {
                my variable widgetOptions
                my variable widgetCompounds

                set widgetOptions(-xpaneorient) $orient

                switch -- $orient {
                        "horizontal" {
                                set img $widgetCompounds(img_leftright)
                        }
                        "vertical" {
                                set img $widgetCompounds(img_topbottom)
                        }
                }

                $widgetCompounds(pane) configure -orient $orient
                $widgetCompounds(pane_bttn) configure -image $img

                my Zoom2Selection
        }
        
        
        method TogglePaneOrientation {{mode ""}} {
                my variable widgetCompounds
                
                set orient [my cget -xpaneorient]
                
                switch -- $mode {
                        "set_image" {
                                # setup icon images and return

                                if {$orient == "horizontal"} {
                                        set img $widgetCompounds(img_leftright)
                                } else {
                                        set img $widgetCompounds(img_topbottom)
                                }
                        
                                $widgetCompounds(pane_bttn) configure -image $img
                                return
                        }
                        "" - default {
                                # pane toggle mode

                                if {$orient == "horizontal"} {
                                        set orient "vertical"
                                } else {
                                        set orient "horizontal"
                                }

                                my SetPaneOrientation $orient
                        }
                }
        }

        method GetMaxAttributeString {lst} {
                set rstr ""
                foreach item $lst {
                        set str [lindex $item 0]
                        
                        # don't forget to add:
                        append str ": "
                        
                        if {$rstr == ""} {set rstr $str}
                        if {[string length $str] > [string length $rstr]} {set rstr $str}
                }
                return $rstr
        }
        
        method AddTextTags {} {
                my variable widgetCompounds
                my variable tblwidget
                
                set txt $widgetCompounds(txtwidget)
                set lst [my cget -xtabheader]
                
                if {[llength $lst] == 0} {
                        return
                }
                
                set attr_str [my GetMaxAttributeString $lst]
                
                # font metrics:
                # font measure font ?-displayof window? text
                # Measures the amount of space the string text would use in the
                # given font when displayed in window.
                # The return value is the total width in pixels of text.
                
                set margin  [font measure APP_FONT_BIG_BOLD -displayof $txt $attr_str]
                # puts "--> $attr_str : $margin"
                
                # text widget tag definitions
                # ---------------------------
                $txt tag configure ATTR_NAME \
                                -font APP_FONT_STD_BOLD_FIXED -spacing1 5
                
                $txt tag configure ATTR_TXT0 \
                                -font APP_FONT_BIG_BOLD \
                                -foreground "DarkRed"
                
                $txt tag configure ATTR_TXT1 \
                                -font APP_FONT_STD_NORMAL_FIXED \
                                -foreground "DarkBlue" -lmargin2 $margin
        }
        
        
        method Build {frm} {
                my variable widgetCompounds
                my variable tblwidget
                
                set f [ttk::frame $frm.bttn]
                pack $f -fill x -side top
                
                ttk::button $f.bttn \
                                -text "" -compound left \
                                -command "[namespace code {my TogglePaneOrientation}]" \
                                -style Toolbutton
                
                ttk::label $f.date \
                                -text "" \
                                -font APP_FONT_SMALL_NORMAL
                
                pack  $f.bttn $f.date -side right -pady 2
                set widgetCompounds(pane_bttn) $f.bttn
                set widgetCompounds(date) $f.date
                
                # status message
                ttk::label $f.lbl_msg \
                                -text "" -compound left \
                                -font APP_FONT_SMALL_NORMAL
                
                pack $f.lbl_msg -side left -padx 5 -pady 2
                set widgetCompounds(status_msg) $f.lbl_msg
                
                # unused
                # set f [ttk::frame $frm.status]
                # pack $f -fill x -side bottom
                
                set f [ttk::frame $frm.tbl]
                pack $f -fill both -expand true -side bottom
                
                # note: ttk::panedwindow does not allow:
                #       "configure -orient ..." (option is read-only ?!...)
                
                set pane [tk::panedwindow $f.pane \
                                -orient [my cget -xpaneorient] \
                                -sashwidth 5 \
                                -opaqueresize true]
                
                $pane add [set pane_uppr [ttk::frame $frm.pane_uppr]]
                pack $pane -fill both -expand true
                
                $pane add [set pane_lowr [ttk::frame $frm.pane_lowr]]
                
                set widgetCompounds(pane) $pane
                
                bind $f.pane <ButtonRelease-1> "[namespace code {my Zoom2Selection}]"
                bind $f.pane <3> "[namespace code {my TogglePaneOrientation}]"
                
                # ----------------------
                # tablelist goes here...
                # ----------------------
                
                tablelist::tablelist $pane_uppr.tbl \
                                -showseparators yes \
                                -selectmode single \
                                -labelcommand "::tablelist::sortByColumn" \
                                -stretch 2 \
                                -yscrollcommand "$pane_uppr.scrolly set" \
                                -stripebackground "#FDFEFE"
                
                set tblwidget $pane_uppr.tbl
                
                ttk::scrollbar $pane_uppr.scrolly \
                                -command "$pane_uppr.tbl yview" -orient vertical
                
                pack $pane_uppr.scrolly -side right -fill y
                pack $pane_uppr.tbl -side left -fill both -expand true
                autoscroll::autoscroll $pane_uppr.scrolly
                
                # -----------
                # text-widget
                # -----------
                
                text $pane_lowr.txt \
                                -wrap word -height 30 \
                                -yscrollcommand "$pane_lowr.scrolly set"
                
                set widgetCompounds(txtwidget) $pane_lowr.txt
                
                ttk::scrollbar $pane_lowr.scrolly \
                                -command "$pane_lowr.txt yview" -orient vertical
                
                pack $pane_lowr.scrolly -side right -fill y
                pack $pane_lowr.txt -side left -fill both -expand true
                autoscroll::autoscroll $pane_lowr.scrolly
                
                # retrieve option settings from ttk
                $widgetCompounds(txtwidget) configure \
                                -fg [ttk::style configure . -foreground] \
                                -bg [ttk::style configure . -background]
                
                $tblwidget configure \
                                -selectforeground [ttk::style configure . -selectforeground] \
                                -selectbackground [ttk::style configure . -selectbackground]
                
                # ---------------------------
                # initialization starts here:
                # ---------------------------
                
                my TogglePaneOrientation "set_image"
                my GetTime
        }
}

# ---
# eof
# ---
  • ImageLib.tcl
# ImageLib.tcl ---
# Automatically created by: CreateImageLib.tcl

set images(img_unchecked) [image create photo -data {
R0lGODlhDQANAPIFABxRgOLi3erq5vHx7/n5+QAAAAAAAAAAACH5BAEBAAUALAAAAAANAA0AAANk
CAAAgAAAAAgQEYEhIjM4ABGBISIzOAMQgSEiM0hDAIEhIjM4RASAISIyOEREgCAiMzhERIQAIjI4
RESEBCAzOEREhEQAMjhERIREBDA4RESEREQAOENEhEREBAgAAIAAAAAICQA7
}]
set images(img_checked) [image create photo -data {
R0lGODlhDQANAPIGABxRgCGhIeLi3erq5vHx7/n5+AAAAAAAACH5BAEBAAYALAAAAAANAA0AAANk
CAAAgAAAAAggIoIyM0RIACKCMjNESAQggjIzRBhVAIIjM0QYUQWAIjFEGBFVgDATQRgRVYUAMxEY
EVWFBTBEGBFVhVUAREgVVYVVBUBIVVWFVVUASFRVhVVVBQgAAIAAAAAICQA7
}]
set images(img_leftright) [image create photo -data {
iVBORw0KG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6MTg6MjgtMDc6MDAxkbIs
AAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDEwLTAyLTIwVDIzOjI0OjIwLTA3OjAw3nmk+AAAACV0RVh0
ZGF0ZTptb2RpZnkAMjAxMC0wMS0xMVQwODo0Mjo1MS0wNzowML4+k18AAAA1dEVYdExpY2Vuc2UA
aHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvTEdQTC8yLjEvO8G0GAAAACV0RVh0
bW9kaWZ5LWRhdGUAMjAwOS0xMS0yOFQxNDozMTozMS0wNzowMC6hf5AAAAAWdEVYdFNvdXJjZQBD
cnlzdGFsIFByb2plY3Tr4+SLAAAAJ3RFWHRTb3VyY2VfVVJMAGh0dHA6Ly9ldmVyYWxkby5jb20v
Y3J5c3RhbC+lkZNbAAAAAElFTkSuQmCC
}]
  • tablelistbrowser_demo.tcl
# -----------------------------------------------------------------------------
# tablelistbrowser.tcl ---
# -----------------------------------------------------------------------------
# (c) 2016, Johann Oberdorfer - Engineering Support | CAD | Software
#     johann.oberdorfer [at] gmail.com
#     www.johann-oberdorfer.eu
# -----------------------------------------------------------------------------
# This source file is distributed under the BSD license.
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#   See the BSD License for more details.
# -----------------------------------------------------------------------------
# Purpose:
#  A TclOO class template to extend tablelist functionality.
#  Might be usefull as a starting point.
# -----------------------------------------------------------------------------
# TclOO naming conventions:
# public methods  - starts with lower case declaration names, whereas
# private methods - starts with uppercase naming, so we are going to use CamelCase ...
# -----------------------------------------------------------------------------

# for development: try to find autoscroll, etc ...
set this_file [file normalize [file dirname [info script]]]

# where to find required packages...
set auto_path [linsert $auto_path 0 [file join $this_file ".."]]

package require Tk
package require TclOO

package require autoscroll
package require tablelist_tile
package require tablelistbrowser


set fnames [font names]
set fsize  10
set ffamily "Courier"

font create APP_FONT_STD_NORMAL                -family $ffamily -size $fsize -weight normal
font create APP_FONT_STD_BOLD                -family $ffamily -size $fsize -weight bold
font create APP_FONT_SMALL_NORMAL        -family $ffamily -size [expr {$fsize - 2}] -weight normal
font create APP_FONT_BIG_BOLD                -family $ffamily -size [expr {$fsize + 0}] -weight bold

# ---------
# demo code
# ---------
catch {console show}

set t [tablelistbrowser::tablelistbrowser .t \
                        -showseparators yes \
                        -selectmode single  \
                        -labelcommand "tablelist::sortByColumn"]

        pack $t -fill both -expand true

# create some random test data...
set demo "info_procs"
        
switch -- $demo {
        "random" {
                
                set header \
                        {{"ID" 10 left}
                        {"Category"      22 left}
                        {"test-column"   16 left}
                        {"Hello\\nWorld" 10 left}
                        {"test"          "hidden" center}
                        {"last\\ncolumn" 10 left}}

                $t configure \
                        -xtabheader $header

                set data_list {}
                set cnt 0

                while {$cnt < 40} {
                        lappend data_list \
                                [list $cnt \
                                        [expr {$cnt +1}] [expr {$cnt +2}] \
                                        [expr {$cnt +3}] [expr {$cnt +4}] \
                                        [expr {$cnt +5}]]
                        incr cnt
                }

                foreach item $data_list {
                        $t insert end $item
                }
        }
        "info_procs" {

                set header \
                        {{"ID" 10 left}
                        {"Info_Procs" 20 left}
                        {"Body"       hidden left}}

                $t configure \
                        -xtabheader $header \
                        -snipstring "..."
        
                set data_list {}

                set cnt 0
                foreach p [lsort -dictionary [info procs]] {
                        # set body [string map {"\n" " "} [info body $p]]
        
                        set row [list $cnt $p [string trim [info body $p]]]
                        $t insert end $row
                        incr cnt
                }
        }
}

# ---------------------
# object introspection:
# ---------------------

# puts [winfo class $t]
# puts [$t configure]

# catch { [$t blabla 1] } msg
# puts $msg
# return


# puts [$t cget -xtabheader]
        
# how to access the tablelist widget:
# [$t getwidgetpath] configure -columns \
#   "12 Test1 left 12 Test2 left"

# $t selection clear 0 end
# puts [$t curselection]

# $t modifyColumnImage "dummy,0" "init"
  • pkgIndex.tcl
# Tcl package index file, version 1.1
# This file is generated by the "pkg_mkIndex" command
# and sourced either when an application starts up or
# by a "package unknown" script.  It invokes the
# "package ifneeded" command to set up package-related
# information so that packages will be loaded automatically
# in response to "package require" commands.  When this
# script is sourced, the variable $dir must contain the
# full path name of this file's directory.

package ifneeded tablelistbrowser 0.1 [list source [file join $dir tablelistbrowser.tcl]]