Coyote's Guide to IDL Programming

Finding the Currently Selected Exclusive Button

QUESTION: I have an exclusive base that is populated by a number of button children. Only one of the buttons can be selected at any particular time. I use the command:

   WIDGET_CONTROL, button1, SET_BUTTON=1

to select the initial button to turn ON. All the rest of the buttons are OFF.

What I don't understand is how to be aware of the currently selected button while my widget program is running. In other words, how can I know which button is currently selected in a group of other buttons? Is there a keyword to Widget_Control or Widget_Info that I can use?

ANSWER: The selected button is identified by the ID field of the event structure in your button (or base) event handler. All other buttons in the exclusive base will be de-selected automatically. If you want other parts of the program (i.e., other event handlers) to know which button is currently selected, you normally put a "currentButton" field in your "info" structure. Your button event handler code might look something like this:

   PRO Button_Events, event
   Widget_Control, event.top, Get_UValue=info, /No_Copy
   info.currentButton = event.ID
   Widget_Control, event.top, Set_UValue=info, /No_Copy
   END

Unfortunately, there is no keyword to either Widget_Control or Widget_Info that can give you this information.

Google
 
Web Coyote's Guide to IDL Programming