Dynamically Changing a Dialog Box


In many cases, it is desirable to update the state or value of a dialog box control depending on the state or value of another control. Dynamic updating can simplify the selection of options within a dialog box. For example, the following dialog box disables the Remove DC Offset checkbox option when the Gnormal option is selected since the GNORMAL function creates zero mean noise by default.





The Remove DC Offset option displays in gray and cannot be selected when Gnormal is selected.


Dynamically updating a dialog box is achieved by placing # update modifier in the display area of a control. Any control with a # immediately updates the entire dialog box contents when selected.  


Here is the menu file for the above dialog box:


// enable1.pan - enable/disable control



// initialize parameters

{defvar("gfunc", "Grandom");defvar("nodc", 1)}


// checkbox enabled

{setvar("chkbox", gfunc=="Grandom")}


Generate Noise


Generate Function <# r w=20>~gfunc = "<{gfunc}>"~<Grandom><Gnormal>

Remove DC Offset  <c e={chkbox}>~nodc=<{nodc}>~<0><1>



~genfunc = sprintf("%s(100, 1/100)", gfunc)

~if(nodc && chkbox, setwf(sprintf("demean(%s)", genfunc)), setwf(genfunc))



When a dialog box is loaded, all expressions contained in {} are evaluated and the resulting values are substituted. In this example, the variables gfunc and nodc are initialized if not already specified. The chkbox variable is set to 1 if gfunc is Grandom, otherwise it is set to 0.


Dynamic updating is accomplished by the lines:


Generate Function <# r w=20>~gfunc = "<{gfunc}>"~<Grandom><Gnormal>

Remove DC Offset  <c e={chkbox}>~nodc=<{nodc}>~<0><1>


The # modifier in the display area of the control indicates the control should evaluate immediately when selected. After the control line evaluates, the entire dialog box is re-evaluated just as if it was invoked by the user. In particular, all expressions in {} are re-evaluated. The e modifier indicates whether a control is enabled or not where e=1 specifies enabled and e=0 specifies disabled.


In this example, when Gnormal is selected, the line:


gfunc = "<{gfunc}>"


immediately evaluates to:


gfunc = "Grandom"


Next, the entire dialog box re-evaluates such that:


{setvar("chkbox", gfunc=="Grandom")}


sets chkbox to 1 because gfunc is now Grandom and the line:


Remove DC Offset  <c e={chkbox}>~nodc=<{nodc}>~<0><1>


now evaluates to:


Remove DC Offset  <c e=0>~nodc=<{nodc}>~<0><1>


rendering the checkbox control disabled. Finally, when the dialog box is processed by pressing the OK button:


~if(nodc && chkbox, setwf(sprintf("demean(%s)", genfunc)), setwf(genfunc))


only selects DEMEAN if the checkbox is selected and enabled.