1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from warnings import warn
17
18 from muntjac.ui.abstract_component_container import AbstractComponentContainer
19 from muntjac.ui.component import Event as ComponentEvent
20 from muntjac.ui.abstract_component import AbstractComponent
21
22
24 """Defines a listener that can receive a PopupVisibilityEvent when the
25 visibility of the popup changes.
26 """
27
29 """Pass to L{PopupView.PopupVisibilityEvent} to start listening
30 for popup visibility changes.
31
32 @param event: the event
33
34 @see: L{PopupVisibilityEvent}
35 @see: L{PopupView.addListener}
36 """
37 raise NotImplementedError
38
39
40 _POPUP_VISIBILITY_METHOD = getattr(IPopupVisibilityListener,
41 'popupVisibilityChange')
42
43
45 """Iterator for the visible components (zero or one components), used by
46 L{PopupView.getComponentIterator}.
47 """
48
52
53
56
57
59 return not self._first
60
61
63 if not self._first:
64 self._first = True
65 return self._component
66 else:
67 raise StopIteration
68
69
71 raise NotImplementedError
72
73
75 """A component for displaying a two different views to data. The minimized
76 view is normally used to render the component, and when it is clicked the
77 full view is displayed on a popup. The class L{popup_view.IContent} is
78 used to deliver contents to this component.
79
80 @author: Vaadin Ltd.
81 @author: Richard Lincoln
82 """
83
84 CLIENT_WIDGET = None
85
87 """A simple way to create a PopupPanel. Note that the minimal
88 representation may not be dynamically updated.
89
90 Alternatively, creates a PopupView through the IContent interface.
91 This allows the creator to dynamically change the contents of the
92 PopupView.
93
94 @param args: tuple of the form
95 - (small, large)
96 1. the minimal textual representation as HTML
97 2. the full, Component-type representation
98 - (content)
99 1. the IContent that contains the information for this
100 """
101 self._content = None
102 self._hideOnMouseOut = None
103 self._visibleComponent = None
104
105 nargs = len(args)
106 if nargs == 1:
107 content, = args
108 super(PopupView, self).__init__()
109 self._hideOnMouseOut = True
110 self.setContent(content)
111 elif nargs == 2:
112 small, large = args
113
114 c = InnerContent(small, large)
115 PopupView.__init__(self, c)
116 else:
117 raise ValueError, 'invalid number of arguments'
118
119
121 """This method will replace the current content of the panel with
122 a new one.
123
124 @param newContent:
125 IContent object containing new information
126 for the PopupView
127 @raise ValueError:
128 if the method is passed a null value, or if one of
129 the content methods returns null
130 """
131 if newContent is None:
132 raise ValueError, 'IContent must not be null'
133 self._content = newContent
134 self.requestRepaint()
135
136
138 """Returns the content-package for this PopupView.
139
140 @return: the IContent for this object or null
141 """
142 return self._content
143
144
146 """@deprecated: Use L{setPopupVisible} instead."""
147 warn('use setPopupVisible() instead', DeprecationWarning)
148 self.setPopupVisible(visible)
149
151 """@deprecated: Use L{isPopupVisible} instead."""
152 warn('use isPopupVisible() instead', DeprecationWarning)
153 return self.isPopupVisible()
154
155
172
173
175 """Return whether the popup is visible.
176
177 @return: true if the popup is showing
178 """
179 return self._visibleComponent is not None
180
181
183 """Check if this popup will be hidden when the user takes the mouse
184 cursor out of the popup area.
185
186 @return: true if the popup is hidden on mouse out, false otherwise
187 """
188 return self._hideOnMouseOut
189
190
191
192
194 """Should the popup automatically hide when the user takes the mouse
195 cursor out of the popup area? If this is false, the user must click
196 outside the popup to close it. The default is true.
197 """
198 self._hideOnMouseOut = hideOnMouseOut
199
200
202 """This class only contains other components when the popup is
203 showing.
204
205 @see: L{ComponentContainer.getComponentIterator}
206 """
207 return SingleComponentIterator(self._visibleComponent)
208
209
211 """Gets the number of contained components. Consistent with the
212 iterator returned by L{getComponentIterator}.
213
214 @return: the number of contained components (zero or one)
215 """
216 return 1 if self._visibleComponent is not None else 0
217
218
220 """Not supported in this implementation.
221
222 @see: L{AbstractComponentContainer.removeAllComponents}
223 @raise NotImplementedError:
224 """
225 raise NotImplementedError
226
227
229 """Not supported in this implementation.
230
231 @see: L{AbstractComponentContainer.moveComponentsFrom}
232 @raise NotImplementedError:
233 """
234 raise NotImplementedError
235
236
238 """Not supported in this implementation.
239
240 @see: L{AbstractComponentContainer.addComponent}
241 @raise NotImplementedError:
242 """
243 raise NotImplementedError
244
245
247 """Not supported in this implementation.
248
249 @see: L{ComponentContainer.replaceComponent}
250 @raise NotImplementedError:
251 """
252 raise NotImplementedError
253
254
256 """Not supported in this implementation
257
258 @see: L{AbstractComponentContainer.removeComponent}
259 """
260 raise NotImplementedError
261
262
263
265 """Paint (serialize) the component for the client.
266
267 @see: L{AbstractComponent.paintContent}
268 """
269
270 super(PopupView, self).paintContent(target)
271
272 html = self._content.getMinimizedValueAsHTML()
273 if html is None:
274 html = ''
275
276 target.addAttribute('html', html)
277 target.addAttribute('hideOnMouseOut', self._hideOnMouseOut)
278
279
280 if self.isPopupVisible():
281 target.startTag('popupComponent')
282 self._visibleComponent.paint(target)
283 target.endTag('popupComponent')
284
285 target.addVariable(self, 'popupVisibility', self.isPopupVisible())
286
287
289 """Deserialize changes received from client.
290
291 @see: L{AbstractComponent.changeVariables}
292 """
293 if 'popupVisibility' in variables:
294 self.setPopupVisible( bool(variables.get('popupVisibility')) )
295
296
312
313
322
323
338
339
348
349
351 """This event is received by the PopupVisibilityListeners when the
352 visibility of the popup changes. You can get the new visibility directly
353 with L{isPopupVisible}, or get the PopupView that produced the event with
354 L{getPopupView}.
355 """
356
359
360
362 """Get the PopupView instance that is the source of this event.
363
364 @return: the source PopupView
365 """
366 return self.getSource()
367
368
370 """Returns the current visibility of the popup.
371
372 @return: true if the popup is visible
373 """
374 return self.getPopupView().isPopupVisible()
375
376
377 -class IContent(object):
378 """Used to deliver customized content-packages to the PopupView. These
379 are dynamically loaded when they are redrawn. The user must take care
380 that neither of these methods ever return null.
381 """
382
384 """This should return a small view of the full data.
385
386 @return: value in HTML format
387 """
388 raise NotImplementedError
389
390
392 """This should return the full Component representing the data
393
394 @return: a Component for the value
395 """
396 raise NotImplementedError
397
398
399 -class InnerContent(IContent):
400
401 - def __init__(self, small, large):
402 self._small = small
403 self._large = large
404
405
408
409
412