Ticket #2449 (closed enhancement: fixed)
[with patch; needs more reviews] interact -- interactive functions in the notebook
| Reported by: | was | Owned by: | was |
|---|---|---|---|
| Priority: | major | Milestone: | sage-2.10.3 |
| Component: | notebook | Keywords: | |
| Cc: | TimothyClemans | Work issues: | |
| Report Upstream: | Reviewers: | ||
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
Description (last modified by was) (diff)
This was #1322.
Implement something like Mathematica's manipulate.
http://sage.math.washington.edu/home/was/tmp/interact.png
There will be two patch bundles attached to this email; each a bundle that applies cleanly against sage-2.10.3.rc3. One against scripts and one against the main sage repo.
I will not put anything in the reference manual until this code has got some testing.
Attachments
Change History
comment:1 Changed 5 years ago by was
- Owner changed from boothby to was
- Status changed from new to assigned
comment:5 Changed 5 years ago by was
- Summary changed from interact -- interactive functions in the notebook to [with patch; needs review] interact -- interactive functions in the notebook
The two bundles below should apply cleanly against 2.10.3.rc3 and give everything needed try use the new interact functionality, which is now done modulo bugfixes:
You can apply both as follows:
sage: hg_sage.apply('http://sage.math.washington.edu/home/was/patches/interact-sage.hg'); hg_sage.merge(); hg_sage.update()
sage: hg_extcode.apply('http://sage.math.washington.edu/home/was/patches/interact-extcode.hg'); hg_extcode.merge(); hg_extcode.update()
comment:6 Changed 5 years ago by was
To try out this code, just start up the sage notebook, create a worksheet, and type interact?
comment:7 Changed 5 years ago by was
Here's an example that makes use of several of the different available widgets:
@interact
def _(title=["A Plot Demo", "Something silly", "something tricky"], a=input_box(sin(x*sin(x*sin(x))), 'function'),
clr=Color('red'), thickness=[1..30], zoom=(1,0.95,..,0.1), plot_points=(200..2000)):
html('<h1 align=center>%s</h1>'%title)
print plot_points
show(plot(a, -zoom*pi,zoom*pi, color=clr, thickness=thickness, plot_points=plot_points))
comment:8 Changed 5 years ago by gfurnish
- Type changed from defect to enhancement
- Summary changed from [with patch; needs review] interact -- interactive functions in the notebook to [with patch; very positive review] interact -- interactive functions in the notebook
comment:9 Changed 5 years ago by gfurnish
- Summary changed from [with patch; very positive review] interact -- interactive functions in the notebook to [with patch; needs more reviews] interact -- interactive functions in the notebook
comment:10 Changed 5 years ago by TimothyClemans
Blows my mind.
One suggestion is to have some builtin styles for an interact box. Maybe: @interact(style='blue') or @interact(style='white') ...
Also I noticed that there is an empty white area above a plot in an interact box.
comment:11 Changed 5 years ago by TimothyClemans
Also I think type=blah should be added to all of the standard controls not just input_box.
comment:12 Changed 5 years ago by TimothyClemans
Here is my attempt at being able to show what you are coloring in a plot:
@interact
def _(item=['Polygon', 'Points'],c=Color('red')):
pts = [(0.65438363916925979, 0.85150056342598845), (0.70937855184366272,
0.029131148388535144), (0.85031921177678882, 0.85521222531849894),
(0.43668577545798215, 0.08598920033699009), (0.65641161685705918,
0.26493224917213731), (0.66939907297513568, 0.32187884928032584)]
a = (0,0.5,0)
b = (0,1,0.5)
if item == 'Polygon':
b = c
else:
a = c
G = points(pts,pointsize=60,rgbcolor=a) + polygon(pts, rgbcolor=b)
show(G, figsize=5, xmin=0, ymin=0)
(1) It would be nice if the box wasn't refreshed when I hit a button. (2) When I pick say a color for the polygon I want the polygon to be that color throughout until changed again by me using the polygon button and color picker.
comment:13 Changed 5 years ago by schilly
wow, looks very nice. just from looking at the screenshot: what about adding the current value and min/max next to the sliders? would be helpful to see the value of a slider directly.
ex:
comment:14 Changed 5 years ago by was
Hi, Thanks for all the comments above.
One suggestion is to have some builtin styles for an interact box.
Maybe: @interact(style='blue') or @interact(style='white') ...
This is specifically listed as a post 1.0 enhancement in interact.py and I will not modify the current patch to do that. More likely, I will leave that to somebody else to do after this is released.
Also I think type=blah should be added to all of the standard controls not just input_box.
That doesn't make sense because input_box is the only control where the code creating the control hasn't already determined the type by their input. E.g., for buttons, sliders, etc., one is giving the types by the input that creates the widget.
(1) It would be nice if the box wasn't refreshed when I hit a button.
What box? I don't understand this at all.
(2) When I pick say a color for the polygon I want the polygon to be that color throughout until changed again by me using the polygon button and color picker.
Isn't that exactly what happens?
comment:15 Changed 5 years ago by was
wow, looks very nice. just from looking at the screenshot: what about adding the current value and min/max next to the sliders? would be helpful to see the value of a slider directly.
That should be a widget style option, which should be made by somebody else *after* the initial release of interact. It shouldn't be on by default because it would clutter the interface.
Changed 5 years ago by was
-
attachment
sage-2449-extra1.patch
added
Only apply this *after* #2451, or some of the doctest examples might be very slow.
comment:16 Changed 5 years ago by TimothyClemans
The commentary for example one in the documentation says that a slider will be the control for the y variable, but I get a dropdown menu.
I find the difference in font color and background between the interact box as a whole and the output area inside it annoying.
I would like there to be a str type option for the other controls, so I don't see quote marks in say button names.
comment:18 Changed 5 years ago by was
- Status changed from assigned to closed
- Resolution set to fixed
