[reportlab-users] Multi-level chapter prefixes in TOCs?

Dinu Gherman gherman at darwin.in-berlin.de
Sat Apr 19 08:14:52 EDT 2008


Hi,

I'm trying to get slightly more beefed-up versions of table
of contents as available in the module

reportlab/platypus/tableofcontents.py.

So I'm trying to modify the file

reportlab/test/test_platypus_toc.py

in order to add multi-level chapter numbering prefixes to the
entries in the table of contents. Since I don't see another
possibility to pass a seperate chapter number to the toc, I'm
overwriting the afterFlowable() method of the DocTemplate class
very slightly to include the following lines:

dinu$ diff -u test_platypus_toc.py test_platypus_toc1.py
--- test_platypus_toc.py 2008-04-19 12:31:59.000000000 +0200
+++ test_platypus_toc1.py 2008-04-19 14:06:01.000000000 +0200
@@ -64,7 +64,16 @@
if styleName[:7] == 'Heading':
# Register TOC entries.
level = int(styleName[7:])
- text = flowable.getPlainText()
+
+ # test adding multi-level chap prefixes to toc entries
+ if not hasattr(self, "chapNum"):
+ self.chapNum = [0]*3
+ self.chapNum[level] += 1
+ # text = flowable.getPlainText()
+ chapPrefix = ".".join(map(str, self.chapNum)) + " "
+ text = chapPrefix + flowable.getPlainText()
+ print "***", text
+
pageNum = self.page
self.notify('TOCEntry', (level, text, pageNum))

Unfortunately, this gives me the following traceback:

Traceback (most recent call last):
File "test_platypus_toc1.py", line 190, in test0
doc.multiBuild(story)
File "/usr/local/lib/python2.5/site-packages/reportlab/platypus/
doctemplate.py", line 832, in multiBuild
raise IndexError, "Index entries not resolved after %d passes" %
maxPasses
IndexError: Index entries not resolved after 10 passes

Maybe somebody knows what's going on here? Or is there another,
less stupid way of doing it? I'm including the modified generator
script.

Thanks,

Dinu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_platypus_toc1.py
Type: text/x-python-script
Size: 6603 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080419/a0051f3e/attachment.bin>
-------------- next part --------------



More information about the reportlab-users mailing list