reportlab/platypus/tables.py
author rgbecker
Fri, 09 Aug 2002 11:19:45 +0000
changeset 1699 37fa8717925f
parent 1683 7fa753e4420a
child 1883 eb6f902a0613
permissions -rwxr-xr-x
Improved line styles, allow for cap etc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 421
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 421
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 421
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/tables.py?cvsroot=reportlab
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.62 2002/08/09 11:19:45 rgbecker Exp $
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
     5
__version__=''' $Id: tables.py,v 1.62 2002/08/09 11:19:45 rgbecker Exp $ '''
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 7
diff changeset
     6
__doc__="""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     7
Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     8
row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     9
color and weight of the lines (if any), and the font, alignment and padding of the text.
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    10
327
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    11
None values in the sequence of row heights or column widths, mean that the corresponding rows
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    12
or columns should be automatically sized.
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    13
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    14
All the cell values should be convertible to strings; embedded newline '\\n' characters
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    15
cause the value to wrap (ie are like a traditional linefeed).
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    16
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    17
See the test output from running this module as a script for a discussion of the method for constructing
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    18
tables and table styles.
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    19
"""
906
04370e5a8cfa hacky fix to nudge bug
aaron_watters
parents: 904
diff changeset
    20
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 248
diff changeset
    21
from reportlab.platypus import *
1207
49a514d10cb0 make tables one point off not bomb mysteriously in paid production installations.
aaron_watters
parents: 1169
diff changeset
    22
from reportlab import rl_config
1533
e25c4dda4840 Added emptyTableAction
rgbecker
parents: 1499
diff changeset
    23
from reportlab.lib.styles import PropertySet, getSampleStyleSheet, ParagraphStyle
168
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    24
from reportlab.lib import colors
1103
857af510186d Added identity method to Flowables
rgbecker
parents: 906
diff changeset
    25
from reportlab.lib.utils import fp_str
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
    26
from reportlab.pdfbase import pdfmetrics
312
b39b1a2ed9d5 support explicit \n line splitting in cells
aaron_watters
parents: 268
diff changeset
    27
import operator, string
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    28
421
6dd1e6e707b7 Flowable cell fixes/changes
rgbecker
parents: 420
diff changeset
    29
from types import TupleType, ListType, StringType
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    30
128
a0676f013314 Splitting layout.py
rgbecker
parents: 122
diff changeset
    31
class CellStyle(PropertySet):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    32
    defaults = {
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    33
        'fontname':'Times-Roman',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    34
        'fontsize':10,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    35
        'leading':12,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    36
        'leftPadding':6,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    37
        'rightPadding':6,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    38
        'topPadding':3,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    39
        'bottomPadding':3,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    40
        'firstLineIndent':0,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    41
        'color':colors.black,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    42
        'alignment': 'LEFT',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    43
        'background': (1,1,1),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    44
        'valign': 'BOTTOM',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    45
        }
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    46
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
    47
LINECAPS={'butt':0,'round':1,'projecting':2,'squared':2}
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
    48
LINEJOINS={'miter':0,'round':1,'bevel':2}
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
    49
730
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
    50
# experimental replacement
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
    51
