1 """Micro reports objects.
2
3 A micro report is a tree of layout and content objects.
4
5 :copyright:
6 2004-2008 `LOGILAB S.A. <http://www.logilab.fr>`_ (Paris, FRANCE),
7 all rights reserved.
8
9 :contact:
10 http://www.logilab.org/project/logilab-common --
11 mailto:python-projects@logilab.org
12
13 :license:
14 `General Public License version 2
15 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>`_
16 """
17 __docformat__ = "restructuredtext en"
18
19 from logilab.common.tree import VNode
20
22 """base report component
23
24 attributes
25 * id : the component's optional id
26 * klass : the component's optional klass
27 """
28 - def __init__(self, id=None, klass=None):
31
33 """base container node
34
35 attributes
36 * BaseComponent attributes
37 * children : components in this table (i.e. the table's cells)
38 """
39 - def __init__(self, children=(), **kwargs):
46
48 """overridden to detect problems easily"""
49 assert child not in self.parents()
50 VNode.append(self, child)
51
53 """return the ancestor nodes"""
54 assert self.parent is not self
55 if self.parent is None:
56 return []
57 return [self.parent] + self.parent.parents()
58
59 - def add_text(self, text):
60 """shortcut to add text data"""
61 self.children.append(Text(text))
62
63
64
65
66 -class Text(BaseComponent):
67 """a text portion
68
69 attributes :
70 * BaseComponent attributes
71 * data : the text value as an encoded or unicode string
72 """
73 - def __init__(self, data, escaped=True, **kwargs):
74 super(Text, self).__init__(**kwargs)
75
76
77 assert isinstance(data, (str, unicode)), data.__class__
78 self.escaped = escaped
79 self.data = data
80
81 -class VerbatimText(Text):
82 """a verbatim text, display the raw data
83
84 attributes :
85 * BaseComponent attributes
86 * data : the text value as an encoded or unicode string
87 """
88
89 -class Link(BaseComponent):
90 """a labelled link
91
92 attributes :
93 * BaseComponent attributes
94 * url : the link's target (REQUIRED)
95 * label : the link's label as a string (use the url by default)
96 """
97 - def __init__(self, url, label=None, **kwargs):
98 super(Link, self).__init__(**kwargs)
99 assert url
100 self.url = url
101 self.label = label or url
102
103
104 -class Image(BaseComponent):
105 """an embeded or a single image
106
107 attributes :
108 * BaseComponent attributes
109 * filename : the image's filename (REQUIRED)
110 * stream : the stream object containing the image data (REQUIRED)
111 * title : the image's optional title
112 """
113 - def __init__(self, filename, stream, title=None, **kwargs):
114 super(Link, self).__init__(**kwargs)
115 assert filename
116 assert stream
117 self.filename = filename
118 self.stream = stream
119 self.title = title
120
121
122
123
125 """a section
126
127 attributes :
128 * BaseLayout attributes
129
130 a title may also be given to the constructor, it'll be added
131 as a first element
132 a description may also be given to the constructor, it'll be added
133 as a first paragraph
134 """
135 - def __init__(self, title=None, description=None, **kwargs):
141
143 """a title
144
145 attributes :
146 * BaseLayout attributes
147
148 A title must not contains a section nor a paragraph!
149 """
150
151 -class Span(BaseLayout):
152 """a title
153
154 attributes :
155 * BaseLayout attributes
156
157 A span should only contains Text and Link nodes (in-line elements)
158 """
159
161 """a simple text paragraph
162
163 attributes :
164 * BaseLayout attributes
165
166 A paragraph must not contains a section !
167 """
168
170 """some tabular data
171
172 attributes :
173 * BaseLayout attributes
174 * cols : the number of columns of the table (REQUIRED)
175 * rheaders : the first row's elements are table's header
176 * cheaders : the first col's elements are table's header
177 * title : the table's optional title
178 """
179 - def __init__(self, cols, title=None,
180 rheaders=0, cheaders=0, rrheaders=0, rcheaders=0,
181 **kwargs):
182 super(Table, self).__init__(**kwargs)
183 assert isinstance(cols, int)
184 self.cols = cols
185 self.title = title
186 self.rheaders = rheaders
187 self.cheaders = cheaders
188 self.rrheaders = rrheaders
189 self.rcheaders = rcheaders
190
191 -class List(BaseLayout):
192 """some list data
193
194 attributes :
195 * BaseLayout attributes
196 """
197