示例#1
0
  def remove(self, wait=False):
    """Removes the widget from the document.

    Args:
      wait: if true the actual deletion doesn't happen until the next output.
    """
    _util.flush_all()
    _tags.clear(wait, self._output_tags)
示例#2
0
  def _publish(self):
    """Publishes this widget.

    Default does nothing but saves the current output area.
    """
    _util.flush_all()
    self._published = True
    # We save active output tags, and use that for all output inside any of the
    # subcomponents, even if they are no longer active.
    # This is done so that if the table # is deleted via tags that are
    # currently active, all its content
    # is also cleaned up.
    self._saved_output_tags = _tags.get_active_tags()
    self._current_component = None
    self._output_tags = self._saved_output_tags.union([self._tag])
示例#3
0
 def _active_component(self, component_id, init_params=None):
   """Sets active subcomponent."""
   if init_params is None:
     init_params = {}
   if not self._published:
     self._publish()
   if self._current_component is not None:
     raise WidgetException('Already inside a component')
   self._current_component = component_id
   _util.flush_all()
   with self._output_in_widget():
     with output.use_tags(self._current_component):
       with output.redirect_to_element('#' + component_id):
         #
         self._prepare_component_for_output(**init_params)
         with output.use_tags('user_output'):
           try:
             yield
           finally:
             _util.flush_all()
             self._current_component = None
示例#4
0
  def _clear_component(self, component_id=None, wait=False):
    """Clears component.

    If component_id is None, it will clear currently active component,
    otherwise it will clear one with given id.

    NOTE FOR SUBCLASS IMPLEMENTTERS:

    When _clear_output is called it will remove all outputs that were created
    within context of _active_component.

    This might produce subtle errors in situations where user clears component
    he is currently producing output for as it will destroy any output that
    is in the context of _active_component. Therefore if your widget
    needs javascript to setup the component for output it should always
    be produced by overloading _prepare_component_for_output.

    Args:
      component_id: which component to clear.
      wait: if True, the output won't be cleared until the next user output.
      See colab.output.clear for full details.

    Raises:
      WidgetException: if component_id and no active element is
      selected
    """
    _util.flush_all()
    if component_id is None:
      if self._current_component is None:
        raise WidgetException('No active component selected')
      component_id = self._current_component
    if component_id == self._current_component:
      # Do not clear the part that sets current active element.
      # If we did, this would have made all consecutive output to stream
      # to wrong outputarea on reload.
      output.clear(wait, output_tags=[component_id] + ['user_output'])
    else:
      output.clear(wait, output_tags=[component_id])
示例#5
0
 def _output_in_widget(self):
   with output.use_tags(self._output_tags):
     try:
       yield
     finally:
       _util.flush_all()