tables.gif
Previous Next Top of Manual blank.gif

HTMLgen 2.2.2 Online Documentation

Tables


TWO IMPLEMENTATIONS

There are actually two separate table implementations in HTMLgen now. The first was historically taken from the old HTMLsupport.py function library. It was designed to take a list of lists and construct a table correctly sized to contain the data, and allowed for some limited customization. For general table display it works fine and is named Table in this module.

The newer implementation was a result of feedback I got during the 1.2 beta releases. It is a collection of classes for the lower level table primitives, TD, TR, TH and Caption along with a simple container class called TableLite. I called it TableLite because it does very little for you, (but it does get out of the way). The user is thus responsible for structuring the contents of each row of the table as well as all other heading and border specifications with the appropriate mix of these classes. Although this requires more coding work on the user's part it does provide complete flexibility and control over the table construction. For those with special table needs, building custom classes on top of TableLite and friends may be the favored approach.
N.B.Please be aware though, that this approach can become a performance problem as all the low level elements are implemented as class instances. It'll be at least two times as slow as a more hardwired approach such as Table. (In particular, the start_tag() method is cool from a reuse perspective but is expensive in CPU cycles.)

FEATURES

Table class

The Table class is instantiated with the table's name (which becomes it's caption), and then is tailored with various keyword parameters or direct attribute assignments. Several attributes control alignment, spacing, border characteristics. The default settings result in a table which looks much like the following. Border is set to 2, cell padding is 4, and overall width is 100%. For example the following code was used to generate the next table.

>>> t = HTMLgen.Table('Caption')
>>> h = ['head 1', 'head 2', 'head 3']
>>> t.heading = h
>>> l = ['one', 'two','three']
>>> t.body = [l]
>>> print t

Caption
head 1head 2head 3
one two three

The body attribute contains a list of lists, the length of which determines the number of rows in the table. The heading attribute is just a list of strings and determines the number of columns. The intent behind the Table class is to provide a simple interface using fairly natural Python datatypes as arguments. See the main manual for detailed documentation.

The TableLite class(es)

The TableLite class is a general container class to be populated by instances from the TD, TR, TH, and Caption classes. All these classes inherit from AbstractTag like most other HTML markup classes. AbstractTag supports such things as append, prepend, copy, markup, as well as others. The following is a usage example.

>>> TDlist = map(HTMLgen.TD, ['one', 'two', 'three'])
>>> body = HTMLgen.TR()
>>> body = body + TDlist
>>> THlist = map(HTMLgen.TH, ['head 1', 'head 2', 'head 3'])
>>> heading = HTMLgen.TR()
>>> heading = heading + THlist
>>> cap = HTMLgen.Caption('Caption')
>>> t = HTMLgen.TableLite(border=2, cellpadding=4, cellspacing=1,width="100%")
>>> t.append(cap, heading, body)

This is obviously more complicated but is necessary when using low level classes such as these. Note: the defaults are only what the browser might use; the TableLite class provides no defaults like the Table class.

The examples below use the barchart module to generate tables which use the TableLite class.


System Throughput (jobs/week)
asc1 1352.01352
asc4 1292.01292
asc8 1371.01371
cn1 1472.01472
cn2 1411.01411
dn1 1441.01441
dn2 1381.01381
fddo1 1418.01418
fddo2 1341.01341
fddo3 1280.01280
fddo4 1318.01318
orb3 1390.01390
AVERAGE 1372.0^ 1000.0 lower bound
SCALE: bar-blue.gif = 47.2 units
     Label      value
      asc1       1352
      asc4       1292
      asc8       1371
       cn1       1472
       cn2       1411
       dn1       1441
       dn2       1381
     fddo1       1418
     fddo2       1341
     fddo3       1280
     fddo4       1318
      orb3       1390


System Load
fddo1 3234.014181201490125
fddo2 2820.01341810466203
fddo3 2264.01280560129295
fddo4 2299.01318456235290
AVERAGE 2654.0bar-blue.gif User    bar-red.gif System    bar-yellow.gif I/O    bar-purple.gif Wait   
     Label       User     System        I/O       Wait
     fddo1       1418       1201        490        125
     fddo2       1341        810        466        203
     fddo3       1280        560        129        295
     fddo4       1318        456        235        290


Previous Next Top of Manual blank.gif
Buzz.gif

Copyright © 1996-7 Robin Friedrich
All Rights Reserved
Comments to author: friedrich@pythonpros.com
Generated: Tue Apr 20, 1999