1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from pyjamas import Factory
16 from pyjamas import DOM
17
18 from pyjamas.ui.CellPanel import CellPanel
19 from pyjamas.ui import HasHorizontalAlignment
20 from pyjamas.ui import HasVerticalAlignment
21
25
28 self.direction = direction
29 self.hAlign = "left"
30 self.height = ""
31 self.td = None
32 self.vAlign = "top"
33 self.width = ""
34
35
37
38 CENTER = "center"
39 EAST = "east"
40 NORTH = "north"
41 SOUTH = "south"
42 WEST = "west"
43
44 elem_props = [
45 ("height", "Cell Height", "CellHeight", str, None),
46 ("width", "Cell Width", "CellWidth", str, None),
47 ("halign", "Cell Horizontal Alignment",
48 "CellHorizontalAlignment", None, "left"),
49 ("valign", "Cell Vertical Alignment",
50 "CellVerticalAlignment", None, "top"),
51 ]
52
55
62
63 - def add(self, widget, direction):
76
77
80
85
87 index, direction = index
88 return self.dock_children[index]
89
94
96 return len(self.dock_children)
97
100
110
116
122
128
134
136 bodyElement = self.getBody()
137
138 while DOM.getChildCount(bodyElement) > 0:
139 DOM.removeChild(bodyElement, DOM.getChild(bodyElement, 0))
140
141 rowCount = 1
142 colCount = 1
143 for child in self.dock_children:
144 dir = child.getLayoutData().direction
145 if dir == self.NORTH or dir == self.SOUTH:
146 rowCount += 1
147 elif dir == self.EAST or dir == self.WEST:
148 colCount += 1
149
150 rows = []
151 for i in range(rowCount):
152 rows.append(DockPanelTmpRow())
153 rows[i].tr = DOM.createTR()
154 DOM.appendChild(bodyElement, rows[i].tr)
155
156 westCol = 0
157 eastCol = colCount - 1
158 northRow = 0
159 southRow = rowCount - 1
160 centerTd = None
161
162 for child in self.dock_children:
163 layout = child.getLayoutData()
164
165 td = DOM.createTD()
166 layout.td = td
167 DOM.setAttribute(layout.td, "align", layout.hAlign)
168 DOM.setStyleAttribute(layout.td, "verticalAlign", layout.vAlign)
169 DOM.setAttribute(layout.td, "width", layout.width)
170 DOM.setAttribute(layout.td, "height", layout.height)
171
172 if layout.direction == self.NORTH:
173 DOM.insertChild(rows[northRow].tr, td, rows[northRow].center)
174 self.appendAndMaybeAdopt(td, child.getElement(), beingAdded)
175 DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1)
176 northRow += 1
177 elif layout.direction == self.SOUTH:
178 DOM.insertChild(rows[southRow].tr, td, rows[southRow].center)
179 self.appendAndMaybeAdopt(td, child.getElement(), beingAdded)
180 DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1)
181 southRow -= 1
182 elif layout.direction == self.WEST:
183 row = rows[northRow]
184 DOM.insertChild(row.tr, td, row.center)
185 row.center += 1
186 self.appendAndMaybeAdopt(td, child.getElement(), beingAdded)
187 DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1)
188 westCol += 1
189 elif layout.direction == self.EAST:
190 row = rows[northRow]
191 DOM.insertChild(row.tr, td, row.center)
192 self.appendAndMaybeAdopt(td, child.getElement(), beingAdded)
193 DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1)
194 eastCol -= 1
195 elif layout.direction == self.CENTER:
196 centerTd = td
197
198 if self.center is not None:
199 row = rows[northRow]
200 DOM.insertChild(row.tr, centerTd, row.center)
201 self.appendAndMaybeAdopt(centerTd, self.center.getElement(), beingAdded)
202
209
210 Factory.registerClass('pyjamas.ui.DockPanel', 'DockPanel', DockPanel)
211