1. Tabular
Tabular is a Tcl/Tk mega-widget for handling tables of data.
It can efficiently manage large data variables,
has a treeview mode for hierarchical data, and supports
multiple images/windows/text/tags per cell.
Tabular also comes with the mini-database applet EdiTbl.tcl
to exercise some of its capabilities. (download here)
2. Features
- Auto-sizing columns for visible cell.
- Interactively resizable columns.
- Sort columns with click on title.
- Column alignment: left, right, center and numeric.
- Columns defined by tab chars providing fast dynamic resizing.
- Support for -variable (array or list) as well as callback commands (eg. sqlite)
- Cell's with any number of text/tags, images and/or windows.
- A tree mode for displaying hierarchical data.
- Good performance with large data sets (eg. 100K+ rows).
- Implementation is pure Tcl ($tk_version >= 8.3).
3. Programming
Programming information is available in the interface specification and auto-documentation, viewing the tests code, or by inspecting the
widget code directly.
Tabular uses two Tk text widgets: one for the
title row and the other for the body or remaining rows in table.
Direct access to
sub-widgets is used to manage tags, text, images, etc,
while minimizing the size of the Tabular API.
4. Cells
A row of cells is simply a line of text where
each cell begins with a pair of tabs "\t\t" and ends with a single tab "\t".
Consequently, cell data containing the characters "\t", "\r" or "\n" is
escaped with a backslash.
Cells in Tabular are indexed using COL,ROW order, ie. as in spreadsheet.
Cell numbering starts from 0, and row 0 contains the column titles (but there are no
row titles).
Tabular can handle large data reasonably well
because it implements dynamic tagging and/or
filling-in of rows as they appear.
Tagging consists of adding the following tags to cells/rows:
#cell #oddrow #oddcol #oddcell #rowNNN #colNNN
5. Variables
The -variable option is intended to provide simple
deferred loading of table data.
Two types of variables are supported: array and list.
5.1 List
A list variable contains column titles in the first element,
and data in the remaining rows.
5.2 Array
A array variable uses the empty element {} to contain
titles. All other elements in the array
are data rows, and these are displayed sorted by the key.
The special case where field names start with a dash - implies
name/value pairs, with -fields containing the names.
This is the same form used by tad, providing
database-like features for arrays (eg. ad-hoc queries).
Simple examples of -variable are:
package require Tabular
# source Tabular.tcl
variable ::x { {A B C} {1 2 3} {4 5 6} }
pack [tabular .tx -variable ::x]
variable ::y
array set ::y { {} {A B C} 0 {1 2 3} 1 {4 5 6} }
pack [tabular .ty -variable ::y]
One issue to be aware of with -variable is that user edits in
Tabular automatically update the variable data. But
changes to the variable do not appear as changes in the widget (unless
the --syncvar option is also used).
6. Tests
Various Tabular tests can be tried out using:
wish Tabular.tcl -test
7. Internal Requirements:
Requirements (except the optional Mod package) are actually included with the package.
- solid.xpm (or write perms in appdir) for cell borders.
- Either Modlite.tcl in appdir, or the package Mod.
- Type checking and query, requires tad.tcl in appdir (if not using Mod).
- Support for sqlite needs the tclsqlite package/library.
- Combo (ie. with -type Choice) falls back to entry/spinbox without Mod.
8. Issues
Column width calculations are not very accurate on really wide columns.
Tcl 8.4 is recommended for Tabular as there are several issues with $tk_version >= 8.5.
The first is that Tk 8.5's text widget displays pathological scrollbar behaviour with
large tables.
Also, [clock scan] about 25 times slower, so if you must use 8.5+ consider
using clockold.
© 2008 Peter MacDonald