tablelist 6.0 - yet another header cellconfigure example

JOB - 2018-01-05 20:54:59

Since tablelist version 6.0 the functionality has been extended to maintain a separate header.

1. Added support for header items (aka title rows) with the aid of the
   new "header", "headerpath", and "headertag" subcommands.
   ...

2. Added the "embed(ttk)checkbutton" and "embed(ttk)checkbuttons"
   subcommands, which provide interactive cell editing with the aid of
   persistently embedded checkbuttons.
   ...

With the following script (which basically was copied over from Csaba Nemethi's tablelist demo section and slightly modified), one can produce the following output:

WikiDBImage tablelist_yet_another_header_cellconfigure_example.png

This example shows a themed ttk::checkbox which perhaps could be used to implement some extra functionality (show/noshow filter, ...)

Here is the modified embeddedWindows_tile.tcl demo code:

set dir [file dirname [info script]]

# where to find required packages:
set auto_path [linsert $auto_path 0 [file join $dir "lib"]]


package require Tk
package require Tablelist_tile


# custom checkbutton style goes here:

set image(checkbox-off) [image create photo -data {
iVBORw0KGgoAAAANSUhEUgAAACMAAAAWCAYAAABKbiVHAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAABGwAAARsAHIJ/VUAAAAB3RJTUUH4AwPFSQzE9atXgAABBZJREFUSMeVVlluIzcQfcWl2a1e
LAWyDRuYr1xlrjA5QuZMyREmR8hFDH/YH7JlybAcaOmFvZD5cMh0S7KUFCBAaBarXtWrhWStxWdi
jPG/vhARjDFgjMEYAyLy+n0dAGCMwVoLIgLnHIyxAx/uG+2D6boOVVWhLMsfq9XqGxHBWot9PcYY
iMg77d+31vrzvt5oNEIYhhRFEYIgAABvl4j+BWOtRdM0yPP863q9/rOua8RxDMYYpJTgnPss1XWN
qqpgjPFAnWNnywXRB2uthZQSWZZ9j+P49yAIBnrkjFVVhe12+16W5QQAlFKYTCbgnEMIMTCotUae
59Bao65r1HUNAAO9fbHWous6AEAYhgjD8K84jn+KosgHIRxvVVV93W63EyLC7e0tpJQH/Lp0KqUg
pURRFFiv12jbduDU1VGfLgCQUvrA67qeGGMsY4yiKPqwbYzBcrm0eZ5DKYWbmxtfdMfA9J3WdQ0p
Jd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AMXRFWHRTb3VyY2VfVVJMAGh0dHA6Ly9jb2RlLmdvb2dsZS5j
b20vcC9nbm9tZS1jb2xvcnMvUB216wAAAABJRU5ErkJggg==
}]


ttk::style element create Custom.Checkbutton.indicator \
        image [list \
                $image(checkbox-off) \
                {disabled selected} $image(checkbox-off) \
                {selected} $image(checkbox-on) \
                {disabled} $image(checkbox-off)]

ttk::style layout Custom.TCheckbutton [list \
        Checkbutton.padding -sticky nswe -children [list \
                Custom.Checkbutton.indicator \
                -side left -sticky {} \
                Checkbutton.focus -side left -sticky w -children { \
                        Checkbutton.label -sticky nswe }]]

ttk::style map Custom.TCheckbutton \
        -background [list active \
        [ttk::style lookup Custom.TCheckbutton -background]]
                
ttk::style configure Custom.TCheckbutton -indicatormargin 0 -takefocus 0



# test code, - copied over from tablelist's demo section -

wm title . "Tile Library Scripts"

#
# Add some entries to the Tk option database
#
set dir [file dirname [info script]]
# source [file join $dir option_tile.tcl]

#
# Create the font TkFixedFont if not yet present
#
catch {font create TkFixedFont -family Courier -size -12}


if {[tablelist::getCurrentTheme] eq "aqua"} {
        #
        # Work around the improper appearance of the tile scrollbars
        #
        interp alias {} ttk::scrollbar {} ::scrollbar
} else {
        #
        # Make the embedded buttons as small as possible.  Recall that in most
        # themes, the tile buttons consist of the following element hierarchy:
        #
        # Button.border
        #     Button.focus              (one of its options is -focusthickness)
        #         Button.padding  (two of its options are -padding and -shiftrelief)
        #             Button.label
        #
        if {[info commands "::ttk::style"] ne ""} {
                interp alias {} styleConfig {} ttk::style configure
        } elseif {[string compare $tile::version "0.7"] >= 0} {
                interp alias {} styleConfig {} style configure
        } else {
                interp alias {} styleConfig {} style default
        }
        styleConfig Embedded.Toolbutton -focusthickness 0 -padding 0 -shiftrelief 0
}

#
# Create a vertically scrolled tablelist widget with 5
# dynamic-width columns and interactive sort capability
#
set tf .tf
ttk::frame $tf -class ScrollArea
set tbl $tf.tbl
set vsb $tf.vsb

tablelist::tablelist $tbl \
                -columns {0 "File Name" left
                        0 "Bar Chart" center
                        0 "File Size" right
                        0 "View"      center
                        0 "Seen"      center} \
                -setgrid no -yscrollcommand [list $vsb set] -width 0

if {[$tbl cget -selectborderwidth] == 0} {
        $tbl configure -spacing 1
}

$tbl columnconfigure 0 -name fileName
$tbl columnconfigure 1 -formatcommand emptyStr -sortmode integer
$tbl columnconfigure 2 -name fileSize -sortmode integer
$tbl columnconfigure 4 -name seen

ttk::scrollbar $vsb -orient vertical -command [list $tbl yview]

proc emptyStr val { return "" }

#
# Create a bold font
#
set tblFont [$tbl cget -font]
set size [font actual $tblFont -size]
if {$size == 0} {                                        ;# e.g., on Ubuntu
        set size -12
}
eval font create BoldFont [font actual $tblFont] -size $size -weight bold

#
# Populate the tablelist widget
#
if {[info exists ttk::library]} {
        cd $ttk::library
} else {
        cd $tile::library
}
set totalSize 0
set maxSize 0
foreach fileName [lsort [glob *.tcl]] {
        set fileSize [file size $fileName]
        $tbl insert end [list $fileName $fileSize $fileSize "" no]
        
        incr totalSize $fileSize
        if {$fileSize > $maxSize} {
                set maxSize $fileSize
        }
}

$tbl header insert 0 [list "[$tbl size] *.tcl files" "" $totalSize "" ""]
$tbl header rowconfigure 0 -foreground "Blue" -background "LightYellow"


#
# Creates a frame widget w to be embedded into the specified cell of the
# tablelist widget tbl, as well as a child frame representing the size of the
# file whose name is diplayed in the first column of the cell's row.
#
proc createFrame {tbl row col w} {
        #
        # Create the frame and replace the binding tag "Frame"
        # with "TablelistBody" in the list of its binding tags
        #
        frame $w -width 102 -height 14 -background ivory -borderwidth 1 \
                        -relief solid
        bindtags $w [lreplace [bindtags $w] 1 1 TablelistBody]
        
        #
        # Create the child frame and replace the binding tag "Frame"
        # with "TablelistBody" in the list of its binding tags
        #
        frame $w.f -height 12 -background red -borderwidth 1 -relief raised
        bindtags $w.f [lreplace [bindtags $w] 1 1 TablelistBody]
        
        #
        # Manage the child frame
        #
        set fileSize [$tbl cellcget $row,fileSize -text]
        place $w.f -relwidth [expr {double($fileSize) / $::maxSize}]
}

#
# Creates a button widget w to be embedded into the specified cell of the
# tablelist widget tbl.
#
proc createButton {tbl row col w} {
        set key [$tbl getkeys $row]
        ttk::button $w \
                -style Embedded.Toolbutton \
                -image $::image(search) \
                -takefocus 0 \
                -command [list viewFile $tbl $key]
}

#
# Displays the content of the file whose name is contained in the row with the
# given key of the tablelist widget tbl.
#
proc viewFile {tbl key} {
        set top .top$key
        if {[winfo exists $top]} {
                raise $top
                return ""
        }
        
        toplevel $top
        set fileName [$tbl cellcget k$key,fileName -text]
        wm title $top "File \"$fileName\""
        
        #
        # Create a vertically scrolled text widget as a grandchild of the toplevel
        #
        set tf $top.tf
        ttk::frame $tf -class ScrollArea
        set txt $tf.txt
        set vsb $tf.vsb
        text $txt -background white -font TkFixedFont -highlightthickness 0 \
                        -setgrid yes -yscrollcommand [list $vsb set]
        catch {$txt configure -tabstyle wordprocessor}        ;# for Tk 8.5 and above
        ttk::scrollbar $vsb -orient vertical -command [list $txt yview]
        
        #
        # Insert the file's content into the text widget
        #
        set chan [open $fileName]
        $txt insert end [read $chan]
        close $chan
        
        set bf $top.bf
        ttk::frame $bf
        set btn [ttk::button $bf.btn -text "Close" -command [list destroy $top]]
        
        #
        # Manage the widgets
        #
        grid $txt -row 0 -column 0 -sticky news
        grid $vsb -row 0 -column 1 -sticky ns
        grid rowconfigure    $tf 0 -weight 1
        grid columnconfigure $tf 0 -weight 1
        pack $btn -pady 10
        pack $bf -side bottom -fill x
        pack $tf -side top -expand yes -fill both
        
        #
        # Mark the file as seen
        #
        $tbl rowconfigure k$key -font BoldFont
        $tbl cellconfigure k$key,seen -text yes
}

#
# Create embedded windows in the columns no. 1 and 3
#
set rowCount [$tbl size]
for {set row 0} {$row < $rowCount} {incr row} {
        $tbl cellconfigure $row,1 -window createFrame -stretchwindow yes
        $tbl cellconfigure $row,3 -window createButton
}

set bf .bf
ttk::frame $bf
set btn [ttk::button $bf.btn -text "Close" -command exit]

#
# Manage the widgets
#
grid $tbl -row 0 -rowspan 2 -column 0 -sticky news
if {[tablelist::getCurrentTheme] eq "aqua"} {
        grid [$tbl cornerpath] -row 0 -column 1 -sticky ew
        grid $vsb -row 1 -column 1 -sticky ns
} else {
        grid $vsb -row 0 -rowspan 2 -column 1 -sticky ns
}
grid rowconfigure    $tf 1 -weight 1
grid columnconfigure $tf 0 -weight 1
pack $btn -pady 10
pack $bf -side bottom -fill x
pack $tf -side top -expand yes -fill both


# -------------------------------------------------------------
# -------------------------------------------------------------

set TESTMODE 1
if {$TESTMODE == 1} {
        catch {console show}
        console eval {wm protocol . WM_DELETE_WINDOW {exit 0}}
        source [file join [file dirname [info script]] "app/ped.tcl"]
}


proc checkButtonCallback {tbl w row col} {
        puts "--> Checkbutton callback arg's: $tbl $w $row $col"
}

proc createHdrButton {tbl row col w} {
                
        ttk::checkbutton $w \
                -style Custom.TCheckbutton \
                -takefocus 0 \
                -command "checkButtonCallback $tbl $w $row $col"
}

# -stretchwindow yes
$tbl header cellconfigure 0,seen -window createHdrButton


# -------------------------------------------------------------
# -------------------------------------------------------------