Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-19-2004, 12:47 PM   #1
LQ Newbie
Registered: Apr 2004
Location: Lake City, Florida, USA
Distribution: Red Hat and SuSE
Posts: 9

Rep: Reputation: 0
GtkAdjustment interactions

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())?

detailed version:
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration