1#!/usr/bin/env python3
2
3"""Widget to add a list of figures section to a report."""
4
5
6
7from chart.reports.widget import Widget
8from chart.common import traits
9
10
11class ListOfFigures(Widget):
12 """Scan through the Document.figures object and create list of figures."""
13
14 name = 'list-of-figures'
15
16 thumbnail = 'widgets/listoffigures.png'
17
18 def __init__(self):
19 super(ListOfFigures, self).__init__()
20 self.output = None
21
22 def html(self, document):
23 self.output = document.html
24
25 def post_html(self, document):
26 # html = document.html
27 html = self.output
28 html.write("""<h2>List of figures</h2>
29 <ul>
30""")
31 for figure_cc, figure in enumerate(document.figures):
32 html.write(' <li>'
33 '<a href="#figure-{figure_cc}">'
34 'Figure {figure_cc} {figure}'
35 '</a></li>\n'.format(figure_cc=figure_cc + 1,
36 figure=traits.to_htmlstr(figure)))
37
38 html.write(' </ul>\n')
39 html.write('<p> </p>\n')