Show More
@@ -180,15 +180,13 b' class Widget(LoggingConfigurable):' | |||||
180 | self.send_state(key=name) |
|
180 | self.send_state(key=name) | |
181 |
|
181 | |||
182 |
|
182 | |||
183 |
def _handle_displayed(self, |
|
183 | def _handle_displayed(self, **kwargs): | |
184 | """Called when a view has been displayed for this widget instance |
|
184 | """Called when a view has been displayed for this widget instance | |
185 |
|
185 | |||
186 | Parameters |
|
186 | Parameters | |
187 | ---------- |
|
187 | ---------- | |
188 | view_name: unicode |
|
188 | [view_name]: unicode (optional kwarg) | |
189 | Name of the view that was displayed. |
|
189 | Name of the view that was displayed.""" | |
190 | parent: Widget instance [optional] |
|
|||
191 | Widget that this widget should be displayed as a child of.""" |
|
|||
192 | for handler in self._display_callbacks: |
|
190 | for handler in self._display_callbacks: | |
193 | if callable(handler): |
|
191 | if callable(handler): | |
194 | argspec = inspect.getargspec(handler) |
|
192 | argspec = inspect.getargspec(handler) | |
@@ -204,12 +202,9 b' class Widget(LoggingConfigurable):' | |||||
204 | elif nargs == 1: |
|
202 | elif nargs == 1: | |
205 | handler(self) |
|
203 | handler(self) | |
206 | elif nargs == 2: |
|
204 | elif nargs == 2: | |
207 | handler(self, view_name) |
|
205 | handler(self, kwargs.get('view_name', None)) | |
208 | elif nargs == 3: |
|
|||
209 | handler(self, view_name, parent) |
|
|||
210 | else: |
|
206 | else: | |
211 | raise TypeError('Widget display callback must ' \ |
|
207 | handler(self, **kwargs) | |
212 | 'accept 0-2 arguments, not %d.' % nargs) |
|
|||
213 |
|
208 | |||
214 |
|
209 | |||
215 | # Public methods |
|
210 | # Public methods | |
@@ -375,7 +370,8 b' class Widget(LoggingConfigurable):' | |||||
375 | - callback() |
|
370 | - callback() | |
376 | - callback(sender) |
|
371 | - callback(sender) | |
377 | - callback(sender, view_name) |
|
372 | - callback(sender, view_name) | |
378 |
- callback(sender, |
|
373 | - callback(sender, **kwargs) | |
|
374 | kwargs from display call passed through without modification. | |||
379 | remove: bool |
|
375 | remove: bool | |
380 | True if the callback should be unregistered.""" |
|
376 | True if the callback should be unregistered.""" | |
381 | if remove and callback in self._display_callbacks: |
|
377 | if remove and callback in self._display_callbacks: | |
@@ -385,7 +381,7 b' class Widget(LoggingConfigurable):' | |||||
385 |
|
381 | |||
386 |
|
382 | |||
387 | # Support methods |
|
383 | # Support methods | |
388 |
def _repr_widget_(self, |
|
384 | def _repr_widget_(self, **kwargs): | |
389 | """Function that is called when `IPython.display.display` is called on |
|
385 | """Function that is called when `IPython.display.display` is called on | |
390 | the widget. |
|
386 | the widget. | |
391 |
|
387 | |||
@@ -393,8 +389,7 b' class Widget(LoggingConfigurable):' | |||||
393 | ---------- |
|
389 | ---------- | |
394 | view_name: unicode (optional) |
|
390 | view_name: unicode (optional) | |
395 | View to display in the frontend. Overrides default_view_name.""" |
|
391 | View to display in the frontend. Overrides default_view_name.""" | |
396 | if not view_name: |
|
392 | view_name = kwargs.get('view_name', self.default_view_name) | |
397 | view_name = self.default_view_name |
|
|||
398 |
|
393 | |||
399 | # Create a communication. |
|
394 | # Create a communication. | |
400 | self._open_communication() |
|
395 | self._open_communication() | |
@@ -405,12 +400,11 b' class Widget(LoggingConfigurable):' | |||||
405 | # Show view. |
|
400 | # Show view. | |
406 | if self.parent is None or self.parent._comm is None: |
|
401 | if self.parent is None or self.parent._comm is None: | |
407 | self._send({"method": "display", "view_name": view_name}) |
|
402 | self._send({"method": "display", "view_name": view_name}) | |
408 | self._handle_displayed(view_name) |
|
|||
409 | else: |
|
403 | else: | |
410 | self._send({"method": "display", |
|
404 | self._send({"method": "display", | |
411 | "view_name": view_name, |
|
405 | "view_name": view_name, | |
412 | "parent": self.parent._comm.comm_id}) |
|
406 | "parent": self.parent._comm.comm_id}) | |
413 |
|
|
407 | self._handle_displayed(**kwargs) | |
414 | self._displayed = True |
|
408 | self._displayed = True | |
415 |
|
409 | |||
416 | # Now display children if any. |
|
410 | # Now display children if any. |
General Comments 0
You need to be logged in to leave comments.
Login now