1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from pyjamas import DOM
17 from pyjamas import Factory
18
19 from ComplexPanel import ComplexPanel
20 from pyjamas.ui import Event
21
23
51
52 - def add(self, widget, stackText="", asHTML=False):
53 widget.removeFromParent()
54 index = self.getWidgetCount()
55
56 tr = DOM.createTR()
57 td = DOM.createTD()
58 DOM.appendChild(self.body, tr)
59 DOM.appendChild(tr, td)
60 self.setStyleName(td, "gwt-StackPanelItem", True)
61 self._setIndex(td, index)
62 DOM.setAttribute(td, "height", "1px")
63
64 tr = DOM.createTR()
65 td = DOM.createTD()
66 DOM.appendChild(self.body, tr)
67 DOM.appendChild(tr, td)
68 DOM.setAttribute(td, "height", "100%")
69 DOM.setAttribute(td, "vAlign", "top")
70
71 ComplexPanel.add(self, widget, td)
72
73 self.setStackVisible(index, False)
74 if self.visibleStack == -1:
75 self.showStack(0)
76
77 if stackText != "":
78 self.setStackText(self.getWidgetCount() - 1, stackText, asHTML)
79
85
86
87 - def remove(self, child, index=None):
88 if index is None:
89 if isinstance(child, int):
90 index = child
91 child = self.getWidget(child)
92 else:
93 index = self.getWidgetIndex(child)
94
95 if child.getParent() != self:
96 return False
97
98 if self.visibleStack == index:
99 self.visibleStack = -1
100 elif self.visibleStack > index:
101 self.visibleStack -= 1
102
103 rowIndex = 2 * index
104 tr = DOM.getChild(self.body, rowIndex)
105 DOM.removeChild(self.body, tr)
106 tr = DOM.getChild(self.body, rowIndex)
107 DOM.removeChild(self.body, tr)
108 ComplexPanel.remove(self, child)
109 rows = self.getWidgetCount() * 2
110
111
112 for i in range(rowIndex, rows, 2):
113 childTR = DOM.getChild(self.body, i)
114 td = DOM.getFirstChild(childTR)
115 curIndex = self._getIndex(td)
116 self._setIndex(td, index)
117 index += 1
118
119 return True
120
122 self.indices[td] = index
123
125 return self.indices.get(td)
126
127 - def setStackText(self, index, text, asHTML=False):
128 if index >= self.getWidgetCount():
129 return
130
131 td = DOM.getChild(DOM.getChild(self.body, index * 2), 0)
132 if asHTML:
133 DOM.setInnerHTML(td, text)
134 else:
135 DOM.setInnerText(td, text)
136
138 if (index >= self.getWidgetCount()) or (index == self.visibleStack):
139 return
140
141 if self.visibleStack >= 0:
142 self.setStackVisible(self.visibleStack, False)
143
144 self.visibleStack = index
145 self.setStackVisible(self.visibleStack, True)
146
148 while (elem is not None) and not DOM.compare(elem, self.getElement()):
149 expando = self._getIndex(elem)
150 if expando is not None:
151 return int(expando)
152
153 elem = DOM.getParent(elem)
154
155 return -1
156
168
170 return self.visibleStack
171
172 Factory.registerClass('pyjamas.ui.StackPanel', StackPanel)
173