Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 1.53 KB

index.rst

File metadata and controls

54 lines (39 loc) · 1.53 KB

jupyter-ui-poll

Block Jupyter cell execution while interacting with widgets.

This library is for people familiar with :mod:`ipywidgets` who want to solve the following problem:

  1. Display User Interface in Jupyter using :mod:`ipywidgets` or similar
  2. Wait for data to be entered (this step is surprisingly non-trivial to implement)
  3. Use entered data in cells below

Quick, self contained example:

import time
from ipywidgets import Button
from jupyter_ui_poll import ui_events

# Set up simple GUI, button with on_click callback
# that sets ui_done=True and changes button text
ui_done = False
def on_click(btn):
    global ui_done
    ui_done = True
    btn.description = '👍'

btn = Button(description='Click Me')
btn.on_click(on_click)
display(btn)

# Wait for user to press the button
with ui_events() as poll:
    while ui_done is False:
        poll(10)          # React to UI events (upto 10 at a time)
        print('.', end='')
        time.sleep(0.1)
print('done')

For a more detailed tutorial see Example notebook, you can also run it right now using awesome Binder service.

.. toctree::
   :hidden:

   install.rst
   api.rst