pro spd_ui_prompt_widget_event, event
compile_opt idl2, hidden
Widget_Control, event.TOP, Get_UValue=state, /No_Copy
err_xxx = 0
Catch, err_xxx
IF (err_xxx NE 0) THEN BEGIN
Catch, /Cancel
Help, /Last_Message, Output = err_msg
spd_ui_sbar_hwin_update, state, err_msg, /error, err_msgbox_title='Error in spd_ui_prompt_widget'
Widget_Control, event.TOP, Set_UValue=state, /No_Copy
widget_control, event.top,/destroy
RETURN
ENDIF
IF(Tag_Names(event, /Structure_Name) EQ 'WIDGET_KILL_REQUEST') THEN BEGIN
state.historyWin->update,'Prompt Widget Killed', /dontshow
Widget_Control, event.TOP, Set_uValue=state, /No_Copy
Widget_Control, event.top, /Destroy
RETURN
ENDIF
Widget_Control, event.id, Get_UValue=uval
if is_string(uval) then begin
*state.answer = uval
Widget_Control, event.top, Set_UValue=state, /No_Copy
Widget_Control, event.top, /Destroy
endif
RETURN
end
function spd_ui_prompt_widget,$
parent,$
statusBar,$
historyWin,$
promptText=promptText,$
no=no,$
yes=yes,$
allno=allno,$
allyes=allyes,$
cancel=cancel,$
ok=ok,$
maxwidth=maxwidth,$
defaultValue=defaultValue,$
title=title,$
traceback=traceback,$
frame_attr=frame_attr
compile_opt idl2
if ~is_string(title,/blank) then begin
title = 'Please Respond'
endif
if ~is_string(promptText,/blank) then begin
promptText = ' '
endif
if ~keyword_set(maxwidth) then begin
maxwidth = 100
endif
if widget_valid(parent) then begin
if ~keyword_set(frame_attr) then begin
tlb = widget_base(/col, title=title, group_leader=parent, /modal, /tlb_kill_request,/base_align_center)
endif else begin
tlb = widget_base(/col, title=title, group_leader=parent, /modal, /tlb_kill_request,/base_align_center,TLB_FRAME_ATTR=frame_attr )
endelse
endif else begin
tlb = widget_base(/col, title=title, /base_align_center)
if ~keyword_set(frame_attr) then begin
tlb = widget_base(/col, title=title, /base_align_center)
endif else begin
tlb = widget_base(/col, title=title, /base_align_center,TLB_FRAME_ATTR=frame_attr )
endelse
parent = 0
endelse
if keyword_set(frame_attr) and obj_valid(tlb) then begin
Widget_Control, tlb, TLB_FRAME_ATTR=frame_attr
endif
width = 0
width += keyword_set(yes) ? 7 : 0
width += keyword_set(no) ? 6 : 0
width += keyword_set(allyes) ? 13 : 0
width += keyword_set(allno) ? 12 : 0
width += keyword_set(cancel) ? 10 : 0
width += (keyword_set(ok) ||(~keyword_set(allyes) && ~keyword_set(allno) && $
~keyword_set(yes) && ~keyword_set(no) && ~keyword_set(cancel))) ? 6 : 0
textlines = strsplit(promptText,ssl_newline(),/extract, count=numlines)
width = max([width,strlen(textlines)])
width += 2
width = width < maxwidth
height = max([long(strlen(promptText)+2) / long(width) + 1,numlines])
textBase = widget_text(tlb, value=promptText,xsize=width,editable=0,/wrap,ysize=height)
buttonBase = widget_base(tlb, /row, /align_center)
if keyword_set(allyes) then begin
default = "yestoall"
endif
if keyword_set(yes) then begin
yesButton = widget_button(buttonBase, value=' Yes ', uvalue='yes')
default = "yes"
endif
if keyword_set(allyes) then begin
yesToAllButton = widget_button(buttonBase, value=' Yes To All ', uvalue='yestoall')
endif
if keyword_set(allno) then begin
default = "notoall"
endif
if keyword_set(no) then begin
noButton = widget_button(buttonBase, value=' No ', uvalue='no')
default = "no"
endif
if keyword_set(allno) then begin
noToAllButton = widget_button(buttonBase, value=' No To All ', uvalue='notoall')
endif
if keyword_set(ok) || (~keyword_set(allyes) && ~keyword_set(allno) && $
~keyword_set(yes) && ~keyword_set(no) && ~keyword_set(cancel)) then begin
okButton = widget_button(buttonBase, value=' Ok ', uvalue='ok')
default = "ok"
endif
if keyword_set(cancel) then begin
cancelButton = widget_button(buttonBase, value=' Cancel ', uvalue='cancel')
default = "cancel"
endif
if size(defaultValue,/type) eq 7 then begin
default = defaultValue
endif
answer = ptr_new(default)
if obj_valid(historyWin) then begin
historyWin->update,"Opening Popup With Prompt: " + promptText, /dontshow
endif
if Keyword_Set(traceback) then begin
Help, Calls=callStack
callingRoutine = (StrSplit(StrCompress(callStack[1])," ", /Extract))[0]
Help, /Last_Message, Output=idl_traceback
traceback = scope_traceback()
Print,''
Print, 'Traceback Report from ' + StrUpCase(callingRoutine) + ':'
Print, ''
for j=0,N_Elements(traceback)-1 do Print, " " + traceback[j]
if keyword_set(idl_traceback[0]) then begin
print,'Last IDL Error: '
print,idl_traceback[0]
if n_elements(idl_traceback) gt 1 then begin
print,idl_traceback[1]
endif
endif
endif
state = {tlb:tlb, parent:parent, statusBar:statusBar,historyWin:historyWin, answer:answer}
centertlb, tlb
Widget_Control, tlb, Set_UValue=state, /No_Copy
Widget_Control, tlb, /Realize
XManager, 'spd_ui_prompt_widget', tlb, No_Block=widget_valid(parent)
if obj_valid(historyWin) then begin
historyWin->update,"Closing Popup With Response: " + *answer, /dontshow
endif
return, *answer
end