Thank you, Mitesh.
On Sep 1, 3:59 pm, Mitesh Patel <[email protected]> wrote:
> If we added a unique HTML 'id' attribute to the input element, perhaps
> we could wrap
>
> html('<script>jQuery("#unique_id_for_this_input").val({0});</script>'.format(n_points_global))
>
> in a friendlier Python function that we could insert here?
If I understand your proposal correctly, your example shows a way to
manipulate/alter the state/rendering of a control (like a slider,
input_box, etc.), which is one direction.
I envision both directions (from control to Python code <implemented
today>, and from Python code to control <new capability>) having to be
equally easy/consistent, so that if you create a GUI with @interact or
any other way, this GUI would both control as well as reflect (be
impacted by) the state of the running math model.
So a simple example (with just an InputBox control) could be something
like (and again, apologies, if I'm just not getting the current
capabilities, and all this is somehow already possible):
# define all GUI controls:
Theta = sagenb.notebook.interact.InputBox('theta', default_value=2,
label='The angle (theta): ', width=5)
# render GUI:
html(Theta.label() + Theta.render())
# impact/affect the GUI:
# input_value = Theta.value() # desired: get the current value (not
just the default_value, which is currently implemented)
input_value = Theta.default_value() # exists: not necessarily the
current value, but default_value() is currently implemented
print "The value of", Theta.var(), "is", input_value
input_value += 1 # any manipulation here
# Theta.value(input_value) # desired: set the control to the new value
# print "The value of", Theta.var(), "has been modified to:",
Theta.value() # desired: get the current, newly modified value
print "The value of", Theta.var(), "has been modified to:",
input_value # exists: wrong, but since we can't get the modified
value...
Thanks,
Mark
> > On Sep 1, 12:21 pm, HMark <[email protected]> wrote:
> >> One thing I'm missing is a way to change interact widget rendering in
> >> the browser, from within the code.
>
> >> So, in the simple example athttp://www.sagenb.org/home/pub/2409/(and
> >> also below), what I'd like to see is that the n_points_local input_box
> >> widget (in this case, but other types of widgets in general) gets
> >> updated every time a new point is added, and n_points_global and
> >> n_points_local get modified.
>
> >> Similarly, the code changes the state of the point_operation buttons
> >> to 'Reset' after every time a point is added, but the button widgets
> >> rendering doesn't reflect that.
>
> >> 1. is there a way to do this with the built-in functionality, or do I
> >> need to build a custom GUI with widgets rendered outside of @interact
> >> (but within the browser)?
>
> >> 2. Regardless, are there examples of custom GUIs, rendered in the
> >> browser (Notebook), interacting with the sage functionality, I can
> >> look at?
>
> >> Any pointers would be appreciated.
>
> >> # --- global ---
> >> display_points = Graphics()
> >> n_points_global = 5
>
> >> for i in range(n_points_global):
> >> display_points += point((round(10 * random(), 0), round(10 *
> >> random(), 0)))
>
> >> @interact
> >> def point_setting(
> >> point_operation = ['Reset', 'Add a point'],
> >> n_points_local = input_box(default = n_points_global, label =
> >> 'number of points:', width = 5)
> >> ):
> >> global display_points, n_points_global
>
> >> if point_operation == 'Add a point':
> >> display_points += point((round(10 * random(), 0), round(10 *
> >> random(), 0)))
> >> n_points_global += 1
> >> n_points_local = n_points_global
> >> point_operation = 'Reset'
> >> print "number of points = ", len(display_points)
> >> show(display_points, xmin = 0, xmax = 10, ymin = 0, ymax = 10)
--
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-support
URL: http://www.sagemath.org