reportlab/platypus/tables.py
author rgbecker
Thu, 06 Jul 2000 14:05:55 +0000
changeset 327 0944cd1f3f80
parent 326 159576a5816e
child 329 7358814b9b59
permissions -rwxr-xr-x
Adjusted doc string
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     1
###############################################################################
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     2
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     3
#	ReportLab Public License Version 1.0
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     4
#
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
     5
#	Except for the change of names the spirit and intention of this
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
     6
#	license is the same as that of Python
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     7
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     8
#	(C) Copyright ReportLab Inc. 1998-2000.
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
     9
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    10
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    11
# All Rights Reserved
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    12
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    13
# Permission to use, copy, modify, and distribute this software and its
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    14
# documentation for any purpose and without fee is hereby granted, provided
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    15
# that the above copyright notice appear in all copies and that both that
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    16
# copyright notice and this permission notice appear in supporting
7
ca9eb4f68eab License text fixes
rgbecker
parents: 6
diff changeset
    17
# documentation, and that the name of ReportLab not be used
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    18
# in advertising or publicity pertaining to distribution of the software
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    19
# without specific, written prior permission. 
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    20
# 
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    21
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    22
# Disclaimer
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    23
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    24
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    25
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    26
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    27
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    28
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    29
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    30
# PERFORMANCE OF THIS SOFTWARE. 
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    31
#
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    32
###############################################################################
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    33
#	$Log: tables.py,v $
327
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    34
#	Revision 1.15  2000/07/06 14:05:55  rgbecker
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    35
#	Adjusted doc string
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    36
#
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    37
#	Revision 1.14  2000/07/06 12:41:47  rgbecker
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    38
#	First try at auto sizing
327
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    39
#	
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    40
#	Revision 1.13  2000/06/29 17:55:19	aaron_watters
312
b39b1a2ed9d5 support explicit \n line splitting in cells
aaron_watters
parents: 268
diff changeset
    41
#	support explicit \n line splitting in cells
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    42
#	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    43
#	Revision 1.12  2000/06/13 13:03:31	aaron_watters
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    44
#	more documentation changes
312
b39b1a2ed9d5 support explicit \n line splitting in cells
aaron_watters
parents: 268
diff changeset
    45
#	
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    46
#	Revision 1.11  2000/06/01 15:23:06	rgbecker
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 248
diff changeset
    47
#	Platypus re-organisation
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    48
#	
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
    49
#	Revision 1.10  2000/05/26 09:49:23	rgbecker
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 221
diff changeset
    50
#	Color fixes; thanks to J Alet
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 248
diff changeset
    51
#	
221
3d71b66b14c6 Changes related to removal of SimpleFlowDocument
rgbecker
parents: 168
diff changeset
    52
#	Revision 1.9  2000/05/16 16:15:16  rgbecker
3d71b66b14c6 Changes related to removal of SimpleFlowDocument
rgbecker
parents: 168
diff changeset
    53
#	Changes related to removal of SimpleFlowDocument
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 221
diff changeset
    54
#	
168
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    55
#	Revision 1.8  2000/04/26 11:07:15  andy_robinson
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    56
#	Tables changed to use reportlab.lib.colors instead of
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    57
#	the six hard-coded color strings there previously.
221
3d71b66b14c6 Changes related to removal of SimpleFlowDocument
rgbecker
parents: 168
diff changeset
    58
#	
129
623baa767856 Splitting layout.py
rgbecker
parents: 128
diff changeset
    59
#	Revision 1.7  2000/04/14 12:17:05  rgbecker
623baa767856 Splitting layout.py
rgbecker
parents: 128
diff changeset
    60
#	Splitting layout.py
168
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    61
#	
128
a0676f013314 Splitting layout.py
rgbecker
parents: 122
diff changeset
    62
#	Revision 1.6  2000/04/14 11:54:57  rgbecker
a0676f013314 Splitting layout.py
rgbecker
parents: 122
diff changeset
    63
#	Splitting layout.py
129
623baa767856 Splitting layout.py
rgbecker
parents: 128
diff changeset
    64
#	
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 16
diff changeset
    65
#	Revision 1.5  2000/04/14 08:56:20  rgbecker
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 16
diff changeset
    66
#	Drawable ==> Flowable
128
a0676f013314 Splitting layout.py
rgbecker
parents: 122
diff changeset
    67
#	
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 7
diff changeset
    68
