reportlab/platypus/tables.py
changeset 2299 d757841f2006
parent 2289 fc3840f8294d
child 2314 a431a62443a7
equal deleted inserted replaced
2298:ffcca4c83d88 2299:d757841f2006
     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.80 2004/04/22 17:36:41 rgbecker Exp $
     4 #$Header: /tmp/reportlab/reportlab/platypus/tables.py,v 1.81 2004/05/18 17:16:55 rgbecker Exp $
     5 __version__=''' $Id: tables.py,v 1.80 2004/04/22 17:36:41 rgbecker Exp $ '''
     5 __version__=''' $Id: tables.py,v 1.81 2004/05/18 17:16:55 rgbecker Exp $ '''
     6 
     6 
     7 __doc__="""
     7 __doc__="""
     8 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
     8 Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in
     9 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
     9 row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the
    10 color and weight of the lines (if any), and the font, alignment and padding of the text.
    10 color and weight of the lines (if any), and the font, alignment and padding of the text.
   179                 Spacer.__init__(self,0,0)
   179                 Spacer.__init__(self,0,0)
   180             else:
   180             else:
   181                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   181                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   182             return
   182             return
   183 
   183 
       
   184         self._cellvalues = data
   184         if colWidths is None: colWidths = ncols*[None]
   185         if colWidths is None: colWidths = ncols*[None]
   185         elif len(colWidths) != ncols:
   186         elif len(colWidths) != ncols:
   186             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
   187             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
   187         if rowHeights is None: rowHeights = nrows*[None]
   188         if rowHeights is None: rowHeights = nrows*[None]
   188         elif len(rowHeights) != nrows:
   189         elif len(rowHeights) != nrows:
   189             raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
   190             raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
   190         for i in range(nrows):
   191         for i in range(nrows):
   191             if len(data[i]) != ncols:
   192             if len(data[i]) != ncols:
   192                 raise ValueError, "%s not enough data points in row %d!" % (self.identity(),i)
   193                 raise ValueError, "%s not enough data points in row %d!" % (self.identity(),i)
   193         self._cellvalues = data
       
   194         self._rowHeights = self._argH = rowHeights
   194         self._rowHeights = self._argH = rowHeights
   195         self._colWidths = self._argW = colWidths
   195         self._colWidths = self._argW = colWidths
   196         cellrows = []
   196         cellrows = []
   197         for i in range(nrows):
   197         for i in range(nrows):
   198             cellcols = []
   198             cellcols = []
   223     def identity(self, maxLen=30):
   223     def identity(self, maxLen=30):
   224         '''Identify our selves as well as possible'''
   224         '''Identify our selves as well as possible'''
   225         vx = None
   225         vx = None
   226         nr = getattr(self,'_nrows','unknown')
   226         nr = getattr(self,'_nrows','unknown')
   227         nc = getattr(self,'_ncols','unknown')
   227         nc = getattr(self,'_ncols','unknown')
   228         cv = self._cellvalues
   228         cv = getattr(self,'_cellvalues',None)
   229         if cv and 'unknown' not in (nr,nc):
   229         if cv and 'unknown' not in (nr,nc):
   230             b = 0
   230             b = 0
   231             for i in xrange(nr):
   231             for i in xrange(nr):
   232                 for j in xrange(nc):
   232                 for j in xrange(nc):
   233                     v = cv[i][j]
   233                     v = cv[i][j]