Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I needed to make 2 slider inter-dependent. Slider b in this example can't be larger than slider a. When I move slider b and release the mouse it will snap back if it stopped at a value larger than current value of a slider.

I noticed this works first time. But when I move the slider b again, it no longer snaps back.

I found this is becuase I had ContinuousAction -> False. But this should not have this effect. This option says that while I am sliding there should be no update to the Manipulate expression. So, once I have released the mouse, my snap logic code should execute each time. In this example below I show that it does not.

Do you think this behaviour is correct? I think it is not. I needed to have the ContinuousAction -> False there for other reasons (I do not want large computation to occur while I am moving the slider, only when I release the slider).

Here is an example that works. Notice no use of ContinuousAction -> False, hence the default is True

Manipulate[
 {a, b},

 Grid[{{
    "a", Manipulator[Dynamic[a,{a = #; If[b > a, b = a]} &], {1, 10, 1}], Dynamic[a]
    }, {
    "b", Manipulator[Dynamic[b,{b = #; If[b > a, b = a]} &], {1, 10, 1}], Dynamic[b]
    }}],
 {{a, 5}, None},
 {{b, 3}, None}
 ]

You can move the slider b to the right as much as you want, release the mouse, and keep doing that. It will never go pass the value in a. Now see what happens with this example:

 Manipulate[
 {a, b},

 Grid[{{
    "a", Manipulator[Dynamic[a,
      {a = #; If[b > a, b = a]} &], {1, 10, 1},ContinuousAction -> False], Dynamic[a]
    }, {
    "b", Manipulator[Dynamic[b,
      {b = #; If[b > a, b = a]} &], {1, 10, 1},ContinuousAction -> False], Dynamic[b]
    }}],
 {{a, 5}, None},
 {{b, 3}, None}
 ]

Move the slide b again. The first time you'll notice the snaps back. But now try to move it again to the right, and you'll see it does not snap back again. The logic inside the Dynamics is not being called.

Question: Do you think this behaviur is correct based on the help:

With ContinuousAction->False, updates are supplied only when the controls are in their final position, say as determined by the release of a mouse button.

For me, the above says one thing, and what I see is something else. What seems to happen is that Mathematica takes the second movement of the same slider as part of the first movement. Even though one has released the mouse in between. But these should be separate movement and not one continuous one.

thanks

share|improve this question
Just to clarify: I am just asking if the above behaviour is correct based on the description in the help. I am not asking for a workaround. I wanted to submit a bug report to WRI, but thought to check with the experts first becuase it might be that this is the way it is supposed to work and I simply misunderstood the description. – Nasser Aug 21 '12 at 1:49
fyi, I submitted a bug report to WRI on this. – Nasser Aug 22 '12 at 1:07

1 Answer

up vote 2 down vote accepted

I would recommend a simpler version to achieve this. It works for all settings of ContinuousAction.

Manipulate[If[a < b, b = a]; {a, b}, {{a, 5}, 1, 10, 1}, {{b, 5}, 1, a, 1}]

Manipulate[If[a < b, b = a]; {a, b}, {{a, 5}, 1, 10, 1, 
  ContinuousAction -> False}, {{b, 5}, 1, a, 1, ContinuousAction -> False}]
share|improve this answer
Thanks. But I must use the second argument of Dynamics form. That is why I use Manipulator. It is critical for the way I do demos. I use the second argumet of dynamics as an event handler. Where I process the control variable change, then tickle another dynamic tick variable, which drives the whole simulation. – Nasser Aug 20 '12 at 23:14
Let me just add, that for this particular case, I can add this one check at the top as you show, i.e. in the Manipulate expression. But as a general case, I find it better to use the second dynamic argument. Action and logic is localized right next to where the control variable is. It makes the overall design better, as each logic is next to the control it affect. For a large an complex GUI this becomes much more important. – Nasser Aug 20 '12 at 23:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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