Message Boards Message Boards

What is the point of PaneSelector?



PaneSelector looks like a pretty idiomatic way to toggle displayed content e.g.:

  {True -> progressBar, False -> button}
, Dynamic @ processing

Analogous If version:

Dynamic[ If[processing, progressBar, button] ]

The difference is that PaneSelector content will be converted to boxes and each switch can be faster than Dynamic which contents are sent for typesetting every time it is refreshed. Shortly, for PS only the value of processing does the round trip while for Dynamic[If[...]], full content.

Sounds good, does not work. I regret each time I use it.

Problem 1

DynamicModule[{processing = False, longProcedure},
 longProcedure[] := Pause[2];
   progressBar = ProgressIndicator[Appearance -> "Indeterminate"],
   button = Button["Run", processing = True; longProcedure[];         processing = False, Method -> "Queued"],
   buttonAsync = Button["Run async", processing = True;         RunScheduledTask[longProcedure[], {.1}, "EpilogFunction" :> (processing = False)], Method -> "Queued"]
    {"processing:", Style[Dynamic @ {processing}, Bold], SpanFromLeft},
    {"PS:", PaneSelector[{True -> progressBar, False -> button},           Dynamic@processing, ImageSize -> All]},
    {"If:", Dynamic[If[TrueQ@processing, progressBar, button]]},
    {"PS:", PaneSelector[{True -> progressBar, False -> buttonAsync},           Dynamic@processing, ImageSize -> All]},
    {"If:", Dynamic[If[TrueQ@processing, progressBar, buttonAsync]]},
    {"Just toggle:",  Button["toggle", processing = ! processing;, Method -> "Queued"]},
    {"Toggle and pause:", Button["toggle2", processing = ! processing; Pause[2];,  Method -> "Queued"]}
    }, Alignment -> Left]

enter image description here

  • Pressing Run affects only If based solutions and not PS.

  • Pressing Run async shows both progress bars but when it is done only the If based solution shows the button back.

  • Simple toggle works as expected

  • Toggle and pause triggers PS based solution only after Pause is finished.

Using FinishDynamic is an overkill here.

Problem 2

It does undocumented caching so you need to inject to your view stuff like random numbers:

Do you fancy debugging by inserting RandomReal[] here and there? I do not.

Problem 3

Since it usually has PaneSelector[{__}, Dynamic[_Symbol]] form, you don't know when this [tag:bug] will hit you:


Did I miss the point of this function? What are the basic rules to follow to not face problems like this? Or is it better to just ignore this function which is what I would suggest to do.

p.s. cross posted in stack exchange

POSTED BY: Kuba Podkalicki
23 days ago

Group Abstract Group Abstract