MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Input Buttons?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42497] Re: [mg42478] Input Buttons?
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Fri, 11 Jul 2003 02:57:58 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

At 02:37 AM 7/10/2003, mark wrote:
>I want to run a program, display some intermediate plot and then
>prompt the user if they want to proceed or not.  Putting buttons
>beneath the plot seems like a good idea, but I do not know how to have
>them pass the result back to the original funtion like
>test=Input["Continue? [y/n]"] would do.  How can I do this with
>buttons?  The only way I can figure to do this is to break my function
>at the buttons and then have the buttons call a second function with
>the variables passed globally (yuck!).  Haven't found a good site
>explaining this stuff... would ultimately like to have buttoned dialog
>boxes and input boxes like you can do in another system with one line of code,
>but don't want to venture into JAVA script (at least for the project
>at hand).
>
>Any help appreciated,
>
>Mark

That is often what you have to do. We've put together a package that makes 
this much easier, though. It has many similarities to how HTML forms work. 
You can download the demo from:

http://omegaconsultinggroup.com/Products/form/

<<FormMaker`

This function creates a nb with 2 buttons. The SumbitBox calls the yes 
function when pressed. The CancelBox closes the form. Any data I want to 
pass to those functions I "hide" in the form. (You can also have users 
enter new data via checkboxes, radioboxes, textfields, etc.)

MyFunction[] :=
   Module[{data = Table[Random[], {20}]},
     NotebookPut[MakeNotebook[
         ListPlot[data],
         {"Continue?", "[", SubmitBox["Y", yes], "/", CancelBox["N"], "]"},
         HiddenBox["data", data],
         WindowSize -> {FitAll, FitAll}
         ]]
     ]

Then I define the yes function. The hidden data and any user input are 
automatically collected and passed to the function as a sequence of rules. 
I close the old form and assign the incoming data to local variables. Then 
I can do whatever I want with the data. Here I'll process and display the 
result in a new notebook.

yes[opts___?OptionQ] :=
   Module[{data, avg},
     CloseForm[];
     data = "data"/.{opts};
     avg = Plus@@data/Length@data;
     NotebookPut[MakeNotebook[
         ListPlot[data,Epilog->Line[{{0, avg},{Length@data, avg}}]],
         WindowSize->{FitAll,FitAll}
         ]]
     ]

This sets the process in motion.

MyFunction[]

It's not the most exciting example, but hopefully you get the idea. No 
global variables, no messing with NotebookRead and NotebookWrite. Just a 
clean pass of data from one function to another. If you have any questions, 
let me know.

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com


  • Prev by Date: Re: Ouput Form
  • Next by Date: Re: WeibullDistribution
  • Previous by thread: Input Buttons?
  • Next by thread: Standard PDE: solution wanted.