Re: Front End Programming question
- To: mathgroup at smc.vnet.net
- Subject: [mg54967] Re: Front End Programming question
- From: dh <dh at metrohm.ch>
- Date: Tue, 8 Mar 2005 05:03:55 -0500 (EST)
- References: <d09dm6$d7k$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Janos, here is a "poor man" solution: use: Input, e.g.: Input["Average Primer"] For more than one item, you would use braces: Input["Enter x and y: {x,y}"] Daniel János wrote: > Hi, > > I am looking at John M. Novak presentation he did at the 1999 > Mathematica Developers's Conference, titled Front End Programming. > Based upon his notebook, I ask input questions the following way. > First I define two functions, askForInput and dialogForInput. > > askForInput[inputLabel_: > ""] := Module[{thenb, > result}, > thenb = dialogForInput[ > inputLabel]; > While[Options[thenb, > Visible] === > {Visible -> True}, > Do[Null, {250}]]; > NotebookFind[thenb, > "TheInput", All, > CellTags]; result = > NotebookRead[thenb]; > NotebookClose[thenb]; > MakeExpression[result[[1, > 1]]]] > > > dialogForInput[ > inputLabel_] := > NotebookPut[Notebook[ > {Cell[BoxData[StringJoin[ > inputLabel, " "]], > "Input", CellFrame -> > True, Evaluatable -> > False, > ShowCellTags -> True, > CellTags -> > "TheInput", > CellMargins -> > {{10, 10}, {4, 4}}, > Deletable -> False], > Cell[BoxData[ > ButtonBox["OK", > RuleDelayed[Butto\ > nFunction, > SetOptions[Butt\ > onNotebook[], > Rule[Visible, > False]]], > Rule[ButtonFrame, > "DialogBox"]] > ], "Input", > Editable -> False, > Active -> True, > TextAlignment -> > Center, > CellMargins -> > {{10, 10}, {20, > 2}}]}, > ShowCellBracket -> > False, WindowFrame -> > "MovableModalDialog", > WindowFloating -> False, > WindowSize -> {300, > 150}, > WindowFrameElements -> > {}, WindowElements -> > { > "VerticalScrollBar"}]]\ > ; > > > Then if I want to ask a question I call askForInput and grab the value > with the Nest: > > primerLength = ReleaseHold[ > askForInput[ > "Length of a Primer:"]]; > primerLength = Nest[Last, > primerLength, > Depth[primerLength] - 1]; > > If I want to ask another question I do the same thing with a different > question into another variable, like: > > averagePrimerDistance = > ReleaseHold[askForInput[ > "Average Primer \ > Distance:"]]; > averagePrimerDistance = > Nest[Last, > averagePrimerDistance, > Depth[ > averagePrimerDistance] \ > - 1]; > > Works great, - one question at a time. My question is, how can I > present multiple questions into one dialog and sort out the answers > after the values are typed in and the <OK> button is clicked. I tried > a number of different ways, - making inputLabel a List, creating a > table of Cells with different CellTags, getting the results back into > an array, played with GUIKit, etc... - but did not find the right one. > All failed at the NotebookFind[thenb, "TheInput", All, CellTags]; > command and its variants. Conceptually the question looks easy, but > the devil is - always - in the implementation :) > > Thanks ahead, > > János > > > ---------------------------------------------- > Trying to argue with a politician is like lifting up the head of a > corpse. > (S. Lem: His Master Voice) >