src/reportlab/platypus/tables.py
changeset 3325 64eb1b787d02
parent 3240 3480466a0fc2
child 3326 ce725978d11c
equal deleted inserted replaced
3324:e1b661e5f494 3325:64eb1b787d02
   211         V[x] += v
   211         V[x] += v
   212 
   212 
   213 class Table(Flowable):
   213 class Table(Flowable):
   214     def __init__(self, data, colWidths=None, rowHeights=None, style=None,
   214     def __init__(self, data, colWidths=None, rowHeights=None, style=None,
   215                 repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None, ident=None,
   215                 repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None, ident=None,
   216                 hAlign=None,vAlign=None):
   216                 hAlign=None,vAlign=None, normalizedData=0, cellStyles=None):
   217         self.ident = ident
   217         self.ident = ident
   218         self.hAlign = hAlign or 'CENTER'
   218         self.hAlign = hAlign or 'CENTER'
   219         self.vAlign = vAlign or 'MIDDLE'
   219         self.vAlign = vAlign or 'MIDDLE'
   220         if not isinstance(data,(tuple,list)):
   220         if not isinstance(data,(tuple,list)):
   221             raise ValueError("%s invalid data type" % self.identity())
   221             raise ValueError("%s invalid data type" % self.identity())
   244             else:
   244             else:
   245                 raise ValueError('%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction))
   245                 raise ValueError('%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction))
   246             return
   246             return
   247 
   247 
   248         # we need a cleanup pass to ensure data is strings - non-unicode and non-null
   248         # we need a cleanup pass to ensure data is strings - non-unicode and non-null
   249         self._cellvalues = data = self.normalizeData(data)
   249         if normalizedData:
       
   250             self._cellvalues = data
       
   251         else:
       
   252             self._cellvalues = data = self.normalizeData(data)
   250         if not _seqCW: colWidths = ncols*[colWidths]
   253         if not _seqCW: colWidths = ncols*[colWidths]
   251         elif len(colWidths)!=ncols:
   254         elif len(colWidths)!=ncols:
   252             if rl_config.allowShortTableRows and isinstance(colWidths,list):
   255             if rl_config.allowShortTableRows and isinstance(colWidths,list):
   253                 n = len(colWidths)
   256                 n = len(colWidths)
   254                 if n<ncols:
   257                 if n<ncols:
   267                     d[n:] = (ncols-n)*['']
   270                     d[n:] = (ncols-n)*['']
   268                 else:
   271                 else:
   269                     raise ValueError("%s expected %d not %d columns in row %d!" % (self.identity(),ncols,n,i))
   272                     raise ValueError("%s expected %d not %d columns in row %d!" % (self.identity(),ncols,n,i))
   270         self._rowHeights = self._argH = rowHeights
   273         self._rowHeights = self._argH = rowHeights
   271         self._colWidths = self._argW = colWidths
   274         self._colWidths = self._argW = colWidths
   272         cellrows = []
   275         if cellStyles is None:
   273         for i in xrange(nrows):
   276             cellrows = []
   274             cellcols = []
   277             for i in xrange(nrows):
   275             for j in xrange(ncols):
   278                 cellcols = []
   276                 cellcols.append(CellStyle(`(i,j)`))
   279                 for j in xrange(ncols):
   277             cellrows.append(cellcols)
   280                     cellcols.append(CellStyle(`(i,j)`))
   278         self._cellStyles = cellrows
   281                 cellrows.append(cellcols)
       
   282             self._cellStyles = cellrows
       
   283         else:
       
   284             self._cellStyles = cellStyles
   279 
   285 
   280         self._bkgrndcmds = []
   286         self._bkgrndcmds = []
   281         self._linecmds = []
   287         self._linecmds = []
   282         self._spanCmds = []
   288         self._spanCmds = []
   283         self._nosplitCmds = []
   289         self._nosplitCmds = []
  1136 
  1142 
  1137         #we're going to split into two superRows
  1143         #we're going to split into two superRows
  1138         #R0 = slelf.__class__( data[:n], self._argW, self._argH[:n],
  1144         #R0 = slelf.__class__( data[:n], self._argW, self._argH[:n],
  1139         R0 = self.__class__( data[:n], colWidths=self._colWidths, rowHeights=self._argH[:n],
  1145         R0 = self.__class__( data[:n], colWidths=self._colWidths, rowHeights=self._argH[:n],
  1140                 repeatRows=repeatRows, repeatCols=repeatCols,
  1146                 repeatRows=repeatRows, repeatCols=repeatCols,
  1141                 splitByRow=splitByRow)
  1147                 splitByRow=splitByRow, normalizedData=1, cellStyles=self._cellStyles[:n])
  1142 
  1148 
  1143         #copy the styles and commands
  1149         #copy the commands
  1144         R0._cellStyles = self._cellStyles[:n]
       
  1145 
  1150 
  1146         A = []
  1151         A = []
  1147         # hack up the line commands
  1152         # hack up the line commands
  1148         for op, (sc,sr), (ec,er), weight, color, cap, dash, join, count, space in self._linecmds:
  1153         for op, (sc,sr), (ec,er), weight, color, cap, dash, join, count, space in self._linecmds:
  1149             if isinstance(sr,basestring) and sr.startswith('split'):
  1154             if isinstance(sr,basestring) and sr.startswith('split'):
  1196         if repeatRows:
  1201         if repeatRows:
  1197             #R1 = slelf.__class__(data[:repeatRows]+data[n:],self._argW,
  1202             #R1 = slelf.__class__(data[:repeatRows]+data[n:],self._argW,
  1198             R1 = self.__class__(data[:repeatRows]+data[n:],colWidths=self._colWidths,
  1203             R1 = self.__class__(data[:repeatRows]+data[n:],colWidths=self._colWidths,
  1199                     rowHeights=self._argH[:repeatRows]+self._argH[n:],
  1204                     rowHeights=self._argH[:repeatRows]+self._argH[n:],
  1200                     repeatRows=repeatRows, repeatCols=repeatCols,
  1205                     repeatRows=repeatRows, repeatCols=repeatCols,
  1201                     splitByRow=splitByRow)
  1206                     splitByRow=splitByRow, normalizedData=1,
  1202             R1._cellStyles = self._cellStyles[:repeatRows]+self._cellStyles[n:]
  1207                     cellStyles=self._cellStyles[:repeatRows]+self._cellStyles[n:])
  1203             R1._cr_1_1(n,repeatRows,A)
  1208             R1._cr_1_1(n,repeatRows,A)
  1204             R1._cr_1_1(n,repeatRows,self._bkgrndcmds)
  1209             R1._cr_1_1(n,repeatRows,self._bkgrndcmds)
  1205             R1._cr_1_1(n,repeatRows,self._spanCmds)
  1210             R1._cr_1_1(n,repeatRows,self._spanCmds)
  1206             R1._cr_1_1(n,repeatRows,self._nosplitCmds)
  1211             R1._cr_1_1(n,repeatRows,self._nosplitCmds)
  1207         else:
  1212         else:
  1208             #R1 = slelf.__class__(data[n:], self._argW, self._argH[n:],
  1213             #R1 = slelf.__class__(data[n:], self._argW, self._argH[n:],
  1209             R1 = self.__class__(data[n:], colWidths=self._colWidths, rowHeights=self._argH[n:],
  1214             R1 = self.__class__(data[n:], colWidths=self._colWidths, rowHeights=self._argH[n:],
  1210                     repeatRows=repeatRows, repeatCols=repeatCols,
  1215                     repeatRows=repeatRows, repeatCols=repeatCols,
  1211                     splitByRow=splitByRow)
  1216                     splitByRow=splitByRow, normalizedData=1, cellStyles=self._cellStyles[n:])
  1212             R1._cellStyles = self._cellStyles[n:]
       
  1213             R1._cr_1_0(n,A)
  1217             R1._cr_1_0(n,A)
  1214             R1._cr_1_0(n,self._bkgrndcmds)
  1218             R1._cr_1_0(n,self._bkgrndcmds)
  1215             R1._cr_1_0(n,self._spanCmds)
  1219             R1._cr_1_0(n,self._spanCmds)
  1216             R1._cr_1_0(n,self._nosplitCmds)
  1220             R1._cr_1_0(n,self._nosplitCmds)
  1217 
  1221