Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement interact/interactive for widgets #4883

Closed
2 of 4 tasks
ellisonbg opened this issue Jan 27, 2014 · 3 comments · Fixed by #4960
Closed
2 of 4 tasks

Implement interact/interactive for widgets #4883

ellisonbg opened this issue Jan 27, 2014 · 3 comments · Fixed by #4960
Assignees
Milestone

Comments

@ellisonbg
Copy link
Member

We will implement a high-level interact/interactive API for widgets that have a value attribute and produce output. The different APIs we will support are:

  • interact(f, *args, **kwargs) = immediate display
  • @interact(*args, **kwargs) = immediate display, identity decorator
  • @interact without arguments = used with annotate
  • w = interactive(f, *args, **kwargs) = delayed display, return Widget

We also attach f.widget when appropriate. Initial work done in this branch:

https://github.com/ellisonbg/ipython/tree/newinteract

@jasongrout
Copy link
Member

@interact without arguments---will that use the default arguments in the function, or just use python 3 annotations?

It's been incredibly convenient in Sage to have default arguments in a function control the widgets. It's a really useful shortcut. Something like:

def interact_default(f):
    args,defaults = inspect.getargspec(f) # pseudo-code here...I don't remember exactly what getargspec returns
    return interact(f, zip(args,defaults))

@ellisonbg
Copy link
Member Author

I like this idea and think it will be possible even without having a
separate API entry point for this. Something like this should work:

def f(x=1, y=2):
    # code goes here...

interact(f)

On Thu, Jan 30, 2014 at 10:54 AM, Jason Grout notifications@github.comwrote:

@interact https://github.com/interact without arguments---will that use
the default arguments in the function, or just use python 3 annotations?

It's been incredibly convenient in Sage to have default arguments in a
function control the widgets. It's a really useful shortcut. Something like:

def interact_default(f):
args,defaults = inspect.getargspec(f) # pseudo-code here...I don't remember exactly what getargspec returns
return interact(f, zip(args,defaults))

Reply to this email directly or view it on GitHubhttps://github.com//issues/4883#issuecomment-33720017
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

I agree. I made it a separate function to make it clearer what I was proposing.

Something like this should work too:

@interact
def f(n=(0,10), x=TextWidget('hi')):
    print n, x

and use the current auto-guessing features to make a slider for n and the requested widget for x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants