Thanks William I tested the code at SageMathCloud, it works for one direction. My initial thought was to realize the conversion on both direction in one function. two directions work simultaneously. if typing the new number at P , the V shows the new result, and the same action works for V too. In other words, from the higher point of view, the P and V is same. when P or V receive the new number from the input, it works as an independent variable. and no input action works on it , it may works as a dependent variable to show the result.
for work on one direction. paulmasson <http://ask.sagemath.org/users/19915/paulmasson/> give the bellow method, it works. nest interact. @interactdef _(P=input_box(20, width=6, label="power(dBm)")): @interact def _(V=input_box(P+107, width=6, label="voltage(dBuV)")): show('P=',P) show('V=',V) As the @interact didn't support to update the value of the input filed, i tried the bellow way. reduced the two input_box to one. (because they are the same way) @interact(layout={'top':[['P']], 'bottom':[['Rule']]}) def _(P=input_box(1, width=8, label="please input the power(dBm) or voltage(dBμV) ", type=float), Rule = selector(['from power(dBm) to voltage(dBμV)', 'from voltage(dBμV) to power(dBm)'], nrows=1, label="please select the convert direction ")): # if the input is not a number, show the message , still looking for way to realize this. if Rule == 'from power(dBm) to voltage(dBμV)': pretty_print("from power(dBm) to voltage(dBμV): ") pretty_print(P+107) else : pretty_print("from voltage(dBμV) to power(dBm): ") pretty_print(P-107) ---------- now, to make this simple self study more integrity. still struggled two things. 1. how to judge the value of the input_box is not a number. 2. I still didn't find how to input newline and give the color to the string in the pretty_print()'s function help. On Monday, May 30, 2016 at 1:48:29 AM UTC+8, William wrote: > > On Sat, May 28, 2016 at 9:48 AM, <[email protected] <javascript:>> > wrote: > > Hello everyone, still new to Sage. followed the pre_tutorials and > online > > ingteract wiki examples. > > > > question: > > > > the code like bellow. given the relationship between V and P is > V=P+107, > > and two input_box are defined. > > > > @interact > > > > def _(P=input_box(20, width=6, label="power(dBm)"),V=input_box(127, > width=6, > > label="voltage(dBuV)")): > > V=P+107 > > > > > > want to know is it possible to realize when I input the new number to > the > > input_box of P, the input_box of V will dynamically update the value > base on > > the relationship of V=P+107. and the vice versa. > > > > thanks in advance. > > A few years ago I rewrote interacts for Sage worksheets at > SageMathCloud (https://cloud.sagemath.com), and they have the > functionality you're asking about, e.g.,: > > @interact > def f(P=input_box(20, width=15, label="power(dBm)"),V=input_box(127, > width=15, label="voltage(dBuV)")): > print "before update, V = ", V > f.V = P+107 > > Click here to see (but you have to make a copy in your own project): > > > https://104.154.250.163/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2016-05-29-interact.sagews > > > I don't know if anybody else's interact work covers this case. > > William > > > > > > > > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "sage-support" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to [email protected] <javascript:>. > > To post to this group, send email to [email protected] > <javascript:>. > > Visit this group at https://groups.google.com/group/sage-support. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > William (http://wstein.org) > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
