src/reportlab/platypus/tableofcontents.py
changeset 4551 d357e2acc856
parent 4528 e09377955af8
equal deleted inserted replaced
4550:80dd9e83dad9 4551:d357e2acc856
     1 #Copyright ReportLab Europe Ltd. 2000-2017
     1 #Copyright ReportLab Europe Ltd. 2000-2017
     2 #see license.txt for license details
     2 #see license.txt for license details
     3 #history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/platypus/tableofcontents.py
     3 #history https://hg.reportlab.com/hg-public/reportlab/log/tip/src/reportlab/platypus/tableofcontents.py
     4 
     4 
     5 __version__='3.3.0'
     5 __version__='3.5.32'
     6 __doc__="""Experimental class to generate Tables of Contents easily
     6 __doc__="""Experimental class to generate Tables of Contents easily
     7 
     7 
     8 This module defines a single TableOfContents() class that can be used to
     8 This module defines a single TableOfContents() class that can be used to
     9 create automatically a table of tontents for Platypus documents like
     9 create automatically a table of tontents for Platypus documents like
    10 this:
    10 this:
    46 
    46 
    47 from reportlab.lib import enums
    47 from reportlab.lib import enums
    48 from reportlab.lib.units import cm
    48 from reportlab.lib.units import cm
    49 from reportlab.lib.utils import commasplit, escapeOnce, encode_label, decode_label, strTypes, asUnicode, asNative
    49 from reportlab.lib.utils import commasplit, escapeOnce, encode_label, decode_label, strTypes, asUnicode, asNative
    50 from reportlab.lib.styles import ParagraphStyle, _baseFontName
    50 from reportlab.lib.styles import ParagraphStyle, _baseFontName
       
    51 from reportlab.lib import sequencer as rl_sequencer
    51 from reportlab.platypus.paragraph import Paragraph
    52 from reportlab.platypus.paragraph import Paragraph
    52 from reportlab.platypus.doctemplate import IndexingFlowable
    53 from reportlab.platypus.doctemplate import IndexingFlowable
    53 from reportlab.platypus.tables import TableStyle, Table
    54 from reportlab.platypus.tables import TableStyle, Table
    54 from reportlab.platypus.flowables import Spacer, Flowable
    55 from reportlab.platypus.flowables import Spacer, Flowable
    55 from reportlab.pdfbase.pdfmetrics import stringWidth
    56 from reportlab.pdfbase.pdfmetrics import stringWidth
    56 from reportlab.pdfgen import canvas
    57 from reportlab.pdfgen import canvas
    57 import unicodedata
    58 import unicodedata
       
    59 from ast import literal_eval
    58 
    60 
    59 def unquote(txt):
    61 def unquote(txt):
    60     from xml.sax.saxutils import unescape
    62     from xml.sax.saxutils import unescape
    61     return unescape(txt, {"'": "'", """: '"'})
    63     return unescape(txt, {"'": "'", """: '"'})
    62 
    64 
   237             _tempEntries = self._lastEntries
   239             _tempEntries = self._lastEntries
   238 
   240 
   239         def drawTOCEntryEnd(canvas, kind, label):
   241         def drawTOCEntryEnd(canvas, kind, label):
   240             '''Callback to draw dots and page numbers after each entry.'''
   242             '''Callback to draw dots and page numbers after each entry.'''
   241             label = label.split(',')
   243             label = label.split(',')
   242             page, level, key = int(label[0]), int(label[1]), eval(label[2],{})
   244             page, level, key = int(label[0]), int(label[1]), literal_eval(label[2])
   243             style = self.getLevelStyle(level)
   245             style = self.getLevelStyle(level)
   244             if self.dotsMinLevel >= 0 and level >= self.dotsMinLevel:
   246             if self.dotsMinLevel >= 0 and level >= self.dotsMinLevel:
   245                 dot = ' . '
   247                 dot = ' . '
   246             else:
   248             else:
   247                 dot = ''
   249                 dot = ''
   303         self._entries = {}
   305         self._entries = {}
   304         self._lastEntries = {}
   306         self._lastEntries = {}
   305         self._flowable = None
   307         self._flowable = None
   306         self.setup(**kwargs)
   308         self.setup(**kwargs)
   307 
   309 
   308     def getFormatFunc(self,format):
   310     def getFormatFunc(self,formatName):
   309         try:
   311         try:
   310             D = {}
   312             return getattr(rl_sequencer,'_format_%s' % formatName)
   311             exec('from reportlab.lib.sequencer import _format_%s as formatFunc' % format, D)
       
   312             return D['formatFunc']
       
   313         except ImportError:
   313         except ImportError:
   314             raise ValueError('Unknown format %r' % format)
   314             raise ValueError('Unknown sequencer format %r' % formatName)
   315 
   315 
   316     def setup(self, style=None, dot=None, tableStyle=None, headers=True, name=None, format='123', offset=0):
   316     def setup(self, style=None, dot=None, tableStyle=None, headers=True, name=None, format='123', offset=0):
   317         """
   317         """
   318         This method makes it possible to change styling and other parameters on an existing object.
   318         This method makes it possible to change styling and other parameters on an existing object.
   319 
   319