added largest row to table splitting error messages
authorandy
Mon, 20 Jun 2011 15:49:26 +0000
changeset 3523 9f062de04bc6
parent 3522 9a6f6e30d49b
child 3524 99211a1ae4bd
added largest row to table splitting error messages
src/reportlab/platypus/doctemplate.py
src/reportlab/platypus/tables.py
--- a/src/reportlab/platypus/doctemplate.py	Mon Jun 20 15:43:31 2011 +0000
+++ b/src/reportlab/platypus/doctemplate.py	Mon Jun 20 15:49:26 2011 +0000
@@ -57,6 +57,7 @@
     pass
 
 def _fSizeString(f):
+    #used to get size during error messages
     w=getattr(f,'width',None)
     if w is None:
         w=getattr(f,'_width',None)
@@ -64,10 +65,15 @@
     h=getattr(f,'height',None)
     if h is None:
         h=getattr(f,'_height',None)
+    #tables in particular may have some nasty large culprit
+    if hasattr(f, '_culprit'):
+        c = ', %s, ' % f._culprit()
+    else:
+        c = ''
     if w is not None or h is not None:
         if w is None: w='???'
         if h is None: h='???'
-        return '(%s x %s)' % (w,h)
+        return '(%s x %s)%s' % (w,h,c)
     return ''
 
 def _doNothing(canvas, doc):
--- a/src/reportlab/platypus/tables.py	Mon Jun 20 15:43:31 2011 +0000
+++ b/src/reportlab/platypus/tables.py	Mon Jun 20 15:49:26 2011 +0000
@@ -323,6 +323,7 @@
         nr = getattr(self,'_nrows','unknown')
         nc = getattr(self,'_ncols','unknown')
         cv = getattr(self,'_cellvalues',None)
+        rh = getattr(self, '_rowHeights', None)
         if cv and 'unknown' not in (nr,nc):
             b = 0
             for i in xrange(nr):
@@ -344,12 +345,16 @@
                         if maxLen: vx = vx[:maxLen]
                     if b: break
                 if b: break
+        if rh:  #find tallest row, it's of great interest'
+            tallest = '(tallest row %d)' % int(max(rh))
+        else:
+            tallest = ''
         if vx:
             vx = ' with cell(%d,%d) containing\n%s' % (ix,jx,repr(vx))
         else:
             vx = '...'
 
-        return "<%s@0x%8.8X %s rows x %s cols>%s" % (self.__class__.__name__, id(self), nr, nc, vx)
+        return "<%s@0x%8.8X %s rows x %s cols%s>%s" % (self.__class__.__name__, id(self), nr, nc, tallest, vx)
 
     def _cellListIter(self,C,aW,aH):
         canv = getattr(self,'canv',None)
@@ -618,6 +623,23 @@
             #now work out the actual rect for each spanned cell from the underlying grid
             self._calcSpanRects()
 
+    def _culprit(self):
+        """Return a string describing the tallest element.
+        
+        Usually this is what causes tables to fail to split.  Currently
+        tables are the only items to have a '_culprit' method. Doctemplate
+        checks for it.
+        """
+        rh = self._rowHeights
+        tallest = max(rh)
+        rowNum = rh.index(tallest)
+        #rowNum of limited interest as usually it's a split one
+        #and we see row #1.  Text might be a nice addition.
+        
+        return 'tallest cell %0.1f points' % tallest
+        
+        
+
     def _hasVariWidthElements(self, upToRow=None):
         """Check for flowables in table cells and warn up front.
 
@@ -1136,7 +1158,6 @@
 
     def wrap(self, availWidth, availHeight):
         self._calc(availWidth, availHeight)
-        #nice and easy, since they are predetermined size
         self.availWidth = availWidth
         return (self._width, self._height)