Stateful button widgets in non-main windows



I had an interesting (to me, anyway) situation:

I have a program which, if a user presses a button, opens a new window containing various text entries, 
textviews, and radiobuttons. The new window also contained a checkbutton. The state of the radiobuttons and 
checkbutton were stored in flags (integers). Whenever the new window was opened, the states of the flags 
associated with the radio and checkbuttons were saved in separate temporary variables, then the radio and 
checkbuttons were set in the GUI to active or not, based on the flag values, and then the flag values 
restored using the saved temporary values. The temporary values were necessary because by setting the states 
of radio and checkbuttons as active, or not, that triggers on_radiobutton_toggled or on_checkbutton_toggled 
callbacks which would change the flag values.

This system worked fine until I took this one step further. In this case, I had a checkbutton in the new 
window which, not only triggered a callback which changed the flag value, but also did some calculations and 
updated other values and stuff in the main window as well as stored data. In this case, upon opening the new 
window, saving current flag value, setting checkbutton state to active or not on the GUI, and then restoring 
flag value, is inadequate, because the callback was doing more than just changing a flag value.

My solution was to not use a stateful button in the new window (radiobuttons, checkbuttons being stateful). 
So instead of a checkbutton, I put a plain button, and beside it, a textview showing the current state of the 
flag.

Now, when opening the new window, the flag's current value is represented in the textview and I don't need to 
set any state for the button, since it's not stateful. Thus, no callback is triggered.


Works great and it isn't ugly, but is this the best solution?

Dave


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