mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Adding decorator forms of interact. Yeah!
This commit is contained in:
parent
dd9a6efaed
commit
6e8c63ea19
@ -237,11 +237,29 @@ def interactive(f, *args, **kwargs):
|
|||||||
|
|
||||||
return container
|
return container
|
||||||
|
|
||||||
def interact(f, *args, **kwargs):
|
def interact(*args, **kwargs):
|
||||||
"""Interact with a function using widgets."""
|
"""Interact with a function using widgets."""
|
||||||
w = interactive(f, *args, **kwargs)
|
if args and callable(args[0]):
|
||||||
f.widget = w
|
# This branch handles the cases:
|
||||||
display(w)
|
# 1. interact(f, *args, **kwargs)
|
||||||
|
# 2. @interact
|
||||||
|
# def f(*args, **kwargs):
|
||||||
|
# ...
|
||||||
|
f = args[0]
|
||||||
|
w = interactive(f, *args[1:], **kwargs)
|
||||||
|
f.widget = w
|
||||||
|
display(w)
|
||||||
|
else:
|
||||||
|
# This branch handles the case:
|
||||||
|
# @interact(10, 20, a=30, b=40)
|
||||||
|
# def f(*args, **kwargs):
|
||||||
|
# ...
|
||||||
|
def dec(f):
|
||||||
|
w = interactive(f, *args, **kwargs)
|
||||||
|
f.widget = w
|
||||||
|
display(w)
|
||||||
|
return f
|
||||||
|
return dec
|
||||||
|
|
||||||
def annotate(**kwargs):
|
def annotate(**kwargs):
|
||||||
"""Python 3 compatible function annotation for Python 2."""
|
"""Python 3 compatible function annotation for Python 2."""
|
||||||
|
Loading…
Reference in New Issue
Block a user