Hi everyone,

I've been thinking about how to implement interactive widgets in the 
notebook.  Things like sliders, buttons, etc., that allow interactivity 
like Maplets in Maple or the Manipulate command in Mathematica 6. 
Here's an example of an interface:

sage: a=Slider(1,10)
sage: plot(sin(a()*x),-3,3)

and in the notebook would appear a slider labeled "a" and the graph 
would appear below it.  As the slider is moved between 1 and 10, the 
plot updates dynamically, showing the frequency-scaling aspect of 
different values of a.

Here's a brainstorm idea of how to do this.  I don't know that much 
about the notebook code or how evaluation works, so I don't know if this 
is the way to do things, but here goes:

* There is a widget class hierarchy.  Widget is the parent class and 
under it are classes for different controls, like sliders, dials, 2-d 
location pickers, etc.  Each widget class has a __call__ method that 
returns a value, so we just use a() like above to get the value of the 
widget.
* Before an expression is evaluated in the notebook, an empty widget 
list is created.
* In the evaluation, if any widget is encountered (i.e., asked for its 
value), then it puts a copy of itself in the widget list.  It returns 
some default value.
* Before displaying the result of the expression, the notebook creates 
javascript widgets corresponding to the widgets in the list.  We could, 
for example, use the jquery ui library or some other widget library.
* Anytime a widget is updated (e.g., a slider is moved), the widget 
value is updated and the expression is reevaluated.

For comparison, here would be the Mathematica 6 syntax for something 
like the above example:

Manipulate[Plot[Sin[a*x],{x,-3,3}], {a,1,10}]

or

Plot[Sin[a*x], {x,-3,3}] // Manipulate[#, {a,1,10}] &

Thoughts or ideas?  I have no clue how to actually implement this in the 
framework that we have for evaluating expressions.

I think something like this would go a long way to making Sage useful in 
the classroom.

Performance might be a problem.  In that case, we could eventually have 
some command that would cache the output of the expression for different 
widget values so the update would be faster.

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to