Table argument order changed
authorrgbecker
Wed, 12 Jul 2000 14:23:12 +0000
changeset 356 377367fe28cb
parent 355 3a8dd5f93921
child 357 f1a45d837afb
Table argument order changed
docs/userguide/ch5_paragraphs.py
docs/userguide/ch6_tables.py
reportlab/demos/pythonpoint/pythonpoint.py
reportlab/platypus/tables.py
reportlab/platypus/test/testplatypus.py
reportlab/platypus/test/testtables.py
--- a/docs/userguide/ch5_paragraphs.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/docs/userguide/ch5_paragraphs.py	Wed Jul 12 14:23:12 2000 +0000
@@ -167,7 +167,7 @@
         D.append((k,S[k]))
     cols=2*[None]
     rows=len(D)*[None]
-    return cols,rows,D
+    return D,cols,rows
 
 t=apply(Table,getAttrs(_paraAttrMap))
 t.setStyle(TableStyle([
--- a/docs/userguide/ch6_tables.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/docs/userguide/ch6_tables.py	Wed Jul 12 14:23:12 2000 +0000
@@ -20,17 +20,8 @@
 heading2('$class Table$ User Methods')
 disc("""These are the main methods which are of interest to the client programmer""")
 
-heading4('$Table(colWidths, rowHeights, data)$')
-
-disc("""The arguments are fairly obvious, the $colWidths$ argument is a sequence
-of numbers or possibly $None$, representing the widths of the rows. The number of elements
-in $colWidths$ determines the number of columns in the table.
-A value of $None$ means that the corresponding column width should be calculated automatically""")
-
-disc("""The $rowHeights$ argument is a sequence
-of numbers or possibly $None$, representing the heights of the rows. The number of elements
-in $rowHeights$ determines the number of rows in the table.
-A value of $None$ means that the corresponding row height should be calculated automatically""")
+heading4("""$Table(data, colWidths=None, rowHeights=None, style=None, splitByRow=1,
+repeatRows=0, repeatCols=0)$""")
 
 disc("""The $data$ argument is a sequence of sequences of cell values each of which
 should be convertible to a string value using the $str$ function. The first row of cell values
@@ -38,7 +29,23 @@
 $data[i][j]$. Newline characters $'\\n'$ in cell values are treated as line split characters and
 are used at <i>draw</i> time to format the cell into lines.
 """)
+disc("""The other arguments are fairly obvious, the $colWidths$ argument is a sequence
+of numbers or possibly $None$, representing the widths of the columns. The number of elements
+in $colWidths$ determines the number of columns in the table.
+A value of $None$ means that the corresponding column width should be calculated automatically.""")
 
+disc("""The $rowHeights$ argument is a sequence
+of numbers or possibly $None$, representing the heights of the rows. The number of elements
+in $rowHeights$ determines the number of rows in the table.
+A value of $None$ means that the corresponding row height should be calculated automatically.""")
+
+disc("""The $style$ argument can be an initial style for the table.""")
+disc("""The $splitByRow$ argument is a boolean indicating that the $Table$ should split itself
+by row before attempting to split itself by column when too littel space is available in
+the current drawing area and the caller wants the $Table$ to split.""")
+
+disc("""The $repeatRows$ and $repeatCols$ arguments specify the number of leading rows and columns
+that should be repeated when the $Table$ is asked to split itself.""")
 heading4('$Table.$setStyle(tblStyle)$')
 disc("""
 This method applies a particular instance of $class TableStyle$ (discussed below)
@@ -117,7 +124,7 @@
         ['10', '11', '12', '13', '14'],
         ['20', '21', '22', '23', '24'],
         ['30', '31', '32', '33', '34']]
-t=Table(5*[None], 4*[None], data)
+t=Table(data)
 t.setStyle(TableStyle([('BACKGROUND',(1,1),(-2,-2),colors.green),
                         ('TEXTCOLOR',(0,0),(1,-1),colors.red)]))
 """)
@@ -128,7 +135,7 @@
         ['10', '11', '12', '13', '14'],
         ['20', '21', '22', '23', '24'],
         ['30', '31', '32', '33', '34']]
-t=Table(5*[0.4*inch], 4*[0.4*inch], data)
+t=Table(data,5*[0.4*inch], 4*[0.4*inch])
 t.setStyle(TableStyle([('ALIGN',(1,1),(-2,-2),'RIGHT'),
                         ('TEXTCOLOR',(1,1),(-2,-2),colors.red),
                         ('VALIGN',(0,0),(0,-1),'TOP'),
@@ -156,7 +163,7 @@
         ['10', '11', '12', '13', '14'],
         ['20', '21', '22', '23', '24'],
         ['30', '31', '32', '33', '34']]
-t=Table(5*[None], 4*[None], data)
+t=Table(data)
 t.setStyle(TableStyle([('GRID',(1,1),(-2,-2),1,colors.green),
                         ('BOX',(0,0),(1,-1),2,colors.red)]))
 """)
--- a/reportlab/demos/pythonpoint/pythonpoint.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/reportlab/demos/pythonpoint/pythonpoint.py	Wed Jul 12 14:23:12 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: pythonpoint.py,v $
+#	Revision 1.24  2000/07/12 14:23:12  rgbecker
+#	Table argument order changed
+#
 #	Revision 1.23  2000/07/12 06:33:43  andy_robinson
 #	Added Speaker Notes facility
-#
+#	
 #	Revision 1.22  2000/07/10 15:25:47  andy_robinson
 #	Added tables to PythonPoint
 #	
@@ -105,7 +108,7 @@
 #	Revision 1.1.1.1  2000/02/15 15:08:55  rgbecker
 #	Initial setup of demos directory and contents.
 #	
-__version__=''' $Id: pythonpoint.py,v 1.23 2000/07/12 06:33:43 andy_robinson Exp $ '''
+__version__=''' $Id: pythonpoint.py,v 1.24 2000/07/12 14:23:12 rgbecker Exp $ '''
 # xml parser stuff for PythonPoint
 # PythonPoint Markup Language!
 __doc__="""
@@ -330,9 +333,9 @@
     def getFlowable(self):
         self.parseData()
         t = Table(
+				self.data,
                 self.widths,
-                self.heights,
-                self.data)
+                self.heights)
         if self.style:
             t.setStyle(getStyles()[self.style])
 
--- a/reportlab/platypus/tables.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/reportlab/platypus/tables.py	Wed Jul 12 14:23:12 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: tables.py,v $
+#	Revision 1.22  2000/07/12 14:23:12  rgbecker
+#	Table argument order changed
+#
 #	Revision 1.21  2000/07/12 09:05:17  rgbecker
 #	Fixed tuple size bug
-#
+#	
 #	Revision 1.20  2000/07/11 14:29:45  rgbecker
 #	Table splitting start
 #	
@@ -92,7 +95,7 @@
 #	Revision 1.2  2000/02/15 15:47:09  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: tables.py,v 1.21 2000/07/12 09:05:17 rgbecker Exp $ '''
+__version__=''' $Id: tables.py,v 1.22 2000/07/12 14:23:12 rgbecker Exp $ '''
 __doc__="""
 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
@@ -113,6 +116,7 @@
 from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE
 import operator, string
 
+from types import TupleType, ListType
 _stringtype = type('')
 
 class CellStyle(PropertySet):
@@ -142,17 +146,27 @@
 		return self._cmds
 
 TableStyleType = type(TableStyle())
-		
+_SeqType = (TupleType, ListType)
+
+def _rowLen(x):
+	return type(x) not in _SeqType and 1 or len(x)
+
 class Table(Flowable):
-	def __init__(self, colWidths, rowHeights, data, style=None,
+	def __init__(self, data, colWidths=None, rowHeights=None, style=None,
 				repeatRows=0, repeatCols=0, splitByRow=1):
-		if not colWidths:
+		nrows = len(data)
+		if len(data)==0 or type(data) not in _SeqType:
+			raise ValueError, "Table must have at least 1 row"
+		ncols = max(map(_rowLen,data))
+		if not ncols:
 			raise ValueError, "Table must have at least 1 column"
-		if not rowHeights:
-			raise ValueError, "Table must have at least 1 row"
-		nrows = self._nrows = len(rowHeights)
-		if len(data) != nrows:
-			raise ValueError, "Data error - %d rows in data but %d in grid" % (len(data), nrows)
+		if colWidths is None: colWidths = ncols*[None]
+		elif len(colWidths) != ncols:
+			raise ValueError, "Data error - %d columns in data but %d in grid" % (ncols, len(colWidths))
+		if rowHeights is None: rowHeights = nrows*[None]
+		elif len(rowHeights) != nrows:
+			raise ValueError, "Data error - %d rows in data but %d in grid" % (nrows, len(rowHeights))
+		self._nrows = nrows
 		ncols = self._ncols = len(colWidths)
 		for i in range(nrows):
 			if len(data[i]) != ncols:
@@ -362,7 +376,7 @@
 		data = self._cellvalues
 
 		#we're going to split into two superRows
-		R0 = Table( self._argW, self._argH[:n], data[:n],
+		R0 = Table( data[:n], self._argW, self._argH[:n],
 				repeatRows=repeatRows, repeatCols=repeatCols,
 				splitByRow=splitByRow)
 
@@ -372,15 +386,15 @@
 		R0._cr_0(n,self._bkgrndcmds)
 
 		if repeatRows:
-			R1 = Table(self._argW, self._argH[:repeatRows]+self._argH[n:],
-					data[:repeatRows]+data[n:],
+			R1 = Table(data[:repeatRows]+data[n:],
+					self._argW, self._argH[:repeatRows]+self._argH[n:],
 					repeatRows=repeatRows, repeatCols=repeatCols,
 					splitByRow=splitByRow)
 			R1._cellStyles = self._cellStyles[:repeatRows]+self._cellStyles[n:]
 			R1._cr_1_1(n,repeatRows,self._linecmds)
 			R1._cr_1_1(n,repeatRows,self._bkgrndcmds)
 		else:
-			R1 = Table(self._argW, self._argH[n:],data[n:],
+			R1 = Table(data[n:], self._argW, self._argH[n:],
 					repeatRows=repeatRows, repeatCols=repeatCols,
 					splitByRow=splitByRow)
 			R1._cellStyles = self._cellStyles[n:]
@@ -565,7 +579,7 @@
 		('Hats', 893, 912, '1,212', 643, 789, 159,
 			 888, '1,298', 832, 453, '1,344','2,843')
 		)	
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	""", styleSheet['Code'], dedent=4))
 	lst.append(Paragraph("""
 	You can then give the Table a TableStyle object to control its format. The first TableStyle used was
@@ -613,13 +627,13 @@
 	lst.append(Paragraph("""
 	A tablestyle is applied to a table by calling Table.setStyle(tablestyle).
 	""", styleSheet['BodyText']))
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	t.setStyle(GRID_STYLE)
 	lst.append(PageBreak())
 	lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText']))
 	lst.append(t)
 	
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	t.setStyle(BOX_STYLE)
 	lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText']))
 	lst.append(t)
@@ -633,11 +647,11 @@
 	)
 	""", styleSheet['Code']))
 	
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	t.setStyle(LABELED_GRID_STYLE)
 	lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText']))
 	lst.append(t)
-	t = Table(colwidths, rowheights2,  data2)
+	t = Table(data2, colwidths, rowheights2)
 	t.setStyle(LABELED_GRID_STYLE)
 	lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText']))
 	lst.append(t)
@@ -655,7 +669,7 @@
 	""", styleSheet['Code']))
 	lst.append(PageBreak())
 	
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	t.setStyle(COLORED_GRID_STYLE)
 	lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText']))
 	lst.append(t)
@@ -672,7 +686,7 @@
 	)
 	""", styleSheet['Code']))
 	
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	t.setStyle(LIST_STYLE)
 	lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText']))
 	lst.append(t)
