reportlab/platypus/tableofcontents.py
author andy_robinson
Mon, 26 Nov 2001 21:49:01 +0000
changeset 1440 243d35446390
parent 817 8c3a399effda
child 1444 454d117af3a5
permissions -rw-r--r--
Removed 0 from multiBuild stuff prior to further changes; ensured test suite really does run silently when making manuals.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
817
8c3a399effda License text changes
rgbecker
parents: 754
diff changeset
     1
#copyright ReportLab Inc. 2000-2001
8c3a399effda License text changes
rgbecker
parents: 754
diff changeset
     2
#see license.txt for license details
8c3a399effda License text changes
rgbecker
parents: 754
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/tableofcontents.py?cvsroot=reportlab
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
     4
#$Header: /tmp/reportlab/reportlab/platypus/tableofcontents.py,v 1.3 2001/11/26 21:49:01 andy_robinson Exp $
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
     5
"""
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
     6
This module defines a single TableOfContents() class that can be used to
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
     7
create automatically a table of tontents for Platypus documents like
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
     8
this:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
     9
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    10
    story = []
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    11
    toc = TableOfContents()
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    12
    story.append(toc)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    13
    # some heading paragraphs here...
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    14
    doc = MyTemplate(path)
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    15
    doc.multiBuild(story)
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    16
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    17
The data needed to create the table is a list of (level, text, pageNum)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    18
triplets, plus some paragraph styles for each level of the table itself.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    19
The triplets will usually be created in a document template's method
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    20
like afterFlowable(), making notification calls using the notify()
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    21
method with appropriate data like this:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    22
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    23
    (level, text, pageNum) = ...
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    24
    self.notify('TOCEntry', (level, text, pageNum))
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    25
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    26
As the table of contents need at least two passes over the Platypus
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    27
story which is why the moultiBuild0() method must be called.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    28
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    29
The level<NUMBER>ParaStyle variables are the paragraph styles used
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    30
to format the entries in the table of contents. Their indentation
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    31
is calculated like this: each entry starts at a multiple of some
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    32
constant named delta. If one entry spans more than one line, all
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    33
lines after the first are indented by the same constant named
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    34
epsilon. 
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    35
"""
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    36
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    37
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    38
from reportlab.lib import enums
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    39
from reportlab.lib.units import cm
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    40
from reportlab.lib.styles import ParagraphStyle
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    41
from reportlab.platypus.paragraph import Paragraph
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    42
from reportlab.platypus.doctemplate import IndexingFlowable
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    43
from reportlab.platypus.tables import TableStyle, Table
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    44
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    45
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    46
# Default paragraph styles for tables of contents.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    47
# (This could also be generated automatically or even
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    48
# on-demand if it is not known how many levels the
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    49
# TOC will finally need to display...)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    50
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    51
delta = 1*cm
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    52
epsilon = 0.5*cm
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    53
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    54
levelZeroParaStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    55
    ParagraphStyle(name='LevelZero',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    56
                   fontName='Times-Roman',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    57
                   fontSize=10,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    58
                   leading=11,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    59
                   firstLineIndent = -epsilon,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    60
                   leftIndent = 0*delta + epsilon)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    61
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    62
levelOneParaStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    63
    ParagraphStyle(name='LevelOne',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    64
                   parent = levelZeroParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    65
                   leading=11,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    66
                   firstLineIndent = -epsilon,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    67
                   leftIndent = 1*delta + epsilon)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    68
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    69
levelTwoParaStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    70
    ParagraphStyle(name='LevelTwo',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    71
                   parent = levelOneParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    72
                   leading=11,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    73
                   firstLineIndent = -epsilon,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    74
                   leftIndent = 2*delta + epsilon)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    75
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    76
levelThreeParaStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    77
    ParagraphStyle(name='LevelThree',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    78
                   parent = levelTwoParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    79
                   leading=11,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    80
                   firstLineIndent = -epsilon,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    81
                   leftIndent = 3*delta + epsilon)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    82
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    83
levelFourParaStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    84
    ParagraphStyle(name='LevelFour',
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    85
                   parent = levelTwoParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    86
                   leading=11,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    87
                   firstLineIndent = -epsilon,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    88
                   leftIndent = 4*delta + epsilon)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    89
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    90
defaultTableStyle = \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    91
    TableStyle([('VALIGN', (0,0), (-1,-1), 'TOP')])
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    92
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    93
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
    94
