Re: [jupyter] API change proposal for ipywidget's interact

Matthias Bussonnier <[email protected]>
Newsgroups gmane.comp.python.ipython.devel
Message-ID <57477D7B-6A7B-413D-AFAE-B897B0265DC1__41472.5036164329$1452628657$gmane$org@gmail.com>
Hi all, 

This was sent on jupyter ML, but as it’s a Python-kernel only change, it might be good to CC IPython-dev, 
which I do there. 

Please keep a single thread, preferably on Jupyter groups as the thread was started there. 

Thanks
-- 
M


> On Jan 12, 2016, at 11:34, Sylvain Corlay <[email protected]> wrote:
> 
> Hello,
> 
> Brian and Fernando advised that I send a message to the mailing list regarding this change.
> 
> Both Jupyter and Sage's interactive widget libraries provide an `@interact` function decorator which introspects the arguments of the function to create a simple GUI for interacting with it. Sage and Jupyter APIs for `@interact` are very similar, but differ in how they use abbreviations.
> 
> Abbreviations are a way to map default values to a type of widget. For example in both cases the following case
> 
>     @interact
>     def foo(x=(0, 100, 2)):
>         print(x)
> 
> both Jupyter and Sage will create a slider with from 0 to 100 with a step of 2. 
> 
> In fact, Jupyter and Sage's uses of abbreviations differ in the following way:
> 
> With Sage: When passing a list of items, the generated widget is always a selection widget.
> When passing a tuple of 2 or 3 numerical values, a slider is created and the values are interpreted as(min, max[, step])
> 
> With Jupyter, a selection widget is only used when passing sequence (tuple or list) of strings. 
> A slider is used when passing a sequence of 2 or 3 numerical values, and these values are interpreted as (min, max[, step]).
> 
> I personally prefer the API of Sage over the one of Jupyter. In my opinion, the type mapping `tuple -> slider` and `list -> selection` is simpler to reason about than a behavior that depends on the type of the items in a sequence.
> 
> Obviously, since the two APIs are not compatible, we cannot support them both at the same time. If we decide that we eventually want to adopt the Sage approach, I proposed a way to achieve a smooth transition in the pull request https://github.com/ipython/ipywidgets/pull/288 <https://github.com/ipython/ipywidgets/pull/288>. The proposed change is backward compatible with the Jupyter approach and introduces deprecation warnings when using a list of 2/3 numerical values to create a slider or if the user creates a selection widget with a tuple of strings.
> 
> The question to the list is: what do you think of adopting the same type abbreviations as Sage in Jupyter's interact?
> 
> Thanks,
> 
> Sylvain 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
> To post to this group, send email to [email protected] <mailto:[email protected]>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CAK%3DPhk6NfcwyaCagm%3DRLBVTbh1oZ0YdYr8ncM1ZLH-JV%3Dz_gYg%40mail.gmail.com <https://groups.google.com/d/msgid/jupyter/CAK%3DPhk6NfcwyaCagm%3DRLBVTbh1oZ0YdYr8ncM1ZLH-JV%3Dz_gYg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.

_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/ipython-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.