@@ -688,7 +702,7 @@
 	)
 	""", styleSheet['Code']))
    
-	t = Table(colwidths, rowheights,  data)
+	t = Table(data, colwidths, rowheights)
 	ts = TableStyle(
 	[('LINEABOVE', (0,0), (-1,0), 2, colors.green),
 	 ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
@@ -723,7 +737,7 @@
 	c = list(colwidths)
 	c[0] = None
 	c[8] = None
-	t = Table(c, [None]+list(rowheights[1:]),  data)
+	t = Table(data, c, [None]+list(rowheights[1:]))
 	t.setStyle(LIST_STYLE)
 	lst.append(Paragraph("""
 		This is a LIST_STYLE table with the first rowheight set to None ie automatic.
@@ -739,7 +753,7 @@
 			['X10y', 'X11y', 'X12y', 'X13y', 'X14y'],
 			['X20y', 'X21y', 'X22y', 'X23y', 'X24y'],
 			['X30y', 'X31y', 'X32y', 'X33y', 'X34y']]
-	t=Table(5*[0.4*inch], 4*[0.4*inch], data)
+	t=Table(data, 5*[0.4*inch], 4*[0.4*inch])
 	t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'),
 				('TEXTCOLOR',(1,1),(-2,-2),colors.red),
 
@@ -769,14 +783,14 @@
 			('spaceAfter', 'spaceafter\012spacea'),
 			('spaceBefore', 'spacebefore\012spaceb'),
 			('textColor', 'fg\012textcolor\012color')]
-	t = Table(2*[None], len(data)*[None], data)
+	t = Table(data)
 	t.setStyle([
             ('VALIGN',(0,0),(-1,-1),'TOP'),
             ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
             ('BOX', (0,0), (-1,-1), 0.25, colors.black),
             ])
 	lst.append(t)
-	t=apply(Table,([None, None], [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None], [('Attribute', 'Synonyms'), ('alignment', 'align, alignment'), ('bulletColor', 'bulletcolor, bcolor'), ('bulletFontName', 'bfont, bulletfontname'), ('bulletFontSize', 'bfontsize, bulletfontsize'), ('bulletIndent', 'bindent, bulletindent'), ('firstLineIndent', 'findent, firstlineindent'), ('fontName', 'face, fontname, font'), ('fontSize', 'size, fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent, lindent'), ('rightIndent', 'rightindent, rindent'), ('spaceAfter', 'spaceafter, spacea'), ('spaceBefore', 'spacebefore, spaceb'), ('textColor', 'fg, textcolor, color')]))
+	t=apply(Table,([('Attribute', 'Synonyms'), ('alignment', 'align, alignment'), ('bulletColor', 'bulletcolor, bcolor'), ('bulletFontName', 'bfont, bulletfontname'), ('bulletFontSize', 'bfontsize, bulletfontsize'), ('bulletIndent', 'bindent, bulletindent'), ('firstLineIndent', 'findent, firstlineindent'), ('fontName', 'face, fontname, font'), ('fontSize', 'size, fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent, lindent'), ('rightIndent', 'rightindent, rindent'), ('spaceAfter', 'spaceafter, spacea'), ('spaceBefore', 'spacebefore, spaceb'), ('textColor', 'fg, textcolor, color')],))
 	t.repeatRows = 1
 	t.setStyle([
 				('FONT',(0,0),(-1,1),'Times-Bold',10,12),
@@ -793,7 +807,7 @@
 				('ALIGN', (1, 1), (1, -1), 'CENTER'),
 				])
 	lst.append(t)
