Package pyjamas :: Package ui :: Module HTMLPanel
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.ui.HTMLPanel

 1  # Copyright 2006 James Tauber and contributors 
 2  # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 
 3  # 
 4  # Licensed under the Apache License, Version 2.0 (the "License"); 
 5  # you may not use this file except in compliance with the License. 
 6  # You may obtain a copy of the License at 
 7  # 
 8  #     http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  # Unless required by applicable law or agreed to in writing, software 
11  # distributed under the License is distributed on an "AS IS" BASIS, 
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13  # See the License for the specific language governing permissions and 
14  # limitations under the License. 
15  from pyjamas import DOM 
16  from pyjamas import Factory 
17  from pyjamas.ui import InnerHTML 
18   
19  from ComplexPanel import ComplexPanel 
20   
21  HTMLPanel_sUid = 0 
22 23 -def getElementsByTagName(element, tagname):
24 try: 25 element_tagname = element.nodeName # DOM.getAttribute(element, "nodeName") 26 element_tagname = str(element_tagname).lower() 27 except: 28 element_tagname = None 29 if element_tagname is not None and element_tagname == tagname: 30 return [element] 31 32 res = [] 33 child = DOM.getFirstChild(element) 34 while child is not None: 35 for el in getElementsByTagName(child, tagname): 36 res.append(el) 37 child = DOM.getNextSibling(child) 38 39 return res
40
41 -def getElementById(element, id):
42 try: 43 element_id = DOM.getAttribute(element, "id") 44 except: 45 element_id = None 46 if element_id is not None and element_id == id: 47 return element 48 49 child = DOM.getFirstChild(element) 50 while child is not None: 51 ret = getElementById(child, id) 52 if ret is not None: 53 return ret 54 child = DOM.getNextSibling(child) 55 56 return None
57
58 59 -class HTMLPanel(ComplexPanel, InnerHTML):
60 - def __init__(self, html, **kwargs):
61 # NOTE! don't set a default style on this panel, because the 62 # HTML might expect to have one already. 63 #if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-HTMLPanel" 64 if html: kwargs['HTML'] = html 65 if kwargs.has_key('Element'): 66 element = kwargs.pop('Element') 67 else: 68 element = DOM.createDiv() 69 self.setElement(element) 70 ComplexPanel.__init__(self, **kwargs)
71
72 - def add(self, widget, id):
73 element = getElementById(self.getElement(), id) 74 if element is None: 75 # throw new NoSuchElementException() 76 return 77 ComplexPanel.add(self, widget, element)
78
79 - def findTags(self, tagname):
80 return getElementsByTagName(self.getElement(), tagname)
81 82 @staticmethod
83 - def createUniqueId():
84 global HTMLPanel_sUid 85 86 HTMLPanel_sUid += 1 87 return "HTMLPanel_%d" % HTMLPanel_sUid
88 89 Factory.registerClass('pyjamas.ui.HTMLPanel', HTMLPanel) 90