4

It is sometimes convenient to use Manipulate to set up global values which are to be used in the rest of the notebook. In such cases one can select and run the notebook up to the cell containing Manipulate, use the dynamic interface, and subsequently select and run the remainder of the notebook.

But it would be great to evaluate the whole notebook with the "Evaluate Notebook" menu item, and have the evaluation pause after the Manipulate, then continue when the user clicks a button indicating that they are done manipulating.

A simple example (each line represents a separate cell):

Manipulate[amazingGraphics[y], {y, 0, 1}, Button["Done", global = y^2]]

(* evaluation pauses here until the button is clicked *)

doSomeStuff[global]

doSomeMoreStuff[]

etc[]

How can this be achieved?

Kuba
  • 136,707
  • 13
  • 279
  • 740
LiMa
  • 41
  • 1
  • And your question is ? – Sektor Sep 08 '14 at 11:12
  • 1
    Can you make up a minimal working example? How would you indicate that a given Manipulate is finished? – Yves Klett Sep 08 '14 at 11:21
  • @YvesKlett https://www.youtube.com/watch?v=hShY6xZWVGE – Dr. belisarius Sep 08 '14 at 14:09
  • 2
    @belisarius a classic, closely followed by the formula for transparent aluminum. – Yves Klett Sep 08 '14 at 14:26
  • 1
    @YvesKlett Yep.I love this sentence: " However, the transparent state lasted for only 40 femtoseconds, until electrons returned to the material." – Dr. belisarius Sep 08 '14 at 14:29
  • I think what the OP requests is a bad idea and completely subverts the intended use of dynamic forms such as Manipulate, but it might be possible. My idea is to rig some sort of trigger, conditionally evaluated within the first argument expression of the Manipulate, that deletes the output cell. I'm a little unclear about the "next cell should be evaluated after Manipulate has finished" bit. Not obvious to me which cell qualifies as next :D Joking aside, I say to the OP: you need to tell us much more about what you are trying to accomplish before we can help you. – m_goldberg Sep 08 '14 at 15:49
  • I think @LiMa may just want the ContinuousAction, SynchronousUpdating, and/or SynchronousInitialization options. – Brett Champion Sep 08 '14 at 21:05
  • 1
    I'll take a stab at interpreting the OP's request - I think the desired functionality is to generate a set of controller states, then use a Button to store those states in a symbol and execute some further code. – bobthechemist Sep 08 '14 at 22:21
  • 2
    While the question is incomplete, I think bobthechemist's interpretation is correct and I would find the functionality useful. Hopefully my edit will make the question suitable for reopening. – Simon Woods Dec 06 '15 at 23:16

2 Answers2

5

Taking inspiration from Kuba's answer I went digging in DialogInput and found the undocumented function WaitUntil which is used to pause evaluation until its argument is True. So this works:

a = 1;
Column[{
  Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}, LocalizeVariables -> False],
  $done = False; DefaultButton[$done = True]
  }]

next cell...

WaitUntil[$done];
a

Here's a picture of the notebook before the button is clicked. I used "Evaluate Notebook" from the menu and the evaluation has paused at WaitUntil, allowing me to use the Manipulate controls to set a and then click the button to continue the evaluation:

enter image description here

Simon Woods
  • 84,945
  • 8
  • 175
  • 324
4

I'd go with DialogInput or friends:

a = 1;

DialogInput@
 Column[{Manipulate[Plot[Sin[x (1 + a x)], {x, 0, 6}], {a, 0, 2}, 
    LocalizeVariables -> False], DefaultButton[]}]

a

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740