Show More
@@ -1,16 +1,7 b'' | |||||
1 | """Interact with functions using widgets.""" |
|
1 | """Interact with functions using widgets.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Copyright (c) 2013, the IPython Development Team. |
|
|||
5 | # |
|
|||
6 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
7 | # |
|
|||
8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
9 | #----------------------------------------------------------------------------- |
|
|||
10 |
|
||||
11 | #----------------------------------------------------------------------------- |
|
|||
12 | # Imports |
|
|||
13 | #----------------------------------------------------------------------------- |
|
|||
14 |
|
5 | |||
15 | from __future__ import print_function |
|
6 | from __future__ import print_function | |
16 |
|
7 | |||
@@ -30,10 +21,6 b' from IPython.utils.traitlets import HasTraits, Any, Unicode' | |||||
30 |
|
21 | |||
31 | empty = Parameter.empty |
|
22 | empty = Parameter.empty | |
32 |
|
23 | |||
33 | #----------------------------------------------------------------------------- |
|
|||
34 | # Classes and Functions |
|
|||
35 | #----------------------------------------------------------------------------- |
|
|||
36 |
|
||||
37 |
|
24 | |||
38 | def _matches(o, pattern): |
|
25 | def _matches(o, pattern): | |
39 | """Match a pattern of types in a sequence.""" |
|
26 | """Match a pattern of types in a sequence.""" | |
@@ -251,7 +238,13 b' def interact(__interact_f=None, **kwargs):' | |||||
251 | # ... |
|
238 | # ... | |
252 | f = __interact_f |
|
239 | f = __interact_f | |
253 | w = interactive(f, **kwargs) |
|
240 | w = interactive(f, **kwargs) | |
254 | f.widget = w |
|
241 | try: | |
|
242 | f.widget = w | |||
|
243 | except AttributeError: | |||
|
244 | # some things (instancemethods) can't have attributes attached, | |||
|
245 | # so wrap in a lambda | |||
|
246 | f = lambda *args, **kwargs: __interact_f(*args, **kwargs) | |||
|
247 | f.widget = w | |||
255 | display(w) |
|
248 | display(w) | |
256 | return f |
|
249 | return f | |
257 | else: |
|
250 | else: | |
@@ -260,10 +253,7 b' def interact(__interact_f=None, **kwargs):' | |||||
260 | # def f(*args, **kwargs): |
|
253 | # def f(*args, **kwargs): | |
261 | # ... |
|
254 | # ... | |
262 | def dec(f): |
|
255 | def dec(f): | |
263 |
|
|
256 | return interact(f, **kwargs) | |
264 | f.widget = w |
|
|||
265 | display(w) |
|
|||
266 | return f |
|
|||
267 | return dec |
|
257 | return dec | |
268 |
|
258 | |||
269 | def interact_manual(__interact_f=None, **kwargs): |
|
259 | def interact_manual(__interact_f=None, **kwargs): |
@@ -366,6 +366,23 b' def test_decorator_kwarg():' | |||||
366 | ) |
|
366 | ) | |
367 |
|
367 | |||
368 | @nt.with_setup(clear_display) |
|
368 | @nt.with_setup(clear_display) | |
|
369 | def test_interact_instancemethod(): | |||
|
370 | class Foo(object): | |||
|
371 | def show(self, x): | |||
|
372 | print(x) | |||
|
373 | ||||
|
374 | f = Foo() | |||
|
375 | ||||
|
376 | with tt.monkeypatch(interaction, 'display', record_display): | |||
|
377 | g = interact(f.show, x=(1,10)) | |||
|
378 | nt.assert_equal(len(displayed), 1) | |||
|
379 | w = displayed[0].children[0] | |||
|
380 | check_widget(w, | |||
|
381 | cls=widgets.IntSlider, | |||
|
382 | value=5, | |||
|
383 | ) | |||
|
384 | ||||
|
385 | @nt.with_setup(clear_display) | |||
369 | def test_decorator_no_call(): |
|
386 | def test_decorator_no_call(): | |
370 | with tt.monkeypatch(interaction, 'display', record_display): |
|
387 | with tt.monkeypatch(interaction, 'display', record_display): | |
371 | @interact |
|
388 | @interact |
General Comments 0
You need to be logged in to leave comments.
Login now