class CellStyle1(PropertySet):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    52
    fontname = "Times-Roman"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    53
    fontsize = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    54
    leading = 12
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    55
    leftPadding = 6
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    56
    rightPadding = 6
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    57
    topPadding = 3
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    58
    bottomPadding = 3
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    59
    firstLineIndent = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    60
    color = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    61
    alignment = 'LEFT'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    62
    background = (1,1,1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    63
    valign = "BOTTOM"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    64
    def __init__(self, name, parent=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    65
        self.name = name
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    66
        if parent is not None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    67
            parent.copy(self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    68
    def copy(self, result=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    69
        if result is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    70
            result = CellStyle1()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    71
        for name in dir(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    72
            setattr(result, name, gettattr(self, name))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    73
        return result
730
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
    74
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
    75
CellStyle = CellStyle1
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
    76
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    77
class TableStyle:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    78
    def __init__(self, cmds=None, parent=None, **kw):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    79
        #handle inheritance from parent first.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    80
        commands = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    81
        if parent:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    82
            # copy the parents list at construction time
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    83
            commands = commands + parent.getCommands()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    84
            self._opts = parent._opts
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    85
        if cmds:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    86
            commands = commands + list(cmds)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    87
        self._cmds = commands
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    88
        self._opts={}
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    89
        self._opts.update(kw)
1435
4d0f57749e18 Added _opts to TableStyle for possible keepWithNext
rgbecker
parents: 1253
diff changeset
    90
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    91
    def add(self, *cmd):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    92
        self._cmds.append(cmd)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    93
    def __repr__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    94
        L = map(repr, self._cmds)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    95
        import string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    96
        L = string.join(L, "  \n")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    97
        return "TableStyle(\n%s\n) # end TableStyle" % L
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    98
    def getCommands(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
    99
        return self._cmds
338
f5eb86d4224f Cosmetics and error testing
rgbecker
parents: 333
diff changeset
   100
f5eb86d4224f Cosmetics and error testing
rgbecker
parents: 333
diff changeset
   101
TableStyleType = type(TableStyle())
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   102
_SeqTypes = (TupleType, ListType)
356
377367fe28cb Table argument order changed
rgbecker
parents: 354
diff changeset
   103
377367fe28cb Table argument order changed
rgbecker
parents: 354
diff changeset
   104
def _rowLen(x):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   105
    return type(x) not in _SeqTypes and 1 or len(x)
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   106
356
377367fe28cb Table argument order changed
rgbecker
parents: 354
diff changeset
   107
221
3d71b66b14c6 Changes related to removal of SimpleFlowDocument
rgbecker
parents: 168
diff changeset
   108
class Table(Flowable):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   109
    def __init__(self, data, colWidths=None, rowHeights=None, style=None,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   110
                repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   111
        #print "colWidths", colWidths
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   112
        self.hAlign = 'CENTER'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   113
        self.vAlign = 'MIDDLE'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   114
        if type(data) not in _SeqTypes:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   115
            raise ValueError, "%s invalid data type" % self.identity()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   116
        self._nrows = nrows = len(data)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   117
        if nrows: self._ncols = ncols = max(map(_rowLen,data))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   118
        elif colWidths: ncols = len(colWidths)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   119
        else: ncols = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   120
        if not emptyTableAction: emptyTableAction = rl_config.emptyTableAction
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   121
        if not (nrows and ncols):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   122
            if emptyTableAction=='error':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   123
                raise ValueError, "%s must have at least a row and column" % self.identity()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   124
            elif emptyTableAction=='indicate':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   125
                self.__class__ = Preformatted
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   126
                global _emptyTableStyle
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   127
                if '_emptyTableStyle' not in globals().keys():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   128
                    _emptyTableStyle = ParagraphStyle('_emptyTableStyle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   129
                    _emptyTableStyle.textColor = colors.red
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   130
                    _emptyTableStyle.backColor = colors.yellow
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   131
                Preformatted.__init__(self,'Table(%d,%d)' % (nrows,ncols), _emptyTableStyle)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   132
            elif emptyTableAction=='ignore':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   133
                self.__class__ = Spacer
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   134
                Spacer.__init__(self,0,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   135
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   136
                raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   137
            return
1533
e25c4dda4840 Added emptyTableAction
rgbecker
parents: 1499
diff changeset
   138
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   139
        if colWidths is None: colWidths = ncols*[None]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   140
        elif len(colWidths) != ncols:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   141
            raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   142
        if rowHeights is None: rowHeights = nrows*[None]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   143
        elif len(rowHeights) != nrows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   144
            raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   145
        for i in range(nrows):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   146
            if len(data[i]) != ncols:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   147
                raise ValueError, "%s not enough data points in row %d!" % (self.identity(),i)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   148
        self._rowHeights = self._argH = rowHeights
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   149
        self._colWidths = self._argW = colWidths
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   150
        self._cellvalues = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   151
##      dflt = CellStyle('<default>')
730
48a169b27fe4 changed handling of table element styles for better space/time. old code left commented
aaron_watters
parents: 684
diff changeset
   152
##
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   153
##      self._cellStyles = [None]*nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   154
##      for i in range(nrows):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   155
##          self._cellStyles[i] = [dflt]*ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   156
        # make unique cell styles for each entry
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   157
        cellrows = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   158
        for i in range(nrows):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   159
            cellcols = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   160
            for j in range(ncols):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   161
                cellcols.append(CellStyle(`(i,j)`))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   162
            cellrows.append(cellcols)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   163
        self._cellStyles = cellrows
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   164
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   165
        self._bkgrndcmds = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   166
        self._linecmds = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   167
        self.repeatRows = repeatRows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   168
        self.repeatCols = repeatCols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   169
        self.splitByRow = splitByRow
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   170
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   171
        if style:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   172
            self.setStyle(style)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   173
    def __repr__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   174
        "incomplete, but better than nothing"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   175
        r = self._rowHeights
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   176
        c = self._colWidths
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   177
        cv = self._cellvalues
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   178
        import pprint, string
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   179
        cv = pprint.pformat(cv)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   180
        cv = string.replace(cv, "\n", "\n  ")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   181
        return "Table(\n rowHeights=%s,\n colWidths=%s,\n%s\n) # end table" % (r,c,cv)
342
a6982189331d Added tables to PythonPoint
andy_robinson
parents: 338
diff changeset
   182
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   183
    def identity(self, maxLen=30):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   184
        '''Identify our selves as well as possible'''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   185
        vx = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   186
        nr = self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   187
        if not hasattr(self,'_ncols'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   188
            nc = 'unknown'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   189
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   190
            nc = self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   191
            cv = self._cellvalues
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   192
            b = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   193
            for i in xrange(nr):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   194
                for j in xrange(nc):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   195
                    v = cv[i][j]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   196
                    t = type(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   197
                    if t in _SeqTypes or isinstance(v,Flowable):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   198
                        if not t in _SeqTypes: v = (v,)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   199
                        r = ''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   200
                        for vij in v:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   201
                            r = vij.identity(maxLen)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   202
                            if r and r[-4:]!='>...':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   203
                                break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   204
                        if r and r[-4:]!='>...':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   205
                            ix, jx, vx, b = i, j, r, 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   206
                    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   207
                        v = v is None and '' or str(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   208
                        ix, jx, vx = i, j, v
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   209
                        b = (vx and t is StringType) and 1 or 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   210
                        if maxLen: vx = vx[:maxLen]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   211
                    if b: break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   212
                if b: break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   213
        if vx:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   214
            vx = ' with cell(%d,%d) containing\n%s' % (ix,jx,repr(vx))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   215
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   216
            vx = '...'
1103
857af510186d Added identity method to Flowables
rgbecker
parents: 906
diff changeset
   217
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   218
        return "<%s at %d %d rows x %s cols>%s" % (self.__class__.__name__, id(self), nr, nc, vx)
1103
857af510186d Added identity method to Flowables
rgbecker
parents: 906
diff changeset
   219
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   220
    def _listCellGeom(self, V,w,s,W=None,H=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   221
        aW = w-s.leftPadding-s.rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   222
        t = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   223
        w = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   224
        canv = getattr(self,'canv',None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   225
        for v in V:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   226
            vw, vh = v.wrapOn(canv,aW, 72000)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   227
            if W is not None: W.append(vw)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   228
            if H is not None: H.append(vh)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   229
            w = max(w,vw)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   230
            t = t + vh + v.getSpaceBefore()+v.getSpaceAfter()
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   231
        return w, t - V[0].getSpaceBefore()-V[-1].getSpaceAfter()
1492
612646d068ca Ensure canv is set on sub flowables
rgbecker
parents: 1488
diff changeset
   232
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   233
    def _calc_width(self):
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   234
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   235
        W = self._argW
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   236
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   237
        canv = getattr(self,'canv',None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   238
        saved = None
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   239
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   240
        if None in W:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   241
            W = W[:]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   242
            self._colWidths = W
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   243
            while None in W:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   244
                j = W.index(None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   245
                f = lambda x,j=j: operator.getitem(x,j)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   246
                V = map(f,self._cellvalues)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   247
                S = map(f,self._cellStyles)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   248
                w = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   249
                i = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   250
                for v, s in map(None, V, S):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   251
                    i = i + 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   252
                    t = type(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   253
                    if t in _SeqTypes or isinstance(v,Flowable):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   254
                        raise ValueError, "Flowable %s in cell(%d,%d) can't have auto width\n%s" % (v.identity(30),i,j,self.identity(30))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   255
                    elif t is not StringType: v = v is None and '' or str(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   256
                    v = string.split(v, "\n")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   257
                    t = s.leftPadding+s.rightPadding + max(map(lambda a, b=s.fontname,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   258
                                c=s.fontsize,d=pdfmetrics.stringWidth: d(a,b,c), v))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   259
                    if t>w: w = t   #record a new maximum
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   260
                W[j] = w
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   261
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   262
        width = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   263
        self._colpositions = [0]        #index -1 is right side boundary; we skip when processing cells
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   264
        for w in W:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   265
            #print w, width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   266
            width = width + w
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   267
            self._colpositions.append(width)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   268
        #print "final width", width
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   269
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   270
        self._width = width
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   271
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   272
    def _calc_height(self):
333
a9e94b0832a4 Fix auto hieght stuff
rgbecker
parents: 329
diff changeset
   273
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   274
        H = self._argH
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   275
        W = self._argW
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   276
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   277
        canv = getattr(self,'canv',None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   278
        saved = None
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   279
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   280
        if None in H:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   281
            if canv: saved = canv._fontname, canv._fontsize, canv._leading
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   282
            H = H[:]    #make a copy as we'll change it
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   283
            self._rowHeights = H
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   284
            while None in H:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   285
                i = H.index(None)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   286
                V = self._cellvalues[i] # values for row i
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   287
                S = self._cellStyles[i] # styles for row i
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   288
                h = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   289
                j = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   290
                for v, s, w in map(None, V, S, W): # value, style, width (lengths must match)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   291
                    j = j + 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   292
                    t = type(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   293
                    if t in _SeqTypes or isinstance(v,Flowable):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   294
                        if not t in _SeqTypes: v = (v,)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   295
                        if w is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   296
                            raise ValueError, "Flowable %s in cell(%d,%d) can't have auto width in\n%s" % (v[0].identity(30),i,j,self.identity(30))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   297
                        if canv: canv._fontname, canv._fontsize, canv._leading = s.fontname, s.fontsize, s.leading or 1.2*s.fontsize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   298
                        dW,t = self._listCellGeom(v,w,s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   299
                        if canv: canv._fontname, canv._fontsize, canv._leading = saved
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   300
                        #print "leftpadding, rightpadding", s.leftPadding, s.rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   301
                        dW = dW + s.leftPadding + s.rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   302
                        if not rl_config.allowTableBoundsErrors and dW>w:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   303
                            raise "LayoutError", "Flowable %s (%sx%s points) too wide for cell(%d,%d) (%sx* points) in\n%s" % (v[0].identity(30),fp_str(dW),fp_str(t),i,j, fp_str(w), self.identity(30))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   304
                    else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   305
                        if t is not StringType:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   306
                            v = v is None and '' or str(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   307
                        v = string.split(v, "\n")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   308
                        t = s.leading*len(v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   309
                    t = t+s.bottomPadding+s.topPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   310
                    if t>h: h = t   #record a new maximum
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   311
                H[i] = h
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   312
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   313
        height = self._height = reduce(operator.add, H, 0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   314
        #print "height, H", height, H
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   315
        self._rowpositions = [height]    # index 0 is actually topline; we skip when processing cells
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   316
        for h in H:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   317
            height = height - h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   318
            self._rowpositions.append(height)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   319
        assert abs(height)<1e-8, 'Internal height error'
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   320
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   321
    def _calc(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   322
        if hasattr(self,'_width'): return
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   323
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   324
        # calculate the full table height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   325
        self._calc_height()
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   326
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   327
        # if the width has already been calculated, don't calculate again
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   328
        # there's surely a better, more pythonic way to short circuit this FIXME FIXME
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   329
        if hasattr(self,'_width_calculated_once'): return
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   330
        self._width_calculated_once = 1
1596
753865895a6f Jim Kraai's patch to preserve auto col width on subsequent pages
andy_robinson
parents: 1536
diff changeset
   331
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   332
        # calculate the full table width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   333
        self._calc_width()
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   334
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   335
    def setStyle(self, tblstyle):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   336
        if type(tblstyle) is not TableStyleType:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   337
            tblstyle = TableStyle(tblstyle)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   338
        for cmd in tblstyle.getCommands():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   339
            self._addCommand(cmd)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   340
        for k,v in tblstyle._opts.items():
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   341
            setattr(self,k,v)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   342
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   343
    def _addCommand(self,cmd):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   344
        if cmd[0] == 'BACKGROUND':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   345
            self._bkgrndcmds.append(cmd)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   346
        elif _isLineCommand(cmd):
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   347
            # we expect op, start, stop, weight, colour, cap, dashes, join
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   348
            cmd = tuple(cmd)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   349
            if len(cmd)<5: raise ValueError('bad line command '+str(cmd))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   350
            if len(cmd)<6: cmd = cmd+(1,)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   351
            else:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   352
                cap = cmd[5]
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   353
                try:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   354
                    if type(cap) is not type(int):
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   355
                        cap = LINECAPS[cap]
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   356
                    elif cap<0 or cap>2:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   357
                        raise ValueError
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   358
                    cmd = cmd[:5]+(cap,)+cmd[6:]
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   359
                except:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   360
                    ValueError('Bad cap value %s in %s'%(cap,str(cmd)))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   361
            if len(cmd)<7: cmd = cmd+(None,)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   362
            if len(cmd)<8: cmd = cmd+(1,)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   363
            else:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   364
                join = cmd[7]
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   365
                try:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   366
                    if type(join) is not type(int):
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   367
                        join = LINEJOINS[cap]
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   368
                    elif join<0 or join>2:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   369
                        raise ValueError
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   370
                    cmd = cmd[:7]+(join,)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   371
                except:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   372
                    ValueError('Bad join value %s in %s'%(join,str(cmd)))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   373
            self._linecmds.append(cmd)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   374
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   375
            (op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   376
            if sc < 0: sc = sc + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   377
            if ec < 0: ec = ec + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   378
            if sr < 0: sr = sr + self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   379
            if er < 0: er = er + self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   380
            for i in range(sr, er+1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   381
                for j in range(sc, ec+1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   382
                    _setCellStyle(self._cellStyles, i, j, op, values)
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   383
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   384
    def _drawLines(self):
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   385
        ccap, cdash, cjoin = None, None, None
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   386
        self.canv.saveState()
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   387
        for op, (sc, sr), (ec, er), weight, color, cap, dash, join in self._linecmds:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   388
            if sc < 0: sc = sc + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   389
            if ec < 0: ec = ec + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   390
            if sr < 0: sr = sr + self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   391
            if er < 0: er = er + self._nrows
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   392
            if ccap!=cap:
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   393
                self.canv.setLineCap(cap)
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   394
                ccap = cap
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   395
            getattr(self,_LineOpMap.get(op, '_drawUnknown' ))( (sc, sr), (ec, er), weight, color)
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   396
        self.canv.restoreState()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   397
        self._curcolor = None
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 221
diff changeset
   398
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   399
    def _drawUnknown(self,  (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   400
        raise ValueError, "Unknown line command '%s'" % op
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   401
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   402
    def _drawGrid(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   403
        self._drawBox( (sc, sr), (ec, er), weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   404
        self._drawInnerGrid( (sc, sr), (ec, er), weight, color)
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   405
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   406
    def _drawBox(self,  (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   407
        self._drawHLines((sc, sr), (ec, sr), weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   408
        self._drawHLines((sc, er+1), (ec, er+1), weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   409
        self._drawVLines((sc, sr), (sc, er), weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   410
        self._drawVLines((ec+1, sr), (ec+1, er), weight, color)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   411
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   412
    def _drawInnerGrid(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   413
        self._drawHLines((sc, sr+1), (ec, er), weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   414
        self._drawVLines((sc+1, sr), (ec, er), weight, color)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   415
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   416
    def _prepLine(self, weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   417
        if color != self._curcolor:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   418
            self.canv.setStrokeColor(color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   419
            self._curcolor = color
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   420
        if weight != self._curweight:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   421
            self.canv.setLineWidth(weight)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   422
            self._curweight = weight
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   423
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   424
    def _drawHLines(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   425
        ecp = self._colpositions[sc:ec+2]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   426
        rp = self._rowpositions[sr:er+1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   427
        if len(ecp)<=1 or len(rp)<1: return
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   428
        self._prepLine(weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   429
        scp = ecp[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   430
        ecp = ecp[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   431
        for rowpos in rp:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   432
            self.canv.line(scp, rowpos, ecp, rowpos)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   433
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   434
    def _drawHLinesB(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   435
        self._drawHLines((sc, sr+1), (ec, er+1), weight, color)
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   436
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   437
    def _drawVLines(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   438
        erp = self._rowpositions[sr:er+2]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   439
        cp  = self._colpositions[sc:ec+1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   440
        if len(erp)<=1 or len(cp)<1: return
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   441
        self._prepLine(weight, color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   442
        srp = erp[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   443
        erp = erp[-1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   444
        for colpos in cp:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   445
            self.canv.line(colpos, srp, colpos, erp)
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   446
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   447
    def _drawVLinesA(self, (sc, sr), (ec, er), weight, color):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   448
        self._drawVLines((sc+1, sr), (ec+1, er), weight, color)
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   449
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   450
    def wrap(self, availWidth, availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   451
        self._calc()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   452
        #nice and easy, since they are predetermined size
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   453
        self.availWidth = availWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   454
        return (self._width, self._height)
1495
fd32c1794998 Propagate font properties to Flowable cells
rgbecker
parents: 1492
diff changeset
   455
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   456
    def onSplit(self,T,byRow=1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   457
        '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   458
        This method will be called when the Table is split.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   459
        Special purpose tables can override to do special stuff.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   460
        '''
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   461
        pass
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   462
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   463
    def _cr_0(self,n,cmds):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   464
        for c in cmds:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   465
            c = tuple(c)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   466
            (sc,sr), (ec,er) = c[1:3]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   467
            if sr>=n: continue
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   468
            if er>=n: er = n-1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   469
            self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   470
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   471
    def _cr_1_1(self,n,repeatRows, cmds):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   472
        for c in cmds:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   473
            c = tuple(c)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   474
            (sc,sr), (ec,er) = c[1:3]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   475
            if sr>=0 and sr>=repeatRows and sr<n and er>=0 and er<n: continue
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   476
            if sr>=repeatRows and sr<n: sr=repeatRows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   477
            elif sr>=repeatRows and sr>=n: sr=sr+repeatRows-n
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   478
            if er>=repeatRows and er<n: er=repeatRows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   479
            elif er>=repeatRows and er>=n: er=er+repeatRows-n
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   480
            self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   481
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   482
    def _cr_1_0(self,n,cmds):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   483
        for c in cmds:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   484
            c = tuple(c)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   485
            (sc,sr), (ec,er) = c[1:3]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   486
            if er>=0 and er<n: continue
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   487
            if sr>=0 and sr<n: sr=0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   488
            if sr>=n: sr = sr-n
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   489
            if er>=n: er = er-n
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   490
            self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:])
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   491
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   492
    def _splitRows(self,availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   493
        h = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   494
        n = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   495
        lim = len(self._rowHeights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   496
        while n<lim:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   497
            hn = h + self._rowHeights[n]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   498
            if hn>availHeight: break
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   499
            h = hn
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   500
            n = n + 1
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   501
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   502
        if n<=self.repeatRows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   503
            return []
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   504
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   505
        if n==lim: return [self]
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   506
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   507
        repeatRows = self.repeatRows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   508
        repeatCols = self.repeatCols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   509
        splitByRow = self.splitByRow
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   510
        data = self._cellvalues
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   511
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   512
        #we're going to split into two superRows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   513
        #R0 = Table( data[:n], self._argW, self._argH[:n],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   514
        R0 = Table( data[:n], self._colWidths, self._argH[:n],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   515
                repeatRows=repeatRows, repeatCols=repeatCols,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   516
                splitByRow=splitByRow)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   517
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   518
        #copy the styles and commands
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   519
        R0._cellStyles = self._cellStyles[:n]
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   520
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   521
        A = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   522
        # hack up the line commands
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   523
        for op, (sc, sr), (ec, er), weight, color, cap, dash, join in self._linecmds:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   524
            if sc < 0: sc = sc + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   525
            if ec < 0: ec = ec + self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   526
            if sr < 0: sr = sr + self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   527
            if er < 0: er = er + self._nrows
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   528
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   529
            if op in ('BOX','OUTLINE','GRID'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   530
                if sr<n and er>=n:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   531
                    # we have to split the BOX
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   532
                    A.append(('LINEABOVE',(sc,sr), (ec,sr), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   533
                    A.append(('LINEBEFORE',(sc,sr), (sc,er), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   534
                    A.append(('LINEAFTER',(ec,sr), (ec,er), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   535
                    A.append(('LINEBELOW',(sc,er), (ec,er), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   536
                    if op=='GRID':
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   537
                        A.append(('LINEBELOW',(sc,n-1), (ec,n-1), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   538
                        A.append(('LINEABOVE',(sc,n), (ec,n), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   539
                        A.append(('INNERGRID',(sc,sr), (ec,er), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   540
                else:
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   541
                    A.append((op,(sc,sr), (ec,er), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   542
            elif op in ('INNERGRID','LINEABOVE'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   543
                if sr<n and er>=n:
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   544
                    A.append(('LINEBELOW',(sc,n-1), (ec,n-1), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   545
                    A.append(('LINEABOVE',(sc,n), (ec,n), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   546
                A.append((op,(sc,sr), (ec,er), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   547
            elif op == 'LINEBELOW':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   548
                if sr<n and er>=(n-1):
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   549
                    A.append(('LINEABOVE',(sc,n), (ec,n), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   550
                A.append((op,(sc,sr), (ec,er), weight, color))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   551
            elif op == 'LINEABOVE':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   552
                if sr<=n and er>=n:
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   553
                    A.append(('LINEBELOW',(sc,n-1), (ec,n-1), weight, color, cap, dash, join))
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   554
                A.append((op,(sc,sr), (ec,er), weight, color, cap, dash, join))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   555
            else:
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   556
                A.append((op,(sc,sr), (ec,er), weight, color, cap, dash, join))
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   557
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   558
        R0._cr_0(n,A)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   559
        R0._cr_0(n,self._bkgrndcmds)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   560
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   561
        if repeatRows:
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   562
            #R1 = Table(data[:repeatRows]+data[n:],self._argW,
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   563
            R1 = Table(data[:repeatRows]+data[n:],self._colWidths,
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   564
                    self._argH[:repeatRows]+self._argH[n:],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   565
                    repeatRows=repeatRows, repeatCols=repeatCols,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   566
                    splitByRow=splitByRow)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   567
            R1._cellStyles = self._cellStyles[:repeatRows]+self._cellStyles[n:]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   568
            R1._cr_1_1(n,repeatRows,A)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   569
            R1._cr_1_1(n,repeatRows,self._bkgrndcmds)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   570
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   571
            #R1 = Table(data[n:], self._argW, self._argH[n:],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   572
            R1 = Table(data[n:], self._colWidths, self._argH[n:],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   573
                    repeatRows=repeatRows, repeatCols=repeatCols,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   574
                    splitByRow=splitByRow)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   575
            R1._cellStyles = self._cellStyles[n:]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   576
            R1._cr_1_0(n,A)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   577
            R1._cr_1_0(n,self._bkgrndcmds)
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   578
1498
2e7cfa1159cb Copy alignments accross split (thanks R�diger M�hl <ruediger.maehl@web.de>
rgbecker
parents: 1495
diff changeset
   579
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   580
        R0.hAlign = R1.hAlign = self.hAlign
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   581
        R0.vAlign = R1.vAlign = self.vAlign
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   582
        self.onSplit(R0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   583
        self.onSplit(R1)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   584
        return [R0,R1]
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   585
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   586
    def split(self, availWidth, availHeight):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   587
        self._calc()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   588
        if self.splitByRow:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   589
            if self._width>availWidth: return []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   590
            return self._splitRows(availHeight)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   591
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   592
            raise NotImplementedError
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   593
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   594
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   595
        self._curweight = self._curcolor = self._curcellstyle = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   596
        self._drawBkgrnd()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   597
        self._drawLines()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   598
        for row, rowstyle, rowpos, rowheight in map(None, self._cellvalues, self._cellStyles, self._rowpositions[1:], self._rowHeights):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   599
            for cellval, cellstyle, colpos, colwidth in map(None, row, rowstyle, self._colpositions[:-1], self._colWidths):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   600
                self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight))
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   601
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   602
    def _drawBkgrnd(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   603
        nrows = self._nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   604
        ncols = self._ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   605
        for cmd, (sc, sr), (ec, er), arg in self._bkgrndcmds:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   606
            if sc < 0: sc = sc + ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   607
            if ec < 0: ec = ec + ncols
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   608
            if sr < 0: sr = sr + nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   609
            if er < 0: er = er + nrows
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   610
            x0 = self._colpositions[sc]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   611
            y0 = self._rowpositions[sr]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   612
            x1 = self._colpositions[min(ec+1,ncols)]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   613
            y1 = self._rowpositions[min(er+1,nrows)]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   614
            w, h = x1-x0, y1-y0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   615
            canv = self.canv
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   616
            if callable(arg):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   617
                apply(arg,(self,canv, x0, y0, w, h))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   618
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   619
                canv.setFillColor(colors.toColor(arg))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   620
                canv.rect(x0, y0, w, h, stroke=0,fill=1)
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   621
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   622
    def _drawCell(self, cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   623
        if self._curcellstyle is not cellstyle:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   624
            cur = self._curcellstyle
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   625
            if cur is None or cellstyle.color != cur.color:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   626
                self.canv.setFillColor(cellstyle.color)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   627
            if cur is None or cellstyle.leading != cur.leading or cellstyle.fontname != cur.fontname or cellstyle.fontsize != cur.fontsize:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   628
                self.canv.setFont(cellstyle.fontname, cellstyle.fontsize, cellstyle.leading)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   629
            self._curcellstyle = cellstyle
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
   630
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   631
        just = cellstyle.alignment
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   632
        valign = cellstyle.valign
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   633
        n = type(cellval)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   634
        if n in _SeqTypes or isinstance(cellval,Flowable):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   635
            if not n in _SeqTypes: cellval = (cellval,)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   636
            # we assume it's a list of Flowables
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   637
            W = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   638
            H = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   639
            w, h = self._listCellGeom(cellval,colwidth,cellstyle,W=W, H=H)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   640
            if valign=='TOP':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   641
                y = rowpos + rowheight - cellstyle.topPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   642
            elif valign=='BOTTOM':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   643
                y = rowpos+cellstyle.bottomPadding + h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   644
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   645
                y = rowpos+(rowheight+cellstyle.bottomPadding-cellstyle.topPadding+h)/2.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   646
            y = y+cellval[0].getSpaceBefore()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   647
            for v, w, h in map(None,cellval,W,H):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   648
                if just=='LEFT': x = colpos+cellstyle.leftPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   649
                elif just=='RIGHT': x = colpos+colwidth-cellstyle.rightPadding - w
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   650
                elif just in ('CENTRE', 'CENTER'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   651
                    x = colpos+(colwidth+cellstyle.leftPadding-cellstyle.rightPadding-w)/2.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   652
                else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   653
                    raise ValueError, 'Invalid justification %s' % just
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   654
                y = y - v.getSpaceBefore()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   655
                y = y - h
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   656
                v.drawOn(self.canv,x,y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   657
                y = y - v.getSpaceAfter()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   658
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   659
            if just == 'LEFT':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   660
                draw = self.canv.drawString
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   661
                x = colpos + cellstyle.leftPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   662
            elif just in ('CENTRE', 'CENTER'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   663
                draw = self.canv.drawCentredString
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   664
                x = colpos + colwidth * 0.5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   665
            elif just == 'RIGHT':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   666
                draw = self.canv.drawRightString
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   667
                x = colpos + colwidth - cellstyle.rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   668
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   669
                raise ValueError, 'Invalid justification %s' % just
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   670
            if n is StringType: val = cellval
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   671
            else: val = str(cellval)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   672
            vals = string.split(val, "\n")
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   673
            n = len(vals)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   674
            leading = cellstyle.leading
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   675
            fontsize = cellstyle.fontsize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   676
            if valign=='BOTTOM':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   677
                y = rowpos + cellstyle.bottomPadding+n*leading-fontsize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   678
            elif valign=='TOP':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   679
                y = rowpos + rowheight - cellstyle.topPadding - fontsize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   680
            elif valign=='MIDDLE':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   681
                y = rowpos + (cellstyle.bottomPadding + rowheight-cellstyle.topPadding+(n-1)*leading)/2.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   682
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   683
                raise ValueError, "Bad valign: '%s'" % str(valign)
329
7358814b9b59 First attempt at VALIGN
rgbecker
parents: 327
diff changeset
   684
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   685
            for v in vals:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   686
                draw(x, y, v)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   687
                y = y-leading
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   688
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   689
# for text,
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   690
#   drawCentredString(self, x, y, text) where x is center
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   691
#   drawRightString(self, x, y, text) where x is right
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   692
#   drawString(self, x, y, text) where x is left
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   693
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   694
_LineOpMap = {  'GRID':'_drawGrid',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   695
                'BOX':'_drawBox',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   696
                'OUTLINE':'_drawBox',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   697
                'INNERGRID':'_drawInnerGrid',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   698
                'LINEBELOW':'_drawHLinesB',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   699
                'LINEABOVE':'_drawHLines',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   700
                'LINEBEFORE':'_drawVLines',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   701
                'LINEAFTER':'_drawVLinesA', }
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   702
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
   703
LINECOMMANDS = _LineOpMap.keys()
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   704
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   705
def _isLineCommand(cmd):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   706
    return cmd[0] in LINECOMMANDS
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   707
350
0916ae478b25 Table splitting start
rgbecker
parents: 342
diff changeset
   708
def _setCellStyle(cellStyles, i, j, op, values):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   709
    #new = CellStyle('<%d, %d>' % (i,j), cellStyles[i][j])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   710
    #cellStyles[i][j] = new
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   711
    ## modify in place!!!
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   712
    new = cellStyles[i][j]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   713
    if op == 'FONT':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   714
        n = len(values)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   715
        new.fontname = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   716
        if n>1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   717
            new.fontsize = values[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   718
            if n>2:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   719
                new.leading = values[2]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   720
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   721
                new.leading = new.fontsize*1.2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   722
    elif op in ('FONTNAME', 'FACE'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   723
        new.fontname = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   724
    elif op in ('SIZE', 'FONTSIZE'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   725
        new.fontsize = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   726
    elif op == 'LEADING':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   727
        new.leading = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   728
    elif op == 'TEXTCOLOR':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   729
        new.color = colors.toColor(values[0], colors.Color(0,0,0))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   730
    elif op in ('ALIGN', 'ALIGNMENT'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   731
        new.alignment = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   732
    elif op == 'VALIGN':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   733
        new.valign = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   734
    elif op == 'LEFTPADDING':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   735
        new.leftPadding = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   736
    elif op == 'RIGHTPADDING':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   737
        new.rightPadding = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   738
    elif op == 'TOPPADDING':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   739
        new.topPadding = values[0]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   740
    elif op == 'BOTTOMPADDING':
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   741
        new.bottomPadding = values[0]
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   742
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   743
GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   744
    [('GRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   745
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   746
    )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   747
BOX_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   748
    [('BOX', (0,0), (-1,-1), 0.50, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   749
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   750
    )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   751
LABELED_GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   752
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   753
     ('BOX', (0,0), (-1,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   754
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   755
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   756
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   757
    )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   758
COLORED_GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   759
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   760
     ('BOX', (0,0), (-1,-1), 2, colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   761
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   762
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   763
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   764
    )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   765
LIST_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   766
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   767
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   768
     ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   769
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   770
    )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   771
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   772
def test():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   773
    from reportlab.lib.units import inch
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   774
    rowheights = (24, 16, 16, 16, 16)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   775
    rowheights2 = (24, 16, 16, 16, 30)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   776
    colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   777
    data = (
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   778
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   779
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   780
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   781
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   782
        ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   783
        )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   784
    data2 = (
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   785
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   786
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   787
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   788
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   789
        ('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   790
        )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   791
    styleSheet = getSampleStyleSheet()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   792
    lst = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   793
    lst.append(Paragraph("Tables", styleSheet['Heading1']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   794
    lst.append(Paragraph(__doc__, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   795
    lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   796
    lst.append(Preformatted("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   797
    colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   798
    rowheights = (24, 16, 16, 16, 16)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   799
    data = (
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   800
        ('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun',
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   801
           'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   802
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   803
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   804
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   805
        ('Hats', 893, 912, '1,212', 643, 789, 159,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   806
             888, '1,298', 832, 453, '1,344','2,843')
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   807
        )
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   808
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   809
    """, styleSheet['Code'], dedent=4))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   810
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   811
    You can then give the Table a TableStyle object to control its format. The first TableStyle used was
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   812
    created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   813
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   814
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   815
GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   816
    [('GRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   817
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   818
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   819
    """, styleSheet['Code']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   820
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   821
    TableStyles are created by passing in a list of commands. There are two types of commands - line commands
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   822
    and cell formatting commands. In all cases, the first three elements of a command are the command name,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   823
    the starting cell and the ending cell.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   824
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   825
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   826
    Line commands always follow this with the weight and color of the desired lines. Colors can be names,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   827
    or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   828
    command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   829
    and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   830
    INNERGRID.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   831
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   832
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   833
    Cell formatting commands are:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   834
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   835
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   836
    FONT - takes fontname, fontsize and (optional) leading.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   837
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   838
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   839
    TEXTCOLOR - takes a color name or (R,G,B) tuple.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   840
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   841
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   842
    ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT and CENTRE (or CENTER).
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   843
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   844
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   845
    LEFTPADDING - defaults to 6.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   846
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   847
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   848
    RIGHTPADDING - defaults to 6.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   849
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   850
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   851
    BOTTOMPADDING - defaults to 3.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   852
    """, styleSheet['Definition']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   853
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   854
    A tablestyle is applied to a table by calling Table.setStyle(tablestyle).
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   855
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   856
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   857
    t.setStyle(GRID_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   858
    lst.append(PageBreak())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   859
    lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   860
    lst.append(t)
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   861
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   862
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   863
    t.setStyle(BOX_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   864
    lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   865
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   866
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   867
    It was created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   868
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   869
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   870
BOX_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   871
    [('BOX', (0,0), (-1,-1), 0.50, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   872
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   873
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   874
    """, styleSheet['Code']))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   875
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   876
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   877
    t.setStyle(LABELED_GRID_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   878
    lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   879
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   880
    t = Table(data2, colwidths, rowheights2)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   881
    t.setStyle(LABELED_GRID_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   882
    lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   883
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   884
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   885
    It was created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   886
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   887
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   888
LABELED_GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   889
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   890
     ('BOX', (0,0), (-1,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   891
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   892
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   893
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   894
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   895
    """, styleSheet['Code']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   896
    lst.append(PageBreak())
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   897
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   898
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   899
    t.setStyle(COLORED_GRID_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   900
    lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   901
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   902
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   903
    It was created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   904
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   905
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   906
COLORED_GRID_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   907
    [('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   908
     ('BOX', (0,0), (-1,-1), 2, colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   909
     ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   910
     ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   911
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   912
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   913
    """, styleSheet['Code']))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   914
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   915
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   916
    t.setStyle(LIST_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   917
    lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   918
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   919
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   920
    It was created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   921
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   922
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   923
LIST_STYLE = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   924
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   925
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   926
     ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   927
     ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   928
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   929
    """, styleSheet['Code']))
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   930
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   931
    t = Table(data, colwidths, rowheights)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   932
    ts = TableStyle(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   933
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   934
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   935
     ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'),
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   936
     ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   937
     ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   938
     ('TEXTCOLOR', (0,1), (0,-1), colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   939
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   940
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   941
    t.setStyle(ts)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   942
    lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   943
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   944
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   945
    It was created as follows:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   946
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   947
    lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   948
   ts = TableStyle(
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   949
    [('LINEABOVE', (0,0), (-1,0), 2, colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   950
     ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   951
     ('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'),
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
   952
     ('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   953
     ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   954
     ('TEXTCOLOR', (0,1), (0,-1), colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   955
     ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   956
    )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   957
    """, styleSheet['Code']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   958
    data = (
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   959
        ('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   960
        ('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   961
        ('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   962
        ('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   963
        ('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   964
        )
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   965
    c = list(colwidths)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   966
    c[0] = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   967
    c[8] = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   968
    t = Table(data, c, [None]+list(rowheights[1:]))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   969
    t.setStyle(LIST_STYLE)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   970
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   971
        This is a LIST_STYLE table with the first rowheight set to None ie automatic.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   972
        The top row cells are split at a newline '\\n' character. The first and August
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   973
        column widths were also set to None.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   974
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   975
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   976
    lst.append(Paragraph("""
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   977
        The red numbers should be aligned LEFT &amp; BOTTOM, the blue RIGHT &amp; TOP
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   978
        and the green CENTER &amp; MIDDLE.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   979
    """, styleSheet['BodyText']))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   980
    XY  =   [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   981
            ['X10y', 'X11y', 'X12y', 'X13y', 'X14y'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   982
            ['X20y', 'X21y', 'X22y', 'X23y', 'X24y'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   983
            ['X30y', 'X31y', 'X32y', 'X33y', 'X34y']]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   984
    t=Table(XY, 5*[0.6*inch], 4*[0.6*inch])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   985
    t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   986
                ('TEXTCOLOR',(1,1),(-2,-2),colors.red),
338
f5eb86d4224f Cosmetics and error testing
rgbecker
parents: 333
diff changeset
   987
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   988
                ('VALIGN',(0,0),(1,-1),'TOP'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   989
                ('ALIGN',(0,0),(1,-1),'RIGHT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   990
                ('TEXTCOLOR',(0,0),(1,-1),colors.blue),
338
f5eb86d4224f Cosmetics and error testing
rgbecker
parents: 333
diff changeset
   991
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   992
                ('ALIGN',(0,-1),(-1,-1),'CENTER'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   993
                ('VALIGN',(0,-1),(-1,-1),'MIDDLE'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   994
                ('TEXTCOLOR',(0,-1),(-1,-1),colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   995
                ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   996
                ('BOX', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   997
                ])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   998
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
   999
    data = [('alignment', 'align\012alignment'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1000
            ('bulletColor', 'bulletcolor\012bcolor'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1001
            ('bulletFontName', 'bfont\012bulletfontname'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1002
            ('bulletFontSize', 'bfontsize\012bulletfontsize'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1003
            ('bulletIndent', 'bindent\012bulletindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1004
            ('firstLineIndent', 'findent\012firstlineindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1005
            ('fontName', 'face\012fontname\012font'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1006
            ('fontSize', 'size\012fontsize'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1007
            ('leading', 'leading'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1008
            ('leftIndent', 'leftindent\012lindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1009
            ('rightIndent', 'rightindent\012rindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1010
            ('spaceAfter', 'spaceafter\012spacea'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1011
            ('spaceBefore', 'spacebefore\012spaceb'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1012
            ('textColor', 'fg\012textcolor\012color')]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1013
    t = Table(data)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1014
    t.setStyle([
333
a9e94b0832a4 Fix auto hieght stuff
rgbecker
parents: 329
diff changeset
  1015
            ('VALIGN',(0,0),(-1,-1),'TOP'),
a9e94b0832a4 Fix auto hieght stuff
rgbecker
parents: 329
diff changeset
  1016
            ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
a9e94b0832a4 Fix auto hieght stuff
rgbecker
parents: 329
diff changeset
  1017
            ('BOX', (0,0), (-1,-1), 0.25, colors.black),
338
f5eb86d4224f Cosmetics and error testing
rgbecker
parents: 333
diff changeset
  1018
            ])
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1019
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1020
    t = Table([ ('Attribute', 'Synonyms'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1021
                ('alignment', 'align, alignment'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1022
                ('bulletColor', 'bulletcolor, bcolor'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1023
                ('bulletFontName', 'bfont, bulletfontname'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1024
                ('bulletFontSize', 'bfontsize, bulletfontsize'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1025
                ('bulletIndent', 'bindent, bulletindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1026
                ('firstLineIndent', 'findent, firstlineindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1027
                ('fontName', 'face, fontname, font'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1028
                ('fontSize', 'size, fontsize'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1029
                ('leading', 'leading'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1030
                ('leftIndent', 'leftindent, lindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1031
                ('rightIndent', 'rightindent, rindent'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1032
                ('spaceAfter', 'spaceafter, spacea'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1033
                ('spaceBefore', 'spacebefore, spaceb'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1034
                ('textColor', 'fg, textcolor, color')])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1035
    t.repeatRows = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1036
    t.setStyle([
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1037
                ('FONT',(0,0),(-1,1),'Times-Bold',10,12),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1038
                ('FONT',(0,1),(-1,-1),'Courier',8,8),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1039
                ('VALIGN',(0,0),(-1,-1),'MIDDLE'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1040
                ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1041
                ('BOX', (0,0), (-1,-1), 0.25, colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1042
                ('BACKGROUND', (0, 0), (-1, 0), colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1043
                ('BACKGROUND', (0, 1), (-1, -1), colors.pink),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1044
                ('ALIGN', (0, 0), (-1, 0), 'CENTER'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1045
                ('ALIGN', (0, 1), (0, -1), 'LEFT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1046
                ('ALIGN', (-1, 1), (-1, -1), 'RIGHT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1047
                ('FONT', (0, 0), (-1, 0), 'Times-Bold', 12),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1048
                ('ALIGN', (1, 1), (1, -1), 'CENTER'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1049
                ])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1050
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1051
    lst.append(Table(XY,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1052
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 5,6),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1053
                    ('GRID', (0,0), (-1,-1), 0.25, colors.blue),]))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1054
    lst.append(Table(XY,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1055
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 10,12),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1056
                    ('GRID', (0,0), (-1,-1), 0.25, colors.black),]))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1057
    lst.append(Table(XY,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1058
            style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 20,24),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1059
                    ('GRID', (0,0), (-1,-1), 0.25, colors.red),]))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1060
    lst.append(PageBreak())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1061
    data=  [['00', '01', '02', '03', '04'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1062
            ['10', '11', '12', '13', '14'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1063
            ['20', '21', '22', '23', '24'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1064
            ['30', '31', '32', '33', '34']]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1065
    t=Table(data,style=[
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1066
                    ('GRID',(0,0),(-1,-1),0.5,colors.grey),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1067
                    ('GRID',(1,1),(-2,-2),1,colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1068
                    ('BOX',(0,0),(1,-1),2,colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1069
                    ('BOX',(0,0),(-1,-1),2,colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1070
                    ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1071
                    ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1072
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1073
                    ('BACKGROUND', (1, 1), (1, 2), colors.lavender),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1074
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1075
                    ])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1076
    lst.append(t)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1077
    lst.append(Spacer(0,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1078
    for s in t.split(4*inch,30):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1079
        lst.append(s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1080
        lst.append(Spacer(0,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1081
    lst.append(Spacer(0,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1082
    for s in t.split(4*inch,36):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1083
        lst.append(s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1084
        lst.append(Spacer(0,6))
403
05b3be301e19 Started debugging Table split
rgbecker
parents: 361
diff changeset
  1085
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1086
    lst.append(Spacer(0,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1087
    for s in t.split(4*inch,56):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1088
        lst.append(s)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1089
        lst.append(Spacer(0,6))
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
  1090
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1091
    import os, reportlab.platypus
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1092
    I = Image(os.path.join(os.path.dirname(reportlab.platypus.__file__),'..','tools','pythonpoint','demos','leftlogo.gif'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1093
    I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1094
    I.drawWidth = 1.25*inch
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1095
    #I.drawWidth = 9.25*inch #uncomment to see better messaging
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1096
    P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1097
    data=  [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1098
            ['00', '01', '02', [I,P], '04'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1099
            ['10', '11', '12', [I,P], '14'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1100
            ['20', '21', '22', '23', '24'],
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1101
            ['30', '31', '32', '33', '34']]
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
  1102
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1103
    t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1104
                    ('BOX',(0,0),(1,-1),2,colors.red),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1105
                    ('LINEABOVE',(1,2),(-2,2),1,colors.blue),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1106
                    ('LINEBEFORE',(2,1),(2,-2),1,colors.pink),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1107
                    ('BACKGROUND', (0, 0), (0, 1), colors.pink),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1108
                    ('BACKGROUND', (1, 1), (1, 2), colors.lavender),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1109
                    ('BACKGROUND', (2, 2), (2, 3), colors.orange),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1110
                    ('BOX',(0,0),(-1,-1),2,colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1111
                    ('GRID',(0,0),(-1,-1),0.5,colors.black),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1112
                    ('VALIGN',(3,0),(3,0),'BOTTOM'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1113
                    ('BACKGROUND',(3,0),(3,0),colors.limegreen),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1114
                    ('BACKGROUND',(3,1),(3,1),colors.khaki),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1115
                    ('ALIGN',(3,1),(3,1),'CENTER'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1116
                    ('BACKGROUND',(3,2),(3,2),colors.beige),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1117
                    ('ALIGN',(3,2),(3,2),'LEFT'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1118
                    ])
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
  1119
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1120
    t._argW[3]=1.5*inch
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1121
    lst.append(t)
419
469fe11a010b Additions/Improvements to LINE CMD Splitting
rgbecker
parents: 403
diff changeset
  1122
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1658
diff changeset
  1123
    SimpleDocTemplate('tables.pdf', showBoundary=1).build(lst)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
  1124
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
  1125
if __name__ == '__main__':
1699
37fa8717925f Improved line styles, allow for cap etc
rgbecker
parents: 1683
diff changeset
  1126
    test()