Show More
@@ -237,11 +237,29 b' def interactive(f, *args, **kwargs):' | |||||
237 |
|
237 | |||
238 | return container |
|
238 | return container | |
239 |
|
239 | |||
240 |
def interact( |
|
240 | def interact(*args, **kwargs): | |
241 | """Interact with a function using widgets.""" |
|
241 | """Interact with a function using widgets.""" | |
|
242 | if args and callable(args[0]): | |||
|
243 | # This branch handles the cases: | |||
|
244 | # 1. interact(f, *args, **kwargs) | |||
|
245 | # 2. @interact | |||
|
246 | # def f(*args, **kwargs): | |||
|
247 | # ... | |||
|
248 | f = args[0] | |||
|
249 | w = interactive(f, *args[1:], **kwargs) | |||
|
250 | f.widget = w | |||
|
251 | display(w) | |||
|
252 | else: | |||
|
253 | # This branch handles the case: | |||
|
254 | # @interact(10, 20, a=30, b=40) | |||
|
255 | # def f(*args, **kwargs): | |||
|
256 | # ... | |||
|
257 | def dec(f): | |||
242 | w = interactive(f, *args, **kwargs) |
|
258 | w = interactive(f, *args, **kwargs) | |
243 | f.widget = w |
|
259 | f.widget = w | |
244 | display(w) |
|
260 | display(w) | |
|
261 | return f | |||
|
262 | return dec | |||
245 |
|
263 | |||
246 | def annotate(**kwargs): |
|
264 | def annotate(**kwargs): | |
247 | """Python 3 compatible function annotation for Python 2.""" |
|
265 | """Python 3 compatible function annotation for Python 2.""" |
General Comments 0
You need to be logged in to leave comments.
Login now