Two-way interaction

628 days ago by qed777

scratch_cell_id = sagenb.notebook.interact.SAGE_CELL_ID 
       
scratch_cell_id = sagenb.notebook.interact.SAGE_CELL_ID 
       
def create_input_box(label, id, value, scratch_cell_id, variable_name): html('''{0} <input id="{1}" value="{2}" onchange="\$('#cell_input_{3}').val('{4} = ' + \$(this).val() + '; print {4}'); evaluate_cell({3}, 0);"></input>'''.format(label, id, value, scratch_cell_id, variable_name)) 
       
def update_input_box(id, new_value): html('''<script>\$("#{0}").val("{1}").trigger('onchange');</script>'''.format(id, new_value)) 
       
c = 5 create_input_box('c', 'c_box_test', c, scratch_cell_id, 'c') 
       
c = 5 create_input_box('c', 'c_box', c, scratch_cell_id, 'c') @interact def _(a=input_box(3), b=input_box(4)): global c print 'a =', a print 'b =', b c = n(sqrt(a^2 + b^2)) update_input_box('c_box', c) print 'c = ', c 
       

Click to the left again to hide and once more to show the dynamic interactive window