Re: Dialogue box generator

*To*: mathgroup at smc.vnet.net*Subject*: [mg104944] Re: Dialogue box generator*From*: Albert Retey <awnl at gmx-topmail.de>*Date*: Sat, 14 Nov 2009 01:56:25 -0500 (EST)*References*: <hdjdpi$atc$1@smc.vnet.net>

robert prince-wright schrieb: > Sorry here is the abutLists code which should have been in the earlier post. > > > abutLists[l1_,l2_]:=({l1}~Join~{l2})\[Transpose] > > > ----- Original Message ---- > From: robert prince-wright <robertprincewright at yahoo.com> > Sent: Thu, November 12, 2009 5:53:45 PM > Subject: Dialogue box generator > > I have tried to create a DynamicModule that allows you to create a dialogue box with names and variable symbols defined in lists passed as arguments. It's almost working, but not quite, so can someone help me finish it. > > As you can see below the DynamicModule creates a temporary list 'x' with length determined by the number or variables (which is also the number of rows in the Dialogue). The list 'x' is used so that we can plant it in the InputField[Dynamic[....] ] statement. This statement is created by Mapping it onto the 'temp' list which is just an index. Now the module as shown works, but of course i dont want to see the result of the the statement 'Dynamic[ ReleaseHold[ variables=x]]' in the output. All i want is the dialogue so that I can enter data and get the values assigned to the variable symbols (len, width etc). The problem is that I can't find a way of returning the Panel and set sysmbols without the list. Also the symbols len, width etc keep getting assigned Null values. > > Can someone show me how to sort this out. It will be a usefull snippet when it works! > > > names = {"Length (m)","Width (m)","Height (m)"}; > variables = { len, width, height}; > > inputDialogue[names_List, variables_List]:=DynamicModule[ > {cellSize1,nRows, x, temp, myCell}, > cellSize1={4,0.75}; > nRows= Length@variables; > x=Table[Null,{i,nRows}]; > temp = Range[ nRows]; > myCell=Table[Null,{i,nRows}]; > myCell=Map[InputField[Dynamic[x[[#]]],Boxes, FieldSize->cellSize1]&, temp]; > {Panel@Grid[abutLists[names,myCell] , Spacings->{1,0.1}],Dynamic[ ReleaseHold[ variables=x]]} > ]; > inputDialogue[names, { len1, width1, height1}] here is a function that does what I think you want to achieve. I have changed the input syntax because that makes the handling of unevaluated symbols somewhat easier. The trick is that I put the unevaluated symbols directly into the Dynamics, so there is no need for a temporary list. varsetter[defs_List] := DynamicModule[{ size = {4, 0.75}, grid }, (* if variables don't have values, set them to Null ... *) Scan[ If[Not[Extract[#, 2, ValueQ]], Set @@ Append[Extract[#, 2, Hold], Null]] &, defs ]; (* create grid of labels and inputfields *) grid = Map[{ #[[1]], InputField[Extract[#, 2, Dynamic], Boxes, FieldSize -> size] } &, defs ]; (* return panel with grid *) Panel[ Grid[grid, Spacings -> {1, 0.1}, Alignment -> Left] ] ]; this is how you would call it: varsetter[{ "Length (m)" :> len, "Width (m)" :> width, "Height (m)" :> height }] note that this will also work if any of the variables already happens to be initialized, if they are not, they are initialized to Null, just to make the input fields look empty... hth, albert