# HG changeset patch # User Jason Grout # Date 1196490833 21600 # Node ID 0e2d666acea18f6a9291332850b56ce086cf079f # Parent cad57dea1832909011c4e8c34de6cb708b7c7dcb [mq]: widgets diff -r cad57dea1832 -r 0e2d666acea1 sage/server/notebook/widgets/all.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sage/server/notebook/widgets/all.py Sat Dec 01 00:33:53 2007 -0600 @@ -0,0 +1,1 @@ +from menu import * diff -r cad57dea1832 -r 0e2d666acea1 sage/server/notebook/widgets/menu.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sage/server/notebook/widgets/menu.py Sat Dec 01 00:33:53 2007 -0600 @@ -0,0 +1,52 @@ +r""" +Menu Control + +Implement an interactive menu in the Sage notebook. +""" + +from sage.structure.sage_object import SageObject +class menu(SageObject): + """ + Create an HTML select box menu in the Sage notebook. + """ + def __init__(self, variable, options, next_update=True): + """ + A select box menu which sets the variable. When an item is + selected in the menu, the variable is set to the item. + + INPUT: + variable -- variable to control + options -- list of options for the menu. + + EXAMPLE: + sage: menu('f', [sin,cos,tan]).show() + + A select box menu appears in the notebook. Select a value for f. + + sage: plot(f(x), 0, 2*pi).show() + + The graph of f(x) is plotted. + + """ +# from sage.server.notebook.widgets import cell +# from sage.server.support import EMBEDDED_MODE + self._variable = variable + self._next_update = next_update + self._options = options + + def show(self): + from sage.server.support import EMBEDDED_MODE + if EMBEDDED_MODE: + change_function="""async_request(worksheet_command('eval'), generic_callback, 'newcell=0&id=-1&input=%s%%3d'+this.options[this.selectedIndex].value)"""%self._variable + html = """%s=" + print(""+html+"") + +# def value(self): +# return self._options[self._current_index] + +# def __call__(self): +# return self.value() + diff -r cad57dea1832 -r 0e2d666acea1 setup.py --- a/setup.py Wed Nov 21 13:48:49 2007 -0800 +++ b/setup.py Sat Dec 01 00:33:53 2007 -0600 @@ -1173,6 +1173,7 @@ setup(name = 'sage', 'sage.server.server1', 'sage.server.notebook', 'sage.server.notebook.compress', + 'sage.server.notebook.widgets', 'sage.server.wiki', 'sage.server.trac', diff -r cad57dea1832 -r 0e2d666acea1 setupnb.py --- a/setupnb.py Wed Nov 21 13:48:49 2007 -0800 +++ b/setupnb.py Sat Dec 01 00:33:53 2007 -0600 @@ -894,6 +894,7 @@ setup(name = 'sage', 'sage.server.server1', 'sage.server.notebook', 'sage.server.notebook.compress', + 'sage.server.notebook.widgets', 'sage.server.wiki', 'sage.server.trac',