#	Revision 1.4  2000/02/17 02:09:05  rgbecker
f9c7525619fb Docstring & other fixes
rgbecker
parents: 7
diff changeset
    69
#	Docstring & other fixes
122
fd68411f49db Drawable ==> Flowable
rgbecker
parents: 16
diff changeset
    70
#	
7
ca9eb4f68eab License text fixes
rgbecker
parents: 6
diff changeset
    71
#	Revision 1.3  2000/02/15 17:55:59  rgbecker
ca9eb4f68eab License text fixes
rgbecker
parents: 6
diff changeset
    72
#	License text fixes
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 7
diff changeset
    73
#	
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    74
#	Revision 1.2  2000/02/15 15:47:09  rgbecker
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    75
#	Added license, __version__ and Logi comment
7
ca9eb4f68eab License text fixes
rgbecker
parents: 6
diff changeset
    76
#	
327
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    77
__version__=''' $Id: tables.py,v 1.15 2000/07/06 14:05:55 rgbecker Exp $ '''
16
f9c7525619fb Docstring & other fixes
rgbecker
parents: 7
diff changeset
    78
__doc__="""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    79
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
    80
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
    81
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
    82
327
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    83
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
    84
or columns should be automatically sized.
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    85
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    86
All the cell values should be convertible to strings; embedded newline '\\n' characters
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    87
cause the value to wrap (ie are like a traditional linefeed).
0944cd1f3f80 Adjusted doc string
rgbecker
parents: 326
diff changeset
    88
268
8414113fa500 more documentation changes
aaron_watters
parents: 253
diff changeset
    89
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
    90
tables and table styles.
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    91
"""
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 248
diff changeset
    92
from reportlab.platypus import *
129
623baa767856 Splitting layout.py
rgbecker
parents: 128
diff changeset
    93
from reportlab.lib.styles import PropertySet, getSampleStyleSheet
168
02bac1346c69 Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents: 129
diff changeset
    94
from reportlab.lib import colors
253
cfcf8d555a2c Platypus re-organisation
rgbecker
parents: 248
diff changeset
    95
from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE
312
b39b1a2ed9d5 support explicit \n line splitting in cells
aaron_watters
parents: 268
diff changeset
    96
import operator, string
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    97
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    98
_stringtype = type('')
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
    99
128
a0676f013314 Splitting layout.py
rgbecker
parents: 122
diff changeset
   100
class CellStyle(PropertySet):
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   101
	defaults = {
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   102
		'fontname':'Times-Roman',
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   103
		'fontsize':10,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   104
		'leading':12,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   105
		'leftPadding':6,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   106
		'rightPadding':6,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   107
		'topPadding':3,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   108
		'bottomPadding':3,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   109
		'firstLineIndent':0,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   110
		'color':colors.black,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   111
		'alignment': 'LEFT',
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   112
		'background': (1,1,1),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   113
		}
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   114
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   115
class TableStyle:
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   116
	def __init__(self, cmds=None):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   117
		self._cmds = cmds
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   118
		if cmds is None:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   119
			self._cmds = []
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   120
	def add(self, *cmd):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   121
		self._cmds.append(cmd)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   122
	def getCommands(self):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   123
		return self._cmds
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   124
		
221
3d71b66b14c6 Changes related to removal of SimpleFlowDocument
rgbecker
parents: 168
diff changeset
   125
