3
$\begingroup$

I have a relatively long code inside Manipulate that computes an output depending on controls. Computation takes about a second, so I am using SynchronousUpdating->False. However, when I do it, initialization of the object is not nice when the content is displayed for the first time. Not only is it a plain bar, but also it shows a misleading tooltip if the mouse is over it (the dynamic is not disabled, and after a second you get a normal object):

Manipulate[Pause[1]; x, {x, 0, 1}, SynchronousUpdating -> False]

enter image description here

I tried to use SynchronousInitialization -> False, which does what I want:

Blockquote

But it only works when SynchronousUpdating -> True. If it is False, as I need, it doesn't work.

Any ideas how to make the initialization prettier and keep the Manipulateresponsive?

$\endgroup$
3
  • $\begingroup$ Can you push some computation time to the Initialization option of the Manipulate? Worst case, a quick DynamicModule with some Control specs isn't too bad here. There you can use three-function Dynamic to get a nicer display. $\endgroup$
    – b3m2a1
    Aug 31, 2017 at 4:38
  • $\begingroup$ What version are you using? I don't see "Evaluating Initialization..." which is expected, since there isn't any Initialization. $\endgroup$
    – Kuba
    Aug 31, 2017 at 6:09
  • $\begingroup$ An example where it appears and is expected is: Manipulate[x, {x, 0, 1}, SynchronousInitialization -> False, Initialization :> (Pause[1])] $\endgroup$
    – Kuba
    Aug 31, 2017 at 6:11

1 Answer 1

3
$\begingroup$

EDIT

The original Kuba's code is slightly modified to 1) ensure finished is initialized (added Initialization line); and 2) avoid slider handle being stuck sometimes and jump back (replaced built-in Manipulate control with an explicit Slider)

Here's what you can do:

DynamicModule[{finished, display}
  , Manipulate[
        DynamicWrapper[
            Dynamic[
                If[finished
                  , display
                  , ProgressIndicator[Appearance -> "Indeterminate"]
                ]
              , TrackedSymbols :> {finished}
            ]
          , finished = False
          ; Pause @ 1
          ; display = {x, x}
          ; finished = True
          , SynchronousUpdating -> False
        ]
      , Row[{Slider[Dynamic@x, {0, 1}]}]
      , Initialization :> (finished = False)

    ]
]

similar ideas are used in:

Performance issue of Manipulate with NSolve and Locator

Button action monitored with progress bar

How to Initiate a queued evaluation from a Dynamic GUI without using a Button

Working with DynamicModule: Tracking the progress of Initialization

$\endgroup$
1
  • $\begingroup$ Perfect! You are GUI wizard :). Slight modifications added to your code! $\endgroup$
    – Stitch
    Aug 31, 2017 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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