; file RESPOND_WIDG.PRO ; ; Creates a widget to prompt user for a "YES" or "NO" response as a default. ; But you may pass your own button names with the BUTTONS keyword. ; ; var = respond_widg, [message=message, buttons=buttons, /column, ; /row, group_leader=group] ; ; INPUTS: ; MESSAGE : String or string vector with message to be ; displayed in widget ; The default message is 'Respond YES or NO ' ; BUTTONS : String vector where each element will be a button ; You may have as many elements as will fit. ; TITLE : string to appear as widget's banner ; COLUMN : if set then the buttons will be verically placed ; ROW : if set then the buttons will be horizontally placed ; (/ROW is the default and it overrides /COLUMN) ; GROUP_LEADER : Causes the widgets destruction if parent is killed ; ; OUTPUTS: ; Returns a -1 if program fails else it returns the index number of ; the button that was selected, as determined by the array BUTTONS. ; Indexes start at 0. ; If you passed this array then you already know your values. ; If you use the default BUTTONS array then ; 0 if "YES" was selected ; 1 if "NO" was selected ; ; ; PROCEDURE: ; Select the desired button. Control will not be returned until you do. ; ; RESTRICTIONS: ; must have X windows device ; ; MODIFICATION HISTORY: ; FEB 1993 - Elaine Einfalt (HSTX) ; ; pro respond_event, event ; the event handler for RESPOND_WIDG common respond_widget, result ; ; Only two things could have happen: the user clicked on the YES or the NO ; widget_control, event.id, get_uvalue=input ; which was clicked result = long(input) ; this button was clicked widget_control, event.top, /destroy ; get rid of widget return end function respond_widg, message=message, buttons=buttons, title=title, $ column=column, row=row, group_leader=group common respond_widget, result result = -1 if n_elements(title) eq 0 then title='Use mouse to choose' if keyword_set(column) then rows = 0 else rows=1 if keyword_set(row) then rows = 1 mess_loop = n_elements(message)-1 & if mess_loop eq -1 then begin message = 'Respond YES or NO ' mess_loop = 0 endif if not keyword_set(buttons) then but_names = [' YES ', ' NO '] $ ; defaults else but_names = buttons ; user's but_loop = n_elements(but_names) & but_junk = lonarr(but_loop) ; ; Create widget with a message and as many buttons as in the array BUTTONS, ; which will require one of the buttons to be selected ; if rows then base = widget_base(title=title, /row, $ xpad=25, ypad=25, space=20) $ else base = widget_base(title=title, /column, $ xpad=25, ypad=25, space=20) label = widget_base(base, /column) ; the message is written ; in a column, regardless. for i = 0, mess_loop do lab = widget_label(label, value=message(i)) for i = 0, but_loop-1 do $ but_junk(i) = widget_button(base, value=but_names(i), $ uvalue=strtrim(i)) widget_control, base, /realize xmanager, 'respond', base, group_leader=group, /modal return, result end