class Table(Flowable):
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   126
	def __init__(self, colWidths, rowHeights, data):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   127
		if not colWidths:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   128
			raise ValueError, "Table must have at least 1 column"
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   129
		if not rowHeights:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   130
			raise ValueError, "Table must have at least 1 row"
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   131
		nrows = self._nrows = len(rowHeights)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   132
		if len(data) != nrows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   133
			raise ValueError, "Data error - %d rows in data but %d in grid" % (len(data), nrows)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   134
		ncols = self._ncols = len(colWidths)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   135
		for i in range(nrows):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   136
			if len(data[i]) != ncols:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   137
				raise ValueError, "Not enough data points in row %d!" % i
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   138
		self._rowHeights = rowHeights
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   139
		self._colWidths = colWidths
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   140
		self._cellvalues = data
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   141
		dflt = CellStyle('<default>')
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   142
		self._cellstyles = [None]*nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   143
		for i in range(nrows):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   144
			self._cellstyles[i] = [dflt]*ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   145
		self._bkgrndcmds = []
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   146
		self._linecmds = []
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   147
		self._curweight = self._curcolor = self._curcellstyle = None
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   148
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   149
	def _calc(self):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   150
		H = self._rowHeights
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   151
		W = self._colWidths
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   152
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   153
		if None in H:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   154
			H = H[:]	#make a copy as we'll change it
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   155
			self._rowHeghts = H
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   156
			while None in H:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   157
				i = H.index(None)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   158
				V = self._cellvalues[i]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   159
				S = self._cellstyles[i]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   160
				h = 0
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   161
				for v, s in map(None, V, S):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   162
					if type(v) is not _stringtype: v = str(v)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   163
					v = string.split(v, "\n")
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   164
					t = s.leading*len(v)+s.bottomPadding+s.topPadding
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   165
					if t>h: h = t	#record a new maximum
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   166
				H[i] = h
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   167
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   168
		if None in W:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   169
			W = W[:]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   170
			self._colWidths = W
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   171
			while None in W:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   172
				i = W.index(None)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   173
				f = lambda x,i=i: operator.getitem(x,i)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   174
				V = map(f,self._cellvalues)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   175
				S = map(f,self._cellstyles)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   176
				w = 0
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   177
				for v, s in map(None, V, S):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   178
					if type(v) is not _stringtype: v = str(v)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   179
					v = string.split(v, "\n")
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   180
					t = s.leftPadding+s.rightPadding + max(map(lambda a, b=s.fontname,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   181
								c=s.fontsize,d=self.canv: d.stringWidth(a,b,c), v))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   182
					if t>w: w = t	#record a new maximum
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   183
				W[i] = w
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   184
0
f19e0a2433ab Initial revision
gmcm
parents:
diff changeset
   185
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   186
		height = self._height = reduce(operator.add, H, 0)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   187
		self._rowpositions = [height]	 # index 0 is actually topline; we skip when processing cells
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   188
		for h in H:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   189
			height = height - h
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   190
			self._rowpositions.append(height)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   191
		assert height == 0
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   192
		width = 0
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   193
		self._colpositions = [0]		#index -1 is right side boundary; we skip when processing cells
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   194
		for w in W:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   195
			width = width + w
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   196
			self._colpositions.append(width)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   197
		self._width = width
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   198
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   199
	def setStyle(self, tblstyle):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   200
		for cmd in tblstyle.getCommands():
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   201
			if cmd[0] == 'BACKGROUND':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   202
				self._bkgrndcmds.append(cmd)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   203
			elif _isLineCommand(cmd):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   204
				self._linecmds.append(cmd)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   205
			else:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   206
				(op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   207
				if sc < 0: sc = sc + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   208
				if ec < 0: ec = ec + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   209
				if sr < 0: sr = sr + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   210
				if er < 0: er = er + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   211
				for i in range(sr, er+1):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   212
					for j in range(sc, ec+1):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   213
						_setCellStyle(self._cellstyles, i, j, op, values)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   214
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   215
	def _drawLines(self):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   216
		for op, (sc, sr), (ec, er), weight, color in self._linecmds:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   217
			if sc < 0: sc = sc + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   218
			if ec < 0: ec = ec + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   219
			if sr < 0: sr = sr + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   220
			if er < 0: er = er + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   221
			if op == 'GRID':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   222
				self._drawBox( (sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   223
				self._drawInnerGrid( (sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   224
			elif op in ('BOX',	'OUTLINE',):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   225
				self._drawBox( (sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   226
			elif op == 'INNERGRID':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   227
				self._drawInnerGrid( (sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   228
			elif op == 'LINEBELOW':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   229
				self._drawHLines((sc, sr+1), (ec, er+1), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   230
			elif op == 'LINEABOVE':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   231
				self._drawHLines((sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   232
			elif op == 'LINEBEFORE':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   233
				self._drawVLines((sc, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   234
			elif op == 'LINEAFTER':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   235
				self._drawVLines((sc+1, sr), (ec+1, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   236
			else:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   237
				raise ValueError, "Unknown line style %s" % op
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   238
		self._curcolor = None
248
c103b7a55e79 Color fixes; thanks to J Alet
rgbecker
parents: 221
diff changeset
   239
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   240
	def _drawBox(self,	(sc, sr), (ec, er), weight, color):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   241
		self._drawHLines((sc, sr), (ec, sr), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   242
		self._drawHLines((sc, er+1), (ec, er+1), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   243
		self._drawVLines((sc, sr), (sc, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   244
		self._drawVLines((ec+1, sr), (ec+1, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   245
	def _drawInnerGrid(self, (sc, sr), (ec, er), weight, color):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   246
		self._drawHLines((sc, sr+1), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   247
		self._drawVLines((sc+1, sr), (ec, er), weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   248
	def _prepLine(self, weight, color):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   249
		if color != self._curcolor:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   250
			self.canv.setStrokeColor(color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   251
			self._curcolor = color
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   252
		if weight != self._curweight:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   253
			self.canv.setLineWidth(weight)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   254
			self._curweight = weight
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   255
	def _drawHLines(self, (sc, sr), (ec, er), weight, color):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   256
		self._prepLine(weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   257
		scp = self._colpositions[sc]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   258
		ecp = self._colpositions[ec+1]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   259
		for rowpos in self._rowpositions[sr:er+1]:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   260
			self.canv.line(scp, rowpos, ecp, rowpos)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   261
	def _drawVLines(self, (sc, sr), (ec, er), weight, color):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   262
		self._prepLine(weight, color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   263
		srp = self._rowpositions[sr]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   264
		erp = self._rowpositions[er+1]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   265
		for colpos in self._colpositions[sc:ec+1]:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   266
			self.canv.line(colpos, srp, colpos, erp)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   267
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   268
	def wrap(self, availWidth, availHeight):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   269
		self._calc()
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   270
		#nice and easy, since they are predetermined size
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   271
		self.availWidth = availWidth
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   272
		return (self._width, self._height)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   273
				
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   274
	def draw(self):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   275
		nudge = 0.5 * (self.availWidth - self._width)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   276
		self.canv.translate(nudge, 0)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   277
		self._drawBkgrnd()
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   278
		self._drawLines()
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   279
		for row, rowstyle, rowpos, rowheight in map(None, self._cellvalues, self._cellstyles, self._rowpositions[1:], self._rowHeights):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   280
			for cellval, cellstyle, colpos, colwidth in map(None, row, rowstyle, self._colpositions[:-1], self._colWidths):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   281
				self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   282
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   283
	def _drawBkgrnd(self):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   284
		for cmd, (sc, sr), (ec, er), color in self._bkgrndcmds:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   285
			if sc < 0: sc = sc + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   286
			if ec < 0: ec = ec + self._ncols
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   287
			if sr < 0: sr = sr + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   288
			if er < 0: er = er + self._nrows
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   289
			color = colors.toColor(color, colors.Color(1,1,1))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   290
			x0 = self._colpositions[sc]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   291
			y0 = self._rowpositions[sr]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   292
			x1 = self._colpositions[ec+1]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   293
			y1 = self._rowpositions[er+1]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   294
			self.canv.setFillColor(color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   295
			self.canv.rect(x0, y0, x1-x0, y1-y0,stroke=0,fill=1)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   296
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   297
	def _drawCell(self, cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   298
		#print "cellstyle is ", repr(cellstyle), id(cellstyle)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   299
		if self._curcellstyle is not cellstyle:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   300
			cur = self._curcellstyle
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   301
			if cur is None or cellstyle.color != cur.color:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   302
				#print "setting cell color to %s" % `cellstyle.color`
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   303
				self.canv.setFillColor(cellstyle.color)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   304
			if cur is None or cellstyle.leading != cur.leading or cellstyle.fontname != cur.fontname or cellstyle.fontsize != cur.fontsize:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   305
				#print "setting font: %s, %s, %s" % (cellstyle.fontname, cellstyle.fontsize, cellstyle.leading)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   306
				self.canv.setFont(cellstyle.fontname, cellstyle.fontsize, cellstyle.leading)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   307
			self._curcellstyle = cellstyle
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   308
		#print "leading is ", cellstyle.leading, "size is", cellstyle.fontsize
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   309
		just = cellstyle.alignment
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   310
		#print "alignment is ", just
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   311
		if just == 'LEFT':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   312
			draw = self.canv.drawString
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   313
			x = colpos + cellstyle.leftPadding
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   314
		elif just in ('CENTRE', 'CENTER'):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   315
			draw = self.canv.drawCentredString
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   316
			x = colpos + colwidth * 0.5
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   317
		else:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   318
			draw = self.canv.drawRightString
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   319
			x = colpos + colwidth - cellstyle.rightPadding
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   320
		y = rowpos + cellstyle.bottomPadding
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   321
		if type(cellval) is _stringtype:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   322
			val = cellval
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   323
		else:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   324
			val = str(cellval)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   325
		vals = string.split(val, "\n")
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   326
		n = len(vals)-1
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   327
		leading = cellstyle.leading
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   328
		y2 = y+leading*n
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   329
		for v in vals:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   330
			draw(x, y2, v)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   331
			y2 = y2-leading
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   332
		
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   333
# for text,
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   334
#	drawCentredString(self, x, y, text) where x is center
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   335
#	drawRightString(self, x, y, text) where x is right
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   336
#	drawString(self, x, y, text) where x is left
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   337
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   338
LINECOMMANDS = (
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   339
	'GRID', 'BOX', 'OUTLINE', 'INNERGRID', 'LINEBELOW', 'LINEABOVE', 'LINEBEFORE', 'LINEAFTER', )
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   340
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   341
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   342
def _isLineCommand(cmd):
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   343
	return cmd[0] in LINECOMMANDS
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   344
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   345
def _setCellStyle(cellstyles, i, j, op, values):
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   346
	new = CellStyle('<%d, %d>' % (i,j), cellstyles[i][j])
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   347
	cellstyles[i][j] = new
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   348
	if op == 'FONT':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   349
		new.fontname = values[0]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   350
		new.fontsize = values[1]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   351
	elif op == 'TEXTCOLOR':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   352
		new.color = colors.toColor(values[0], colors.Color(0,0,0))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   353
	elif op in ('ALIGN', 'ALIGNMENT'):
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   354
		new.alignment = values[0]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   355
	elif op == 'LEFTPADDING':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   356
		new.leftPadding = values[0]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   357
	elif op == 'RIGHTPADDING':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   358
		new.rightPadding = values[0]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   359
	elif op == 'TOPPADDING':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   360
		new.topPadding = values[0]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   361
	elif op == 'BOTTOMPADDING':
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   362
		new.bottomPadding = values[0]
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   363
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   364
GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   365
	[('GRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   366
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   367
	)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   368
BOX_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   369
	[('BOX', (0,0), (-1,-1), 0.50, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   370
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   371
	)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   372
LABELED_GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   373
	[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   374
	 ('BOX', (0,0), (-1,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   375
	 ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   376
	 ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   377
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   378
	)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   379
COLORED_GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   380
	[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   381
	 ('BOX', (0,0), (-1,-1), 2, colors.red),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   382
	 ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   383
	 ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   384
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   385
	)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   386
LIST_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   387
	[('LINEABOVE', (0,0), (-1,0), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   388
	 ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   389
	 ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   390
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   391
	)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   392
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   393
def test():
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   394
	rowheights = (24, 16, 16, 16, 16)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   395
	rowheights2 = (24, 16, 16, 16, 30)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   396
	colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   397
	data = (
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   398
		('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   399
		('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   400
		('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   401
		('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   402
		('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   403
		)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   404
	data2 = (
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   405
		('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   406
		('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   407
		('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   408
		('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   409
		('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   410
		)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   411
	styleSheet = getSampleStyleSheet()
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   412
	lst = []
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   413
	lst.append(Paragraph("Tables", styleSheet['Heading1']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   414
	lst.append(Paragraph(__doc__, styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   415
	lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   416
	lst.append(Preformatted("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   417
	colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   418
	rowheights = (24, 16, 16, 16, 16)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   419
	data = (
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   420
		('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun',
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   421
		   'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   422
		('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   423
		('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   424
		('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   425
		('Hats', 893, 912, '1,212', 643, 789, 159,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   426
			 888, '1,298', 832, 453, '1,344','2,843')
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   427
		)	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   428
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   429
	""", styleSheet['Code'], dedent=4))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   430
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   431
	You can then give the Table a TableStyle object to control its format. The first TableStyle used was
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   432
	created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   433
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   434
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   435
GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   436
	[('GRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   437
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   438
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   439
	""", styleSheet['Code']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   440
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   441
	TableStyles are created by passing in a list of commands. There are two types of commands - line commands
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   442
	and cell formatting commands. In all cases, the first three elements of a command are the command name,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   443
	the starting cell and the ending cell.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   444
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   445
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   446
	Line commands always follow this with the weight and color of the desired lines. Colors can be names,
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   447
	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
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   448
	command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   449
	and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   450
	INNERGRID.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   451
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   452
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   453
	Cell formatting commands are:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   454
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   455
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   456
	FONT - takes fontname, fontsize and (optional) leading.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   457
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   458
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   459
	TEXTCOLOR - takes a color name or (R,G,B) tuple.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   460
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   461
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   462
	ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT and CENTRE (or CENTER).
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   463
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   464
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   465
	LEFTPADDING - defaults to 6.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   466
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   467
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   468
	RIGHTPADDING - defaults to 6.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   469
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   470
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   471
	BOTTOMPADDING - defaults to 3.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   472
	""", styleSheet['Definition']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   473
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   474
	A tablestyle is applied to a table by calling Table.setStyle(tablestyle).
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   475
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   476
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   477
	t.setStyle(GRID_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   478
	lst.append(PageBreak())
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   479
	lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   480
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   481
	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   482
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   483
	t.setStyle(BOX_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   484
	lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   485
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   486
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   487
	It was created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   488
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   489
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   490
BOX_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   491
	[('BOX', (0,0), (-1,-1), 0.50, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   492
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   493
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   494
	""", styleSheet['Code']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   495
	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   496
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   497
	t.setStyle(LABELED_GRID_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   498
	lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   499
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   500
	t = Table(colwidths, rowheights2,  data2)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   501
	t.setStyle(LABELED_GRID_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   502
	lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   503
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   504
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   505
	It was created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   506
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   507
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   508
LABELED_GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   509
	[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   510
	 ('BOX', (0,0), (-1,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   511
	 ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   512
	 ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   513
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   514
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   515
	""", styleSheet['Code']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   516
	lst.append(PageBreak())
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   517
	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   518
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   519
	t.setStyle(COLORED_GRID_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   520
	lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   521
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   522
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   523
	It was created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   524
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   525
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   526
COLORED_GRID_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   527
	[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   528
	 ('BOX', (0,0), (-1,-1), 2, colors.red),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   529
	 ('LINEBELOW', (0,0), (-1,0), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   530
	 ('LINEAFTER', (0,0), (0,-1), 2, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   531
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   532
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   533
	""", styleSheet['Code']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   534
	
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   535
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   536
	t.setStyle(LIST_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   537
	lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   538
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   539
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   540
	It was created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   541
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   542
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   543
LIST_STYLE = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   544
	[('LINEABOVE', (0,0), (-1,0), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   545
	 ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   546
	 ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   547
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT')]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   548
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   549
	""", styleSheet['Code']))
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   550
   
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   551
	t = Table(colwidths, rowheights,  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   552
	ts = TableStyle(
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   553
	[('LINEABOVE', (0,0), (-1,0), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   554
	 ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   555
	 ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   556
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   557
	 ('TEXTCOLOR', (0,1), (0,-1), colors.red),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   558
	 ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   559
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   560
	t.setStyle(ts)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   561
	lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   562
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   563
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   564
	It was created as follows:
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   565
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   566
	lst.append(Preformatted("""
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   567
   ts = TableStyle(
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   568
	[('LINEABOVE', (0,0), (-1,0), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   569
	 ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   570
	 ('LINEBELOW', (0,-1), (-1,-1), 2, colors.green),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   571
	 ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   572
	 ('TEXTCOLOR', (0,1), (0,-1), colors.red),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   573
	 ('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))]
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   574
	)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   575
	""", styleSheet['Code']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   576
	data = (
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   577
		('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   578
		('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   579
		('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   580
		('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13),
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   581
		('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843')
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   582
		)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   583
	c = list(colwidths)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   584
	c[0] = None
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   585
	c[8] = None
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   586
	t = Table(c, [None]+list(rowheights[1:]),  data)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   587
	t.setStyle(LIST_STYLE)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   588
	lst.append(Paragraph("""
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   589
		This is a LIST_STYLE table with the first rowheight set to None ie automatic.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   590
		The top row cells are split at a newline '\\n' character. The first and August
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   591
		column widths were also set to None.
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   592
	""", styleSheet['BodyText']))
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   593
	lst.append(t)
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   594
	SimpleDocTemplate('testtables.pdf', showBoundary=1).build(lst)
6
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   595
eb791971b252 Added license, __version__ and Logi comment
rgbecker
parents: 0
diff changeset
   596
if __name__ == '__main__':
326
159576a5816e First try at auto sizing
rgbecker
parents: 312
diff changeset
   597
	test()