reportlab/platypus/tables.py
changeset 2401 cd68d7a84d05
parent 2397 6b3ce9559beb
child 2412 b8bf2e639769
equal deleted inserted replaced
2400:f47d5c6d8fcd 2401:cd68d7a84d05
   156         self.vAlign = 'MIDDLE'
   156         self.vAlign = 'MIDDLE'
   157         if type(data) not in _SeqTypes:
   157         if type(data) not in _SeqTypes:
   158             raise ValueError, "%s invalid data type" % self.identity()
   158             raise ValueError, "%s invalid data type" % self.identity()
   159         self._nrows = nrows = len(data)
   159         self._nrows = nrows = len(data)
   160         self._cellvalues = []
   160         self._cellvalues = []
       
   161         _seqCW = type(colWidths) in _SeqTypes
       
   162         _seqRH = type(rowHeights) in _SeqTypes
   161         if nrows: self._ncols = ncols = max(map(_rowLen,data))
   163         if nrows: self._ncols = ncols = max(map(_rowLen,data))
   162         elif colWidths: ncols = len(colWidths)
   164         elif colWidths and _seqCW: ncols = len(colWidths)
   163         else: ncols = 0
   165         else: ncols = 0
   164         if not emptyTableAction: emptyTableAction = rl_config.emptyTableAction
   166         if not emptyTableAction: emptyTableAction = rl_config.emptyTableAction
   165         if not (nrows and ncols):
   167         if not (nrows and ncols):
   166             if emptyTableAction=='error':
   168             if emptyTableAction=='error':
   167                 raise ValueError, "%s must have at least a row and column" % self.identity()
   169                 raise ValueError, "%s must have at least a row and column" % self.identity()
   179             else:
   181             else:
   180                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   182                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
   181             return
   183             return
   182 
   184 
   183         self._cellvalues = data
   185         self._cellvalues = data
   184         if colWidths is None: colWidths = ncols*[None]
   186         if not _seqCW: colWidths = ncols*[colWidths]
   185         elif len(colWidths) != ncols:
   187         elif len(colWidths) != ncols:
   186             raise ValueError, "%s data error - %d columns in data but %d in grid" % (self.identity(),ncols, len(colWidths))
   188             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]
   189         if not _seqRH: rowHeights = nrows*[rowHeights]
   188         elif len(rowHeights) != nrows:
   190         elif len(rowHeights) != nrows:
   189             raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
   191             raise ValueError, "%s data error - %d rows in data but %d in grid" % (self.identity(),nrows, len(rowHeights))
   190         for i in range(nrows):
   192         for i in range(nrows):
   191             if len(data[i]) != ncols:
   193             if len(data[i]) != ncols:
   192                 raise ValueError, "%s not enough data points in row %d!" % (self.identity(),i)
   194                 raise ValueError, "%s not enough data points in row %d!" % (self.identity(),i)