
 
 
 
 
 
 
 
 
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.  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
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.)
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
| head 1 | head 2 | head 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 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.
| asc1 | 1352.0 |  | 
| asc4 | 1292.0 |  | 
| asc8 | 1371.0 |  | 
| cn1 | 1472.0 |  | 
| cn2 | 1411.0 |  | 
| dn1 | 1441.0 |  | 
| dn2 | 1381.0 |  | 
| fddo1 | 1418.0 |  | 
| fddo2 | 1341.0 |  | 
| fddo3 | 1280.0 |  | 
| fddo4 | 1318.0 |  | 
| orb3 | 1390.0 |  | 
| AVERAGE | 1372.0 | ^ 1000.0 lower bound SCALE:  =    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
| fddo1 | 3234.0 |     | 
| fddo2 | 2820.0 |     | 
| fddo3 | 2264.0 |     | 
| fddo4 | 2299.0 |     | 
| AVERAGE | 2654.0 |  User  System  I/O  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
 
 
 
 
 
 
 
 
 
Copyright © 1996-7 Robin Friedrich
All Rights Reserved
Comments to author: friedrich@pythonpros.com
Generated: Tue Apr 20, 1999