[reportlab-users] Problems with tables containing Para flowables

Dirk Holtwick holtwick at spirito.de
Tue Jan 2 13:59:24 EST 2007


Hi,

I experienced problems using Para() elements (recent SVN version) within
Platypus Tables. The tables always consumed more space than available.
Therfore I wrote a little patch that overrides the calculations done by
the Reportlab Table Class. It adds a "totalWidth" attribute to the Table
object and calculates entries width "*" and None the way they consume
the available space.

Hope this may be usefull. Code follows.

Yours Dirk

---

class PmlTable(Table):

def _normWidth(self, w, maxw):
" Helper for calculating percentages "
if type(w)==type(""):
w = ((maxw/100.0) * float(w[:-1]))
elif (w is None) or (w=="*"):
w = maxw
return min(w, maxw)

def wrap(self, availWidth, availHeight):

# Prepare values
totalWidth = self._normWidth(self.totalWidth, availWidth)
remainingWidth = totalWidth
remainingCols = 0
newColWidths = self._colWidths

# Calculate widths that are fix
# IMPORTANT!!! We can not substitute the private value
# self._colWidths therefore we have to modify list in place
for i in range(len(newColWidths)):
colWidth = newColWidths[i]
if (colWidth is not None) or (colWidth=='*'):
colWidth = self._normWidth(colWidth, totalWidth)
remainingWidth -= colWidth
else:
remainingCols += 1
colWidth = None
newColWidths[i] = (colWidth)

# Distribute remaining space
if remainingCols:
for i in range(len(newColWidths)):
if newColWidths[i] is None:
newColWidths[i] = (remainingWidth / remainingCols)

# print "New values:", totalWidth, newColWidths, sum(newColWidths)

# Call original method "wrap()"
# self._colWidths = newColWidths
return Table.wrap(self, availWidth, availHeight)

t = PmlTable(...)
t.totalWidth = _width(tdata.width)



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

spirito GmbH
Dirk Holtwick
Grünstraße 6
D-47051 Duisburg

fon: +49-203-3187777
fax: +49-203-34666896
mbx: holtwick at spirito.de
web: http://www.spirito.de
skype: holtwick

GnuPG fingerprint (http://www.gnupg.org)
A5A1 54E1 C82E 02AD 4804 0547 66F4 3FB0 C790 EBAB

Wichtiger Hinweis:

E-Mails können leicht verfälscht oder unter fremdem Namen erstellt
werden. Zu Ihrer und unserer Sicherheit schließen wir die rechtliche
Verbindlichkeit des vorstehenden Inhaltes aus, mithin dient der
Versand von E-Mails ausschließlich dem Informationsaustausch.
Bitte senden Sie in Ihrem eigenen Interesse keine E-Mails in
fristgebundenen Sachen.


More information about the reportlab-users mailing list