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 pyjamas.ui.CellPanel import CellPanel
20 from pyjamas.ui import Event
21
23
33
35 self.stackListeners.append(listener)
36
37 - def add(self, widget, stackText="", asHTML=False):
38 widget.removeFromParent()
39 index = self.getWidgetCount()
40
41 tr = DOM.createTR()
42 td = DOM.createTD()
43 DOM.appendChild(self.body, tr)
44 DOM.appendChild(tr, td)
45 self.setStyleName(td, "gwt-StackPanelItem", True)
46 self._setIndex(td, index)
47 DOM.setAttribute(td, "height", "1px")
48
49 tr = DOM.createTR()
50 td = DOM.createTD()
51 DOM.appendChild(self.body, tr)
52 DOM.appendChild(tr, td)
53 DOM.setAttribute(td, "height", "100%")
54 DOM.setAttribute(td, "vAlign", "top")
55
56 CellPanel.add(self, widget, td)
57
58 self.setStackVisible(index, False)
59 if self.visibleStack == -1:
60 self.showStack(0)
61
62 if stackText != "":
63 self.setStackText(self.getWidgetCount() - 1, stackText, asHTML)
64
70
71
72 - def remove(self, child, index=None):
73 if index is None:
74 if isinstance(child, int):
75 index = child
76 child = self.getWidget(child)
77 else:
78 index = self.getWidgetIndex(child)
79
80 if child.getParent() != self:
81 return False
82
83 if self.visibleStack == index:
84 self.visibleStack = -1
85 elif self.visibleStack > index:
86 self.visibleStack -= 1
87
88 rowIndex = 2 * index
89 tr = DOM.getChild(self.body, rowIndex)
90 DOM.removeChild(self.body, tr)
91 tr = DOM.getChild(self.body, rowIndex)
92 DOM.removeChild(self.body, tr)
93 CellPanel.remove(self, child)
94 rows = self.getWidgetCount() * 2
95
96
97 for i in range(rowIndex, rows, 2):
98 childTR = DOM.getChild(self.body, i)
99 td = DOM.getFirstChild(childTR)
100 curIndex = self._getIndex(td)
101 self._setIndex(td, index)
102 index += 1
103
104 return True
105
107 self.indices[td] = index
108
110 return self.indices.get(td)
111
112 - def setStackText(self, index, text, asHTML=False):
113 if index >= self.getWidgetCount():
114 return
115
116 td = DOM.getChild(DOM.getChild(self.body, index * 2), 0)
117 if asHTML:
118 DOM.setInnerHTML(td, text)
119 else:
120 DOM.setInnerText(td, text)
121
123 if (index >= self.getWidgetCount()) or (index == self.visibleStack):
124 return
125
126 if self.visibleStack >= 0:
127 self.setStackVisible(self.visibleStack, False)
128
129 self.visibleStack = index
130 self.setStackVisible(self.visibleStack, True)
131 for listener in self.stackListeners:
132 listener.onStackChanged(self, index)
133
135 while (elem is not None) and not DOM.compare(elem, self.getElement()):
136 expando = self._getIndex(elem)
137 if expando is not None:
138 return int(expando)
139
140 elem = DOM.getParent(elem)
141
142 return -1
143
155
157 return self.visibleStack
158
159 Factory.registerClass('pyjamas.ui.StackPanel', 'StackPanel', StackPanel)
160