Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Front End Programming question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54868] Front End Programming question
  • From: János <janos.lobb at yale.edu>
  • Date: Fri, 4 Mar 2005 05:08:03 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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)


  • Prev by Date: Re: Re: computing residues
  • Next by Date: Re: Re: Re: Bug in Import?
  • Previous by thread: Re: Precise bitmaps
  • Next by thread: Re: Front End Programming question