reportlab/platypus/tables.py
changeset 730 48a169b27fe4
parent 684 2a43c747527a
child 735 5dffc9c425d6
equal deleted inserted replaced
729:aa2a02fdd97c 730:48a169b27fe4
     1 #copyright ReportLab Inc. 2000
     1 #copyright ReportLab Inc. 2000
     2 #see license.txt for license details
     2 #see license.txt for license details
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/tables.py?cvsroot=reportlab
     3 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/tables.py?cvsroot=reportlab
     4 #$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.35 2001/03/07 18:57:12 rgbecker Exp $
     4 #$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.36 2001/03/19 23:48:00 aaron_watters Exp $
     5 __version__=''' $Id: tables.py,v 1.35 2001/03/07 18:57:12 rgbecker Exp $ '''
     5 __version__=''' $Id: tables.py,v 1.36 2001/03/19 23:48:00 aaron_watters Exp $ '''
     6 __doc__="""
     6 __doc__="""
     7 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
     7 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
     8 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
     8 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
     9 color and weight of the lines (if any), and the font, alignment and padding of the text.
     9 color and weight of the lines (if any), and the font, alignment and padding of the text.
    10 
    10 
    38 		'color':colors.black,
    38 		'color':colors.black,
    39 		'alignment': 'LEFT',
    39 		'alignment': 'LEFT',
    40 		'background': (1,1,1),
    40 		'background': (1,1,1),
    41 		'valign': 'BOTTOM',
    41 		'valign': 'BOTTOM',
    42 		}
    42 		}
       
    43 
       
    44 # experimental replacement
       
    45 class CellStyle1(PropertySet):
       
    46 	fontname = "Times-Roman"
       
    47 	fontsize = 10
       
    48 	leading = 12
       
    49 	leftPadding = 6
       
    50 	rightPadding = 6
       
    51 	topPadding = 3
       
    52 	bottomPadding = 3
       
    53 	firstLineIndent = 0
       
    54 	color = colors.black
       
    55 	alignment = 'LEFT'
       
    56 	background = (1,1,1)
       
    57 	valign = "BOTTOM"
       
    58 	def __init__(self, name, parent=None):
       
    59 		self.name = name
       
    60 		if parent is not None:
       
    61 			parent.copy(self)
       
    62 	def copy(self, result=None):
       
    63 		if result is None:
       
    64 			result = CellStyle1()
       
    65 		for name in dir(self):
       
    66 			setattr(result, name, gettattr(self, name))
       
    67 		return result
       
    68 
       
    69 CellStyle = CellStyle1
    43 
    70 
    44 class TableStyle:
    71 class TableStyle:
    45 	def __init__(self, cmds=None):
    72 	def __init__(self, cmds=None):
    46 		self._cmds = cmds
    73 		self._cmds = cmds
    47 		if cmds is None:
    74 		if cmds is None:
    95 			if len(data[i]) != ncols:
   122 			if len(data[i]) != ncols:
    96 				raise ValueError, "Not enough data points in row %d!" % i
   123 				raise ValueError, "Not enough data points in row %d!" % i
    97 		self._rowHeights = self._argH = rowHeights
   124 		self._rowHeights = self._argH = rowHeights
    98 		self._colWidths = self._argW = colWidths
   125 		self._colWidths = self._argW = colWidths
    99 		self._cellvalues = data
   126 		self._cellvalues = data
   100 		dflt = CellStyle('<default>')
   127 ##		dflt = CellStyle('<default>')
   101 
   128 ##
   102 		self._cellStyles = [None]*nrows
   129 ##		self._cellStyles = [None]*nrows
       
   130 ##		for i in range(nrows):
       
   131 ##			self._cellStyles[i] = [dflt]*ncols
       
   132 		# make unique cell styles for each entry
       
   133 		cellrows = []
   103 		for i in range(nrows):
   134 		for i in range(nrows):
   104 			self._cellStyles[i] = [dflt]*ncols
   135 			cellcols = []
       
   136 			for j in range(ncols):
       
   137 				cellcols.append(CellStyle(`(i,j)`))
       
   138 			cellrows.append(cellcols)
       
   139 		self._cellStyles = cellrows
   105 
   140 
   106 		self._bkgrndcmds = []
   141 		self._bkgrndcmds = []
   107 		self._linecmds = []
   142 		self._linecmds = []
   108 		self._curweight = self._curcolor = self._curcellstyle = None
   143 		self._curweight = self._curcolor = self._curcellstyle = None
   109 		self.repeatRows = repeatRows
   144 		self.repeatRows = repeatRows
   510 
   545 
   511 def _isLineCommand(cmd):
   546 def _isLineCommand(cmd):
   512 	return cmd[0] in LINECOMMANDS
   547 	return cmd[0] in LINECOMMANDS
   513 
   548 
   514 def _setCellStyle(cellStyles, i, j, op, values):
   549 def _setCellStyle(cellStyles, i, j, op, values):
   515 	new = CellStyle('<%d, %d>' % (i,j), cellStyles[i][j])
   550 	#new = CellStyle('<%d, %d>' % (i,j), cellStyles[i][j])
   516 	cellStyles[i][j] = new
   551 	#cellStyles[i][j] = new
       
   552 	## modify in place!!!
       
   553 	new = cellStyles[i][j]
   517 	if op == 'FONT':
   554 	if op == 'FONT':
   518 		n = len(values)
   555 		n = len(values)
   519 		new.fontname = values[0]
   556 		new.fontname = values[0]
   520 		if n>1:
   557 		if n>1:
   521 			new.fontsize = values[1]
   558 			new.fontsize = values[1]