# HG changeset patch # User Igor Tolkov # Date 1215475635 25200 # Node ID 2e16e235d7fb40668b814bc45843b144214c31ac # Parent aa99aecac97e583ecb30adf9c8bff77b5cb0dfd6 Longer slider and label. diff -r aa99aecac97e -r 2e16e235d7fb sage/server/notebook/interact.py --- a/sage/server/notebook/interact.py Sun Jul 06 15:39:47 2008 -0700 +++ b/sage/server/notebook/interact.py Mon Jul 07 17:07:15 2008 -0700 @@ -208,12 +208,13 @@ def html(s): """ print "%s"%s -def html_slider(id, callback, steps, default=0, margin=0): +def html_slider(id, values, callback, steps, default=0, margin=0): """ Return the HTML representation of a jQuery slider. INPUT: id -- string -- the DOM id of the slider (better be unique) + values -- 'null' or javascript string containing array of values on slider callback-- javascript that is executed whenever the slider is done moving steps -- number of steps from minimum to maximum value. default -- (default: 0) the default position of the slider @@ -224,19 +225,27 @@ def html_slider(id, callback, steps, def you should obtain a slider that when moved pops up a window showing its current position. sage: from sage.server.notebook.interact import html_slider, html - sage: html(html_slider('slider-007', 'alert(position)', steps=5, default=2, margin=5)) + sage: html(html_slider('slider-007', 'null', 'alert(position)', steps=5, default=2, margin=5)) ... """ - s = """
"""%( - id, int(margin)) + s = """"""%(id, int(margin)) + if values != "null": + s += ""%id + s += "
+
+
" # We now generate javascript that gets run after the above div # gets inserted. This happens because of the setTimeout function # below which gets passed an anonymous function. - s += """"""%(id, steps-1, default, id, callback) + s += """"""%(values, id, steps-1, default, id, id, callback, id, id, id, id) # change 'change' to 'slide' and it changes the slider every time it moves; # needs much more work to actually work, since server gets fludded by # requests. @@ -886,7 +895,7 @@ class Selector(InteractControl): class Slider(InteractControl): - def __init__(self, var, values, default_position, label=None): + def __init__(self, var, values, default_position, label=None, display_value=True): """ A slider interact control that takes on the given list of values. @@ -897,6 +906,8 @@ class Slider(InteractControl): default_position -- int; default location that the slider is set to. label -- alternative label to the left of the slider, instead of the variable. + display_value -- boolean, whether to display the current value right + of the slider EXAMPLES: sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha') @@ -905,6 +916,7 @@ class Slider(InteractControl): InteractControl.__init__(self, var, values[default_position], label=label) self.__values = values self.__default_position = default_position + self.__display_value = display_value def __repr__(self): """ @@ -941,7 +953,7 @@ class Slider(InteractControl): 'position' """ return "position" - + def _adaptor(self, position, globs): """ Adapt a user input, which is the slider position, to be an @@ -972,10 +984,22 @@ class Slider(InteractControl): EXAMPLES: sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').render() - '
...
...