Updated 2014-04-30 10:37:25 by RLE

ulis a(Virtual)ListBox is a Tcl megawidget that displays a virtual list.

The idea of a virtual listbox was evoked in ANNOUNCE: Tk Virtual Listbox, Greg Goodman, comp.lang.tcl, 1995.

I never read the thread before but his description is very close to my design.

The items are virtual and are obtained through a procedure callback when they should be displayed.

  • the list is not fixed and can vary on demand,
  • there can be more virtual items than memory can contain (until 2^30 - 1 items),
  • the items can be memorized to optimize the display,
  • the items can be invalidated to free the memory,
  • a note can be associated with each item.

Download  edit

Virtuallist.zip
documentation is included

See Also  edit

Hugecombo
Hugelist
Lightbutton

Description  edit

2003-09-28: How is it different from a (Tktable) table?

ulis: It's not a multi-columns megawidget but a widget with virtual data (given by a callback).

At the top of the page you can see:

  • the demo with computed items
  • the demo with items from the Web
  • the demo with items from a DB (3 associated virtuallists)

LV: This is quite exciting. ulis, have you considered submitting your widgets to tklib for wider distribution?

ulis: All my packages are under the NOL licence and there is no need for my permission to submit them to tklib.

LV: ulis, while the license would permit the tklib maintainers to make use of your code, the Tcl community mindset is to try their hardest to involve the author in the process of making use of their code.

ulis: Sorry, LV but I'm disengaging from Tcl. ... would you care to share why are you disengaging from Tcl?'

ulis Yes, indeed. I came to Tcl thru Tk: a tool that permits to build portable UI. I discovered with Tcl a coherent language that permits to write scripts almost without documentation and almost without bugs. But my first goal was to define my proper language: "s" as "simple", a coherent and versatile C, C++ avatar that optimizes the programer time (and maybe the computer time in a future version, if needed). I used Tcl to sketch the OOP component (a 4,000 lines package). Now, I hope I payed my debt to Tcl and I feel to be ready to go back to my first goal.

LV: continued: As for the VirtualList, think of things this way. In most cases, a listbox contains a fixed set of data that you obtain up front, storing the values in at least the widget, if not additionally some sort of list variable.

However, with VirtualList, it sounds as if ulis uses callbacks, so that the data need not all be in memory - instead, it is fetched as you scroll further in the list.

Greg Goodman thread
  TK VIRTUAL LISTBOX WIDGET

  A virtual listbox is a listbox that presents an arbitrarily large list
  without keeping the entire list in memory.

  Instead of maintaining all the list entries, the virtual listbox maintains
  a smaller cache of list entries for presentation.  As the listbox's visible
  window moves, the contents of the cache are managed so that the visible
  items are in memory.

  We modified the tkListbox.c source to produce tkVlistbox.c, which
  implements a new Tk command, vlistbox.  The vlistbox command works
  just like the listbox command, except as follows:

  1. There are several additional configuration options.

     -cachesize

        This is the maximum number of elements maintained in memory at any
        one time.  It must be at least as large as the visible number of
        entries.  The default for the cachesize is 100.

     -numelements

        This is the total number of elements in the list.  We need this to
        properly position the thumb of the scrollbar.

        This option is required.

     -getelementcommand

        This is a user-supplied script that supplies the string to be
        displayed at any given position.  The script takes a single
        parameter, a 0-based index.  It returns a list consisting of
        a return code and the string to be displayed at that index.

        the return code is:
           0 (TCL_OK) if everything is ok
           3 (TCL_BREAK) if the string is not available
           1 (TCL_ERROR) in any other case

        If the return code is 0, then the second element of the list
        is the string to be displayed.

        This option is required.

  2. There is an additional widget command, "flush", that tells the
     vlistbox to dump its cache and repopulate it with calls to the user
     script.

  3. There is no insert or delete command.

     These are not necessary, since the list element for every position
     is provided, as needed, by a script.

  4. There is currently no multiple selection.

     We didn't need it right away, and haven't gotten around to it yet.

  To Do List

     1 Add multiple selection
     2 Add some more error handling (like missing required options)
     3 port to Tcl 7.4 / Tk 4.0

  How to get it.

     The virtual listbox package consists of a single source file
     (tkVlistbox.c), this documentation, instructions for installing it,
     and two simple demo scripts.

     For now, I will email a copy to anyone who requests it.  If there is
     enough demand, or when I've done a couple of the items on the
     "To Do List" I'll submit it to alcatel.

  --
  Greg Goodman
  [email protected]
  <URL: http://starbase.neosoft.com/~gregg>