Re: how to lock two sliders or spin buttons



Hi Amadeus,

On Fri, 2005-12-23 at 00:14 -0500, Amadeus W. M. wrote:
> I want to mimic the behavior of the knobs in volume control applications.
> Usually there is a knob for the left speaker and another for the right
> one, and a lock check button. If the lock is on, sliding one of the knobs
> moves the other one simultaneously.
> 
> I have two spin buttons rather than knobs, DxSpin and DySpin, and
> callbacks on_DxSpin_changed() and on_DySpin_changed(), connected each to
> the corresponding changed signal. 
> 
> >From within either callback, I read the value and set the other spin
> button to the exact same value:
> 
> on_DxSpin_changed()
> {
>   if(Lock->get_active())
>     DySpin->set_value(DxSpin->get_value());
> }
> 
> and similarly for DySpin. This naive approach produces an infinite loop,
> obviously: each time the Dx button changes the value of Dy, Dy will also
> change the value of Dy, and so on.
> 
> How do I do this? 

You could test for equality before setting the new value, e.g.

if(Lock->get_active() && get_value()!=the_other->get_value()) {
	the_other->set_value(get_value());
}

or something similar.

Matthias





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]