-	SimpleDocTemplate('testtables.pdf', showBoundary=1).build(lst)
+	SimpleDocTemplate('tables.pdf', showBoundary=1).build(lst)
 
 if __name__ == '__main__':
 	test()
--- a/reportlab/platypus/test/testplatypus.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/reportlab/platypus/test/testplatypus.py	Wed Jul 12 14:23:12 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: testplatypus.py,v $
+#	Revision 1.18  2000/07/12 14:23:12  rgbecker
+#	Table argument order changed
+#
 #	Revision 1.17  2000/06/01 15:23:06  rgbecker
 #	Platypus re-organisation
-#
+#	
 #	Revision 1.16  2000/05/17 22:17:38	rgbecker
 #	Renamed BasicFrame to Frame
 #	
@@ -80,7 +83,7 @@
 #	Revision 1.2  2000/02/15 15:47:10  rgbecker
 #	Added license, __version__ and Logi comment
 #	
-__version__=''' $Id: testplatypus.py,v 1.17 2000/06/01 15:23:06 rgbecker Exp $ '''
+__version__=''' $Id: testplatypus.py,v 1.18 2000/07/12 14:23:12 rgbecker Exp $ '''
 
 #tests and documents Page Layout API
 __doc__="""This is not obvious so here's a brief explanation.  This module is both
@@ -450,12 +453,12 @@
 	story.append(platypus.Spacer(0, 12))
 	
 	g = platypus.Table(
-			(72,36,36,36,36),
-			(24, 16,16,18),
 			(('','North','South','East','West'),
 			 ('Quarter 1',100,200,300,400),
 			 ('Quarter 2',100,200,300,400),
-			 ('Total',200,400,600,800))
+			 ('Total',200,400,600,800)),
+			(72,36,36,36,36),
+			(24, 16,16,18)
 			)
 
 	style = platypus.TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'),
--- a/reportlab/platypus/test/testtables.py	Wed Jul 12 13:34:35 2000 +0000
+++ b/reportlab/platypus/test/testtables.py	Wed Jul 12 14:23:12 2000 +0000
@@ -32,9 +32,12 @@
 #
 ###############################################################################
 #	$Log: testtables.py,v $
+#	Revision 1.11  2000/07/12 14:23:12  rgbecker
+#	Table argument order changed
+#
 #	Revision 1.10  2000/06/01 16:27:56  rgbecker
 #	pageSize is wrong at present
-#
+#	
 #	Revision 1.9  2000/06/01 15:23:06  rgbecker
 #	Platypus re-organisation
 #	
@@ -60,20 +63,19 @@
 #	Revision 1.2  2000/02/15 15:47:10  rgbecker
 #	Added license, __version__ and Logi comment
 #
-__version__=''' $Id: testtables.py,v 1.10 2000/06/01 16:27:56 rgbecker Exp $ '''
+__version__=''' $Id: testtables.py,v 1.11 2000/07/12 14:23:12 rgbecker Exp $ '''
 __doc__='Test script for reportlab.tables'
 from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle
 from reportlab.lib.units import inch
 from reportlab.lib import colors
 
 def getTable():
-    t = Table(
-            (72,36,36,36,36),
-            (24, 16,16,18),
-            (('','North','South','East','West'),
+    t = Table((('','North','South','East','West'),
              ('Quarter 1',100,200,300,400),
              ('Quarter 2',100,400,600,800),
-             ('Total',300,600,900,'1,200'))
+             ('Total',300,600,900,'1,200')),
+             (72,36,36,36,36),
+             (24, 16,16,18)
             )
     return t