class TableOfContents(IndexingFlowable):
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    95
    """This creates a formatted table of contents.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    96
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    97
    It presumes a correct block of data is passed in.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    98
    The data block contains a list of (level, text, pageNumber)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
    99
    triplets.  You can supply a paragraph style for each level
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   100
    (starting at zero).
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   101
    """
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   102
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   103
    def __init__(self):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   104
        self.entries = []
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   105
        self.rightColumnWidth = 72
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   106
        self.levelStyles = [levelZeroParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   107
                            levelOneParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   108
                            levelTwoParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   109
                            levelThreeParaStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   110
                            levelFourParaStyle]
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   111
        self.tableStyle = defaultTableStyle
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   112
        self._table = None
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   113
        self._entries = []
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   114
        self._lastEntries = []
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   115
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   116
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   117
    def beforeBuild(self):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   118
        # keep track of the last run
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   119
        self._lastEntries = self._entries[:]
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   120
        self.clearEntries()
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   121
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   122
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   123
    def isIndexing(self):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   124
        return 1
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   125
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   126
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   127
    def isSatisfied(self):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   128
        return (self._entries == self._lastEntries)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   129
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   130
1440
243d35446390 Removed 0 from multiBuild stuff prior to further changes;
andy_robinson
parents: 817
diff changeset
   131
    # Shouldn't that be notify??
754
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   132
    def notify(self, kind, stuff):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   133
        """The notification hook called to register all kinds of events.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   134
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   135
        Here we are interested in 'TOCEntry' events only.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   136
        """
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   137
        if kind == 'TOCEntry':
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   138
            (level, text, pageNum) = stuff
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   139
            self.addEntry(level, text, pageNum)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   140
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   141
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   142
    def clearEntries(self):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   143
        self._entries = []
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   144
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   145
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   146
    def addEntry(self, level, text, pageNum):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   147
        """Adds one entry to the table of contents.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   148
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   149
        This allows incremental buildup by a doctemplate.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   150
        Requires that enough styles are defined."""
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   151
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   152
        assert type(level) == type(1), "Level must be an integer"
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   153
        assert level < len(self.levelStyles), \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   154
               "Table of contents must have a style defined " \
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   155
               "for paragraph level %d before you add an entry" % level
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   156
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   157
        self._entries.append((level, text, pageNum))
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   158
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   159
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   160
    def addEntries(self, listOfEntries):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   161
        """Bulk creation of entries in the table of contents.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   162
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   163
        If you knew the titles but not the page numbers, you could
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   164
        supply them to get sensible output on the first run."""
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   165
        
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   166
        for (level, text, pageNum) in listOfEntries:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   167
            self.addEntry(level, text, pageNum)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   168
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   169
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   170
    def wrap(self, availWidth, availHeight):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   171
        "All table properties should be known by now."
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   172
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   173
        widths = (availWidth - self.rightColumnWidth,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   174
                  self.rightColumnWidth)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   175
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   176
        # makes an internal table which does all the work.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   177
        # we draw the LAST RUN's entries!  If there are
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   178
        # none, we make some dummy data to keep the table
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   179
        # from complaining
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   180
        if len(self._lastEntries) == 0:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   181
            _tempEntries = [(0,'Placeholder for table of contents',0)]
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   182
        else:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   183
            _tempEntries = self._lastEntries
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   184
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   185
        tableData = []
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   186
        for (level, text, pageNum) in _tempEntries:
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   187
            leftColStyle = self.levelStyles[level]
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   188
            #right col style is right aligned
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   189
            rightColStyle = ParagraphStyle(name='leftColLevel%d' % level,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   190
                                           parent=leftColStyle,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   191
                                           leftIndent=0,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   192
                                           alignment=enums.TA_RIGHT)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   193
            leftPara = Paragraph(text, leftColStyle)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   194
            rightPara = Paragraph(str(pageNum), rightColStyle)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   195
            tableData.append([leftPara, rightPara])
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   196
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   197
        self._table = Table(tableData, colWidths=widths,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   198
                            style=self.tableStyle)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   199
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   200
        self.width, self.height = self._table.wrap(availWidth, availHeight)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   201
        return (self.width, self.height)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   202
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   203
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   204
    def split(self, availWidth, availHeight):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   205
        """At this stage we do not care about splitting the entries,
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   206
        we will just return a list of platypus tables.  Presumably the
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   207
        calling app has a pointer to the original TableOfContents object;
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   208
        Platypus just sees tables.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   209
        """
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   210
        return self._table.split(availWidth, availHeight)
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   211
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   212
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   213
    def drawOn(self, canvas, x, y, _sW=0):
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   214
        """Don't do this at home!  The standard calls for implementing
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   215
        draw(); we are hooking this in order to delegate ALL the drawing
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   216
        work to the embedded table object.
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   217
        """
ac7d1e99bd3e Replaced trailing digit file.
dinu_gherman
parents:
diff changeset
   218
        self._table.drawOn(canvas, x, y, _sW)