short version of question:
Is there some way to tell in a GtkAdjustment value_changed callback if the change was caused by the user taking action (with the mouse) or if the value was changed by the program itself (for instance using gtk_adjustment_set_value())?
I have an application written using another GUI that I am considering porting to the GTK+ GUI. In testing, GTK+, I have noticed an interaction which will cause trouble unless I can find a work-around.
The application does an astrodynamic computation in 3 variables, each of which may be set using a slider (a gtk_hscale, for instance), and displays the resulting satellite orbit in an OpenGL drawing.
However, the situation may equally well be described by 3 OTHER variables. So I have 3 additional sliders showing these values. When I change any one of the first 3 sliders, typically all three of the second set of sliders need to move to reflect new values. Similary, if any one of the second set of sliders is changed, all three of the first sliders need to move to show new values.
The probem stems from the GtkAdjustment callbacks and the fact that converting between the two sets of variables is quite complex. The complexity of the computation leads to slight rounding and truncation errors, so converting value set A to value set B and back to value set A does not exactly result in the original values.
Call the two sets of sliders A and B. Here is what happens:
1. Move a slider in set A.
2. A value_changed callback occurs, and I compute and set values for each slider in set B.
3. Next, because the sliders in set B have changed, I get three value_changed callbacks, each of which causes a recomputation of values for slider set A and causes their values to be reset
4. Because the sliders in set A have changed, I get more callbacks which recompute and set the sliders in set B.
5. Because the sliders in set B have changed, I get more callbacks which recompute and set the sliders in set A.
6. etc. ...
It will just loop forever.
So I need to be able to distinguish between a callback caused by the user and one caused by the program itself. I would act on the former and ignore the latter and the problem would be solved.
Thanks for any ideas.
|All times are GMT -5. The time now is 11:07 AM.|