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

Source Code for Module pyjamas.ui.CaptionPanel

 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   
18  from SimplePanel import SimplePanel 
19   
20 -class CaptionPanel(SimplePanel):
21 """ 22 A panel that wraps its contents in a border with a caption that appears in 23 the upper left corner of the border. This is an implementation of the 24 fieldset HTML element. 25 """ 26
27 - def __init__(self, caption, widget=None, **kwargs):
28 if kwargs.has_key('Element'): 29 element = kwargs.pop('Element') 30 else: 31 element = DOM.createElement("fieldset") 32 self.legend = DOM.createElement("legend") 33 DOM.appendChild(element, self.legend) 34 kwargs['Caption'] = caption 35 if widget is not None: 36 kwargs['Widget'] = widget 37 SimplePanel.__init__(self, element, **kwargs)
38
39 - def getCaption(self):
40 return self.caption
41
42 - def setCaption(self, caption):
43 self.caption = caption 44 if caption is not None and not caption == "": 45 DOM.setInnerHTML(self.legend, caption) 46 DOM.insertChild(self.getElement(), self.legend, 0) 47 elif DOM.getParent(self.legend) is not None: 48 DOM.removeChild(self.getElement(), self.legend)
49 50 Factory.registerClass('pyjamas.ui.CaptionPanel', CaptionPanel) 51