XTablelist Package

A kind of TclOO code example to show how an existing widget can be extended to add more sub-commands to it.

Purpose

A TclOO class to extend the fabulous tablelist widget.

TclOO naming conventions

  • public methods - starts with lower case declaration names, whereas
  • private methods - starts with uppercase naming, so we use CamelCase …

Widget commands

  • xtablelist::xtablelist

  • xtablelist::configure

  • xtablelist::cget

    xtablelist::xtablelist understands all commands from original tablelist,
    for more sub-command refer as well to the public class interface

    widget options:

    • -xhideoption boolean “yes”,1 / “no”,0 (default: “no”), hide/show a popup-menu which allows to manipulate the tablelist column display

    • -xshowbuttons boolean (default: “no”), show sidebar action buttons to manipulate the tablelist content

    • -xsortoption boolean (default: “no”), hide/show popup-menu to modify tablelist column sort order

    • -xfileread boolean (default: “no”), allows to read-in a previously stored file

    • -xfilesave boolean (default: “no”) allows to saving tablelist data to a file

    • -xfilereadpostcmd file read post command (default: “”) if defined, allows to e.g. set widget state of depending action buttons in the caller program

    • -xdeletepostcmd cmd table entry delete post command (default: “”)

    • -xrefreshpostcmd cmd executed after a delete / refresh action takes place

    • -xselectpostcmd cmd specify a command to be executed after selecting an item in the tablelist (default: “”)

    • -xmoveovereffect boolean (default: “no”), enables visual “move over” effect

Virtual events

  • <<TLExtDataModified>> - delete, modified or sort action took place
  • <<TLExtDataModifiedUndo>> - undo, nothing changed so far!

Demo Code

The following code will produce this GUI:

xtablelist_demo

The tablelist object is decorated with a side iconbar, which allows to manipulate the tablelist content.

show xtablelist_demo.tcl code ...


# -----------------------------------------------------------------------------
# xtablelist_demo.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 use CamelCase ...
# -----------------------------------------------------------------------------

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

# where to find required packages...
set auto_path [linsert $auto_path 0 [file join $dir "."]]
set auto_path [linsert $auto_path 0 [file join $dir "../../00-lib"]]

package require Tk
package require TclOO

package require autoscroll
package require tablelist_tile

package require xtablelist

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

# 1st example:

set t [xtablelist::xtablelist .t \
		-showseparators "yes" \
		-labelcommand "tablelist::sortByColumn" \
		-width 80 -height 10 \
		-xfilesave 1 \
		-xfileread 1 \
		-xshowbuttons 1 \
		-xrefreshpostcmd {puts "Refresh postcommand done."}]

pack $t -fill both -expand true

# maybe some configuration changes later on ...
$t configure \
		-xmoveovereffect "yes"

# create some random test data...

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 +3}] [expr {$cnt +4}] \
			[expr {$cnt +1}] [expr {$cnt +2}] \
			[expr {$cnt +5}]]
	incr cnt
}

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

# 2nd example:

proc SelectPostCmd {t} {

	set sel [$t selection get]
	puts $sel

}

set t1 [xtablelist::xtablelist .t1 \
		-showseparators "yes" \
		-labelcommand "tablelist::sortByColumn" \
		-width 80 -height 10 \
		-xfilesave 1 \
		-xfileread 0 \
		-xshowbuttons 0 \
		-xrefreshpostcmd {puts "Refresh postcommand done."} \
		-xselectpostcmd "SelectPostCmd .t1"]

pack $t1 -fill both -expand true

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

$t1 configure \
		-snipstring "..." \
		-xtabheader $header

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]]]
	$t1 insert end $row
	incr cnt
}

puts "________________"
puts [$t cget -xfilesave]
puts "________________"

puts "________________"
puts [$t1 cget -xfilesave]
puts "________________"

Hint

Some of the options need to be specified when creating the widget and are not fully configurable later on once the widget has been created (open issue to be implemented later on…)

Credits

  • tablelist widget: Copyright (c) 2000-2021 Csaba Nemethi
  • tooltip: Copyright (c) 1996-2007 Jeffrey Hobbs
  • autoscroll: Copyright (c) 2003 Kevin B Kenny
  • icons used from: Open Icon Library

The package can be downloaded from here:

File name:Size / byte:
xtablelist0.4.zip147353