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