1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from pyjamas.ui.Composite import Composite
17 from pyjamas import Factory
18 from pyjamas.ui.Widget import Widget
19 from pyjamas.ui.SimplePanel import SimplePanel
20 from pyjamas.ui.VerticalPanel import VerticalPanel
21 from pyjamas.ui import Event
22 from pyjamas import DOM
23 import pygwt
24
42
43 Factory.registerClass('pyjamas.ui.DisclosurePanel', 'ClickableHeader', ClickableHeader)
44
65
67 return DOM.getInnerText(self.labelTD)
68
70 DOM.setInnerText(self.labelTD, text)
71
74
77
79 self.imageBase = pygwt.getImageBaseURL(images)
80
82 if setOpen:
83 DOM.setAttribute(self.imgElem, "src",
84 self.imageBase + "disclosurePanelOpen.png")
85 else:
86 DOM.setAttribute(self.imgElem, "src",
87 self.imageBase + "disclosurePanelClosed.png")
88
89
90
91
92
93
95
97
98 self.handlers = []
99 self.content = None
100 self.images = False
101
102
103
104 element = kwargs.pop('Element', None)
105
106
107 headerText = headerWidget = None
108 isOpen = False
109 if len(args) == 1:
110 header = args[0]
111 if len(args) == 2:
112 header, isOpen = args[:2]
113
114 if isinstance(header, basestring):
115 headerText = header
116 else:
117 headerWidget = header
118 isOpen = kwargs.pop('isOpen', isOpen)
119 headerText = kwargs.pop('header', headerText)
120 headerWidget = kwargs.pop('header', headerWidget)
121
122
123
124
125
126 headerContent = headerWidget
127 if headerText is not None or headerContent is None:
128 if headerText is None:
129 headerText = ""
130 headerContent = DefaultHeader(headerText)
131
132 self.mainPanel = VerticalPanel(Element=element)
133
134 self._init_header(headerContent)
135
136 self.contentWrapper = SimplePanel()
137 self.mainPanel.add(self.header)
138 self.mainPanel.add(self.contentWrapper)
139 DOM.setStyleAttribute(self.contentWrapper.getElement(),
140 "padding", "0px");
141 DOM.setStyleAttribute(self.contentWrapper.getElement(),
142 "overflow", "hidden");
143
144 kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DisclosurePanel")
145 Composite.__init__(self, self.mainPanel, **kwargs)
146
147
148 self.isOpen = None
149 self.setOpen(isOpen)
150
151 self.setContentDisplay()
152
158
159 - def add(self, widget):
162
165
168
171
172 - def getContent(self):
174
177
180
183
189
190 - def setContent(self, widget):
191 if self.content is not None:
192 self.contentWrapper.setWidget(None)
193 self.content.removeStyleName("content")
194
195 self.content = widget
196 if self.content is not None:
197 self.contentWrapper.setWidget(self.content)
198 self.content.addStyleName("content")
199 self.setContentDisplay()
200
203
210
219
221 for handler in self.handlers:
222 if self.isOpen:
223 handler.onOpen(self)
224 else:
225 handler.onClose(self)
226
228 if self.isOpen:
229 self.addStyleName("open")
230 self.removeStyleName("closed")
231 else:
232 self.addStyleName("closed")
233 self.removeStyleName("open")
234 self.contentWrapper.setVisible(self.isOpen)
235
236 Factory.registerClass('pyjamas.ui.DisclosurePanel', 'DisclosurePanel', DisclosurePanel)
237