3

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?

Kuba
  • 136,707
  • 13
  • 279
  • 740
Stitch
  • 4,205
  • 1
  • 12
  • 28
  • 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. – b3m2a1 Aug 31 '17 at 04:38
  • What version are you using? I don't see "Evaluating Initialization..." which is expected, since there isn't any Initialization. – Kuba Aug 31 '17 at 06:09
  • An example where it appears and is expected is: Manipulate[x, {x, 0, 1}, SynchronousInitialization -> False, Initialization :> (Pause[1])] – Kuba Aug 31 '17 at 06:11

1 Answers1

3

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

Kuba
  • 136,707
  • 13
  • 279
  • 740