4
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Can you make up a minimal working example? How would you indicate that a given Manipulate is finished? $\endgroup$ – Yves Klett Sep 8 '14 at 11:21
  • 2
    $\begingroup$ @belisarius a classic, closely followed by the formula for transparent aluminum. $\endgroup$ – Yves Klett Sep 8 '14 at 14:26
  • 1
    $\begingroup$ @YvesKlett Yep.I love this sentence: " However, the transparent state lasted for only 40 femtoseconds, until electrons returned to the material." $\endgroup$ – Dr. belisarius Sep 8 '14 at 14:29
  • 1
    $\begingroup$ 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. $\endgroup$ – bobthechemist Sep 8 '14 at 22:21
  • 2
    $\begingroup$ 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. $\endgroup$ – Simon Woods Dec 6 '15 at 23:16
5
$\begingroup$

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

$\endgroup$
4
$\begingroup$

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

$\endgroup$
  • $\begingroup$ This is a good idea, though it would be nice to keep the Manipulate in the notebook. $\endgroup$ – Simon Woods Dec 7 '15 at 21:22
  • $\begingroup$ @SimonWoods I'd say it's a matter of taste :) $\endgroup$ – Kuba Dec 7 '15 at 21:37
  • $\begingroup$ Agreed, sometimes the dialog is a better choice. $\endgroup$ – Simon Woods Dec 7 '15 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.