MathGroup Archive 2009

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

Search the Archive

Re: Dialogue box generator

  • To: mathgroup at
  • Subject: [mg104944] Re: Dialogue box generator
  • From: Albert Retey <awnl at>
  • Date: Sat, 14 Nov 2009 01:56:25 -0500 (EST)
  • References: <hdjdpi$atc$>

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>
> 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 ... *)
    If[Not[Extract[#, 2, ValueQ]],
      Set @@ Append[Extract[#, 2, Hold], Null]] &,
   (* create grid of labels and inputfields *)
   grid = Map[{
     InputField[Extract[#, 2, Dynamic], Boxes, FieldSize -> size]
     } &,
   (* return panel with grid *)
    Grid[grid, Spacings -> {1, 0.1}, Alignment -> Left]

this is how you would call it:

  "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...



  • Prev by Date: Error when working with a derivative
  • Next by Date: Re: Re: Wrong limit?
  • Previous by thread: Re: Dialogue box generator
  • Next by thread: Re: Re: Re: Complex solutions to simple