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

Source Code for Module pyjamas.ui.CellPanel

  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 ComplexPanel import ComplexPanel 
 19   
20 -class CellPanel(ComplexPanel):
21
22 - def __init__(self, **kwargs):
23 element = None 24 if kwargs.has_key('Element'): 25 element = kwargs.pop('Element') 26 if element is None: 27 element = DOM.createTable() 28 self.table = element 29 self.setElement(self.table) 30 self.body = DOM.createTBody() 31 self.spacing = None 32 self.padding = None 33 DOM.appendChild(self.table, self.body) 34 35 ComplexPanel.__init__(self, **kwargs)
36
37 - def getTable(self):
38 return self.table
39
40 - def getBody(self):
41 return self.body
42
43 - def getBorderWidth(self):
44 return DOM.getAttribute(self.table, "border")
45
46 - def getCellHeight(self, widget):
47 td = DOM.getParent(widget.getElement()) 48 return DOM.getAttribute(td, "height")
49
50 - def getCellWidth(self, widget):
51 td = DOM.getParent(widget.getElement()) 52 return DOM.getAttribute(td, "width")
53
54 - def getSpacing(self):
55 return self.spacing
56
57 - def getPadding(self):
58 return self.padding
59
60 - def getCellHorizontalAlignment(self, widget):
61 td = self.getWidgetTd(widget) 62 if td is None: 63 return None 64 return DOM.getAttribute(td, "align")
65
66 - def getCellVerticalAlignment(self, widget):
67 td = self.getWidgetTd(widget) 68 if td is None: 69 return None 70 return DOM.getStyleAttribute(td, "verticalAlign")
71
72 - def getWidgetTd(self, widget):
73 if widget.getParent() != self: 74 return None 75 return DOM.getParent(widget.getElement())
76
77 - def setBorderWidth(self, width):
78 if width is None or width == "": 79 DOM.removeAttribute(self.table, "border") 80 else: 81 DOM.setAttribute(self.table, "border", "%d" % width)
82
83 - def setCellHeight(self, widget, height):
84 td = DOM.getParent(widget.getElement()) 85 if height is None: 86 DOM.removeAttribute(td, "height") 87 else: 88 DOM.setAttribute(td, "height", height)
89
90 - def setCellHorizontalAlignment(self, widget, align):
91 td = self.getWidgetTd(widget) 92 if td is not None: 93 if align is None: 94 DOM.removeAttribute(td, "align") 95 else: 96 DOM.setAttribute(td, "align", align)
97
98 - def setCellVerticalAlignment(self, widget, align):
99 td = self.getWidgetTd(widget) 100 if td is not None: 101 if align is None: 102 DOM.setStyleAttribute(td, "verticalAlign", "") 103 else: 104 DOM.setStyleAttribute(td, "verticalAlign", align)
105
106 - def setCellWidth(self, widget, width):
107 td = DOM.getParent(widget.getElement()) 108 if width is None: 109 DOM.removeAttribute(td, "width") 110 else: 111 DOM.setAttribute(td, "width", width)
112
113 - def setSpacing(self, spacing):
114 self.spacing = spacing 115 if spacing is None: 116 DOM.removeAttribute(self.table, "cellSpacing") 117 else: 118 DOM.setAttribute(self.table, "cellSpacing", str(spacing))
119
120 - def setPadding(self, padding):
121 self.padding = padding 122 if padding is None: 123 DOM.removeAttribute(self.table, "cellPadding") 124 else: 125 DOM.setAttribute(self.table, "cellPadding", str(padding))
126 127 Factory.registerClass('pyjamas.ui.CellPanel', CellPanel) 128