587
|
1 |
#============================================================================
|
|
2 |
#Name : widgets.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
588
|
19 |
""" handles components in XML documents"""
|
587
|
20 |
|
628
|
21 |
# pylint: disable=E1101
|
587
|
22 |
|
|
23 |
import xml.dom.minidom
|
|
24 |
class Widget:
|
|
25 |
""" Class Widget represents a component in an xml document """
|
|
26 |
def __init__(self):
|
|
27 |
pass
|
|
28 |
|
|
29 |
def getDOMContainer(self):
|
588
|
30 |
"""get DOM container"""
|
587
|
31 |
pass
|
|
32 |
|
|
33 |
|
|
34 |
class Box(Widget):
|
|
35 |
""" A widget of type Box """
|
|
36 |
def __init__(self, doc, container, divId = "mb", divClass = "mc"):
|
|
37 |
Widget.__init__(self)
|
588
|
38 |
doc_1 = doc.createElementNS("", "div")
|
|
39 |
doc_1.setAttributeNS("", "id", divId)
|
|
40 |
container.appendChild(doc_1)
|
|
41 |
m_c = doc.createElementNS("", "div")
|
|
42 |
m_c.setAttributeNS("", "class", divClass)
|
|
43 |
doc_1.appendChild(m_c)
|
587
|
44 |
self.__doc = doc
|
|
45 |
self.__title = None
|
588
|
46 |
self.__mc = m_c
|
587
|
47 |
|
|
48 |
def setTitle(self, title=""):
|
588
|
49 |
"""set the title"""
|
587
|
50 |
if self.__title == None:
|
588
|
51 |
t_doc = self.__doc.createElementNS("", "h1")
|
|
52 |
self.__mc.insertBefore(t_doc, self.__mc.firstChild)
|
587
|
53 |
self.__title = self.__doc.createTextNode(title)
|
588
|
54 |
t_doc.appendChild(self.__title)
|
587
|
55 |
self.__title.data = title
|
|
56 |
|
|
57 |
def getDOMContainer(self):
|
588
|
58 |
"""get DOM container"""
|
587
|
59 |
return self.__mc
|
|
60 |
|
588
|
61 |
class Summary(Box):
|
587
|
62 |
""" A widget representing a summary component """
|
|
63 |
def __init__(self, doc, container):
|
|
64 |
Box.__init__(self, doc, container, divId = "s_mb", divClass = "s_mc")
|
|
65 |
self.__table = doc.createElementNS("", "table")
|
|
66 |
self.__table.setAttributeNS("", "cellspacing", "0")
|
|
67 |
self.__table.setAttributeNS("", "cellpadding", "0")
|
|
68 |
self.__table.setAttributeNS("", "border", "0")
|
|
69 |
self.__table.setAttributeNS("", "width", "100%")
|
|
70 |
self.__table.appendChild(self._Box__doc.createTextNode(""))
|
|
71 |
div = self._Box__doc.createElementNS("", "div")
|
|
72 |
div.setAttributeNS("", "class", "t_wrapper")
|
|
73 |
div.appendChild(self.__table)
|
|
74 |
self.getDOMContainer().appendChild(div)
|
|
75 |
self.__table_stat = None
|
|
76 |
self.setTitle()
|
|
77 |
|
|
78 |
|
|
79 |
def addElement(self, tag, value):
|
588
|
80 |
"""add Element"""
|
587
|
81 |
row = self._Box__doc.createElementNS("", "tr")
|
|
82 |
#Tag
|
588
|
83 |
t_d = self._Box__doc.createElementNS("", "td")
|
|
84 |
t_d.setAttributeNS("", "valign", "top")
|
|
85 |
t_d.setAttributeNS("", "nowrap", "nowrap")
|
587
|
86 |
div = self._Box__doc.createElementNS("", "div")
|
|
87 |
div.setAttributeNS("", "class", "s_tag")
|
|
88 |
div.appendChild(self._Box__doc.createTextNode(tag))
|
588
|
89 |
t_d.appendChild(div)
|
|
90 |
row.appendChild(t_d)
|
587
|
91 |
|
|
92 |
# Value
|
588
|
93 |
t_d = self._Box__doc.createElementNS("", "td")
|
|
94 |
t_d.setAttributeNS("", "width", "100%")
|
587
|
95 |
div = self._Box__doc.createElementNS("", "div")
|
|
96 |
div.setAttributeNS("", "class", "s_val")
|
|
97 |
div.appendChild(self._Box__doc.createTextNode(value))
|
588
|
98 |
t_d.appendChild(div)
|
|
99 |
row.appendChild(t_d)
|
587
|
100 |
|
|
101 |
self.__table.appendChild(row)
|
|
102 |
|
628
|
103 |
def addStatistics(self, type_, value):
|
588
|
104 |
"""add Statistics"""
|
587
|
105 |
if self.__table_stat == None:
|
588
|
106 |
head1 = self._Box__doc.createElementNS("", "h1")
|
|
107 |
head1.appendChild(self._Box__doc.createTextNode("Global Statistics"))
|
|
108 |
self.getDOMContainer().appendChild(head1)
|
587
|
109 |
|
|
110 |
div = self._Box__doc.createElementNS("", "div")
|
|
111 |
div.setAttributeNS("", "class", "t_wrapper")
|
|
112 |
self.getDOMContainer().appendChild(div)
|
|
113 |
self.__table_stat = self._Box__doc.createElementNS("", "table")
|
|
114 |
self.__table_stat.setAttributeNS("", "cellspacing", "0")
|
|
115 |
self.__table_stat.setAttributeNS("", "cellpadding", "0")
|
|
116 |
self.__table_stat.setAttributeNS("", "border", "0")
|
|
117 |
self.__table_stat.setAttributeNS("", "width", "100%")
|
|
118 |
div.appendChild(self.__table_stat)
|
|
119 |
|
|
120 |
row = self._Box__doc.createElementNS("", "tr")
|
|
121 |
self.__table_stat.appendChild(row)
|
|
122 |
self.__table_stat = row
|
|
123 |
|
588
|
124 |
t_d = self._Box__doc.createElementNS("", "td")
|
587
|
125 |
div = self._Box__doc.createElementNS("", "div")
|
628
|
126 |
div.setAttributeNS("", "class", "gbl_cnt_" + type_)
|
|
127 |
div.appendChild(self._Box__doc.createTextNode("%d %ss" % (value, type_)))
|
588
|
128 |
t_d.appendChild(div)
|
|
129 |
self.__table_stat.appendChild(t_d)
|
587
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
class Event(Widget):
|
|
134 |
""" A widget representing an event component """
|
628
|
135 |
def __init__(self, doc, container, id_):
|
587
|
136 |
Widget.__init__(self)
|
|
137 |
self.__doc = doc
|
|
138 |
node_head = doc.createElementNS("", "div")
|
|
139 |
node_head.setAttributeNS("", "class", "node_head")
|
|
140 |
container.appendChild(node_head)
|
|
141 |
|
|
142 |
link = doc.createElementNS("", "a")
|
628
|
143 |
link.setAttributeNS("", "href", "javascript:ToggleNode('Img%d')" % id_)
|
587
|
144 |
node_head.appendChild(link)
|
|
145 |
|
|
146 |
span = doc.createElementNS("", "span")
|
628
|
147 |
span.setAttributeNS("", "id", "Img%d" % id_)
|
587
|
148 |
span.setAttributeNS("", "style", "background:url(http://fawww.europe.nokia.com/isis/isis_interface/img/icons/button_open.gif) no-repeat")
|
|
149 |
link.appendChild(span)
|
|
150 |
|
|
151 |
stitle = doc.createElementNS("", "span")
|
|
152 |
stitle.setAttributeNS("", "class", "node_title")
|
|
153 |
self.__title = doc.createTextNode("")
|
|
154 |
stitle.appendChild(self.__title)
|
|
155 |
span.appendChild(stitle)
|
|
156 |
|
|
157 |
# shaow all
|
|
158 |
showall = doc.createElementNS("", "a")
|
628
|
159 |
showall.setAttributeNS("", "href", "javascript:ShowChilds('Img%d')" % id_)
|
587
|
160 |
span = doc.createElementNS("", "span")
|
|
161 |
span.setAttributeNS("", "class", "node_action")
|
|
162 |
span.appendChild(doc.createTextNode("[Show All]"))
|
|
163 |
showall.appendChild(span)
|
|
164 |
|
|
165 |
#hide all
|
|
166 |
hideall = doc.createElementNS("", "a")
|
628
|
167 |
hideall.setAttributeNS("", "href", "javascript:HideChilds('Img%d')" % id_)
|
587
|
168 |
span = doc.createElementNS("", "span")
|
|
169 |
span.setAttributeNS("", "class", "node_action")
|
|
170 |
span.appendChild(doc.createTextNode("[Hide All]"))
|
|
171 |
hideall.appendChild(span)
|
|
172 |
|
|
173 |
#toggle node
|
|
174 |
self.__togglenode = doc.createElementNS("", "a")
|
628
|
175 |
self.__togglenode.setAttributeNS("", "href", "javascript:ToggleNode('Img%d')" % id_)
|
587
|
176 |
self.__togglenode.appendChild(doc.createTextNode(""))
|
|
177 |
# append container
|
|
178 |
node_head.appendChild(showall)
|
|
179 |
node_head.appendChild(hideall)
|
588
|
180 |
node_head.appendChild(self.__togglenode)
|
587
|
181 |
|
|
182 |
contentx = doc.createElementNS("", "div")
|
628
|
183 |
contentx.setAttributeNS("", "id", "Content%d" % id_)
|
587
|
184 |
contentx.setAttributeNS("", "style", "display:none")
|
|
185 |
container.appendChild(contentx)
|
|
186 |
content = doc.createElementNS("", "div")
|
|
187 |
content.setAttributeNS("", 'class', "node_content")
|
|
188 |
content.appendChild(doc.createTextNode(""))
|
|
189 |
contentx.appendChild(content)
|
|
190 |
self.__container = content
|
|
191 |
self.__node_info = None
|
|
192 |
|
|
193 |
def setTitle(self, title = ""):
|
588
|
194 |
"""set Title"""
|
587
|
195 |
self.__title.data = title
|
|
196 |
|
628
|
197 |
def addStatistics(self, type_, value):
|
588
|
198 |
"""add Statistics"""
|
587
|
199 |
if self.__node_info == None:
|
|
200 |
self.__node_info = self.__doc.createElementNS("", "span")
|
|
201 |
self.__node_info.setAttributeNS("", "class", "node_info")
|
|
202 |
self.__togglenode.appendChild(self.__node_info)
|
|
203 |
span = self.__doc.createElementNS("", "span")
|
628
|
204 |
span.setAttributeNS("", "class","cnt_%s" % type_)
|
|
205 |
span.appendChild(self.__doc.createTextNode("%d %ss" % (value, type_)))
|
587
|
206 |
self.__node_info.appendChild(span)
|
|
207 |
#<span class="node_info">
|
|
208 |
# <span class="cnt_warning">2 warnings</span>
|
|
209 |
#</span>
|
|
210 |
|
|
211 |
def getDOMContainer(self):
|
588
|
212 |
"""get DOM Container"""
|
587
|
213 |
return self.__container
|
|
214 |
|
|
215 |
|
|
216 |
class Header(Widget):
|
|
217 |
""" A widget representing a Header section """
|
|
218 |
def __init__(self, doc, container):
|
|
219 |
Widget.__init__(self)
|
|
220 |
self.__doc = doc
|
|
221 |
h_wrapper = self.__doc.createElementNS("", "div")
|
|
222 |
h_wrapper.setAttributeNS("", "id", "h_wrapper")
|
|
223 |
h_elmt = self.__doc.createElementNS("", "div")
|
|
224 |
h_elmt.setAttributeNS("", "class", "h_elmt")
|
|
225 |
h_wrapper.appendChild(h_elmt)
|
|
226 |
container.appendChild(h_wrapper)
|
|
227 |
#title
|
588
|
228 |
t_elem = self.__doc.createElementNS("", "div")
|
587
|
229 |
self.__title = doc.createTextNode("")
|
588
|
230 |
t_elem.appendChild(self.__title)
|
|
231 |
t_elem.setAttributeNS("", "class", "h_title")
|
|
232 |
h_elmt.appendChild(t_elem)
|
587
|
233 |
#subtitle
|
588
|
234 |
t_elem = self.__doc.createElementNS("", "div")
|
587
|
235 |
self.__subtitle = doc.createTextNode("")
|
588
|
236 |
t_elem.appendChild(self.__subtitle)
|
|
237 |
t_elem.setAttributeNS("", "class", "h_subtitle")
|
|
238 |
h_elmt.appendChild(t_elem)
|
587
|
239 |
|
|
240 |
|
|
241 |
|
588
|
242 |
def setTitle(self, title):
|
|
243 |
"""set Title"""
|
587
|
244 |
self.__title.data = title
|
|
245 |
|
588
|
246 |
def setSubTitle(self, title):
|
|
247 |
"""set Sub Title"""
|
587
|
248 |
self.__subtitle.data = title
|
|
249 |
|
|
250 |
def getDOMContainer(self):
|
588
|
251 |
"""get DOM Container"""
|
587
|
252 |
return None
|
|
253 |
|
|
254 |
class Footer(Widget):
|
|
255 |
""" A widget representing a footer section """
|
|
256 |
def __init__(self, doc, container):
|
|
257 |
Widget.__init__(self)
|
|
258 |
self.__doc = doc
|
|
259 |
h_wrapper = self.__doc.createElementNS("", "div")
|
|
260 |
h_wrapper.setAttributeNS("", "id", "f_wrapper")
|
|
261 |
h_elmt = self.__doc.createElementNS("", "div")
|
|
262 |
h_elmt.setAttributeNS("", "class", "f_elmt")
|
|
263 |
h_wrapper.appendChild(h_elmt)
|
|
264 |
container.appendChild(h_wrapper)
|
|
265 |
#title
|
588
|
266 |
t_elem = self.__doc.createElementNS("", "div")
|
587
|
267 |
self.__title = doc.createTextNode("")
|
588
|
268 |
t_elem.appendChild(self.__title)
|
|
269 |
t_elem.setAttributeNS("", "class", "f_title")
|
|
270 |
h_elmt.appendChild(t_elem)
|
587
|
271 |
#subtitle
|
588
|
272 |
t_elem = self.__doc.createElementNS("", "div")
|
587
|
273 |
self.__subtitle = doc.createTextNode("")
|
588
|
274 |
t_elem.appendChild(self.__subtitle)
|
|
275 |
t_elem.setAttributeNS("", "class", "f_subtitle")
|
|
276 |
h_elmt.appendChild(t_elem)
|
587
|
277 |
|
588
|
278 |
def setTitle(self, title):
|
|
279 |
"""set Title"""
|
587
|
280 |
self.__title.data = title
|
|
281 |
|
588
|
282 |
def setSubTitle(self, title):
|
|
283 |
"""set Sub Title"""
|
587
|
284 |
self.__subtitle.data = title
|
|
285 |
|
|
286 |
class Text(Widget):
|
|
287 |
""" A widget representing a text component """
|
|
288 |
def __init__(self, doc, container):
|
|
289 |
Widget.__init__(self)
|
|
290 |
self.__doc = doc
|
|
291 |
self.__div = self.__doc.createElementNS("", "div")
|
|
292 |
self.__div.setAttributeNS("", "class", "icn_dft")
|
|
293 |
container.appendChild(self.__div)
|
|
294 |
|
|
295 |
def setIcon(self, name):
|
588
|
296 |
"""set Icon"""
|
587
|
297 |
self.__div.setAttributeNS("", "class", name)
|
|
298 |
|
588
|
299 |
def appendText(self, text):
|
|
300 |
"""append Text"""
|
587
|
301 |
def pushContent(arg):
|
588
|
302 |
"""push Content"""
|
587
|
303 |
self.getDOMContainer().appendChild(self.__doc.createTextNode(arg))
|
|
304 |
self.getDOMContainer().appendChild(self.__doc.createElementNS("","br"))
|
628
|
305 |
[pushContent(line) for line in text.strip().split("\n")]
|
587
|
306 |
|
|
307 |
def getDOMContainer(self):
|
588
|
308 |
"""get DOM Container"""
|
587
|
309 |
return self.__div
|
|
310 |
|
|
311 |
class RawText(Text):
|
|
312 |
""" This class represents a raw text component """
|
|
313 |
def appendText(self, text):
|
588
|
314 |
"""append Text"""
|
587
|
315 |
for child in xml.dom.minidom.parseString("<xhtml>" + text.strip() + "</xhtml>").documentElement.childNodes:
|
|
316 |
self.getDOMContainer().appendChild(child.cloneNode(True))
|
|
317 |
|
|
318 |
class BoldText(Text):
|
|
319 |
""" This class represents a bold text component """
|
|
320 |
def __init__(self, doc, container):
|
|
321 |
Text.__init__(self, doc, container)
|
|
322 |
self.__bold = doc.createElementNS("","b")
|
|
323 |
self._Text__div.appendChild(self.__bold)
|
|
324 |
|
|
325 |
def getDOMContainer(self):
|
588
|
326 |
"""get DOM COntainer"""
|
587
|
327 |
return self.__bold
|