Exemplo n.º 1
0
def _display_stdin_widget(delay_millis=0):
    """Context manager that displays a stdin UI widget and hides it upon exit.

  Args:
    delay_millis: Duration (in milliseconds) to delay showing the widget within
      the UI.

  Yields:
    A callback that can be invoked with a single argument indicating whether
    echo is enabled.
  """
    shell = _ipython.get_ipython()
    display_args = ['cell_display_stdin', {'delayMillis': delay_millis}]
    _message.blocking_request(*display_args, parent=shell.parent_header)

    def echo_updater(new_echo_status):
        # Note: Updating the echo status uses colab_request / colab_reply on the
        # stdin socket. Input provided by the user also sends messages on this
        # socket. If user input is provided while the blocking_request call is still
        # waiting for a colab_reply, the input will be dropped per
        # https://github.com/googlecolab/colabtools/blob/56e4dbec7c4fa09fad51b60feb5c786c69d688c6/google/colab/_message.py#L100.
        update_args = ['cell_update_stdin', {'echo': new_echo_status}]
        _message.blocking_request(*update_args, parent=shell.parent_header)

    yield echo_updater

    hide_args = ['cell_remove_stdin', {}]
    _message.blocking_request(*hide_args, parent=shell.parent_header)
def _display_stdin_widget(delay_millis=0):
    """Context manager that displays a stdin UI widget and hides it upon exit."""
    shell = _ipython.get_ipython()
    display_args = ['cell_display_stdin', {'delayMillis': delay_millis}]
    _message.send_request(*display_args, parent=shell.parent_header)

    yield

    hide_args = ['cell_remove_stdin', {}]
    _message.send_request(*hide_args, parent=shell.parent_header)
Exemplo n.º 3
0
def initialize():
    ip = ipython.get_ipython()
    if ip:
        _CustomErrorHandlers(ip)