TIP 576: Poor-mans Table listbox enhancement

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Brian Griffin <briang42@easystreet.net>
State:          Draft
Type:           Project
Created:        25-May-2020
Post-History:   
Keywords:       Tk listbox
Tcl-Version:    8.7
Tk-Version:     8.7

Abstract

Make a small enhancement to the listbox widget to allow convient viewing of a list of lists, as a 2d-table.

Rationale

The listbox widget is an ideal Mode-View-Control implementation that has a low impedence match between Tcl's natural list format, as a model, and a corresponding view/control management for presentation. This allows for convient buisiness logic to perform data manipulations using Tcl's natural data form, without having to transform the data for viewing. However, it is limited to lists of a single dimension. Using 2 dimension, i.e. list of lists, does not results in an optimal display since there is no easy way to control columns of values. This shortcoming can be easily overcome by using multiple instances of a listbox widget and having these widets share the common list variable. If the widgets can share the data, index the data by column, and manage view control from a single master widget, the end result is quick and easy table view.

Specification

This TIP proposes adding 2 options to the listbox widget, "-column" and "-master". The "-column" option defines an index value used to index a row in the list. The listbox already displays each element of the list as a row in the window. The column value would be used to index that row and display only the value of that element from the row. Multiple instances of a listbox can be packed/grided/panewindowed/etc. together to display each column independently. The GUI construction now has the option to display columns in any order, and to even hide columns, maintaining the view independence from the model. The second option, "-master", identifies a single listbox widget as the master control widget for the given listbox. A listbox with a NULL -master value controls itself, as already currently implemented. A listbox that has a master value referencing another listbox widget will register itself with the master widget, and allow the master to perform the view update operations and external callbacks (e.g. scrollbars).

Optionally, additional Tcl scripts could be provided to build the geometry managed collection of columns. For the first cut, however, I am proposing this organization be left up to the end applications to decide.

Alternative consideration

The -column specification could be a range. However, this would require creating a temporary Tcl_Obj containing the sublist, an expense not worth adding to the Display code. The simple index should be a negligable cost because in most cases the index will return a reference to an already existing Tcl_Obj.

Implementation

See the poormans-tablelistbox branch.

Copyright

This document has been placed in the public domain.

History