; Author: P. Romashkin ; Date: 9-28-2001 ; Utility function allowing to save contents of a local variable to a top-level variable. ; Usage: EXPORT_TO_MAIN, MY_VARIABLE ; ********************* pro export_to_main_ev, event compile_opt IDL2, obsolete, hidden ;Since events are very limited, simplify event handling. Action=widget_info(event.id, /name) ;Only Text or Button can be an event source. case Action of 'TEXT': begin widget_control, event.top, get_uvalue=Stored widget_control, event.id, get_value=Temp *Stored = Temp[0] widget_control, event.top, /DESTROY end 'BUTTON': begin widget_control, event.top, get_uvalue=Stored widget_control, widget_info(event.top, /child), get_uvalue=Entry_field widget_control, Entry_field, get_value=Temp *Stored = Temp[0] widget_control, event.top, /DESTROY end else : endcase end ; ********************* pro export_to_main, value, group_leader=group_leader, TITLE=TITLE, _extra=_extra compile_opt IDL2, obsolete, hidden if n_elements(_extra) ne 0 then begin junk = dialog_message(['Author: Pavel A. Romashkin, NOAA/CMDL-CIRES, 9-28-2001. ', $ 'EXPORT_TO_MAIN allows to save a local variable ', + $ 'from a routine to the main IDL level. ', 'Usage: ', 'EXPORT_TO_MAIN, My_Variable. ', $ 'If My_Variable is not defined, EXPORT_TO_MAIN returns quietly. ', $ 'Keywords (optional): ', 'TITLE - set to the title of the popup dialog, ', $ 'GROUP_LEADER - set to widget ID of a group leader base.']) return end if n_elements(value) eq 0 then return Stored=ptr_new('') if not keyword_set(TITLE) then Label='Variable name:' else Label=TITLE ;STORED will allow to recover the result after the base is killed. Base =widget_base(group_leader=group_leader, /column, uval=Stored, title='EXP', $ event_pro='export_to_main_ev') Label = widget_label(Base, value=Label, /align_left) Entry_field = widget_text(Base, value='', xsize=5, /editable) widget_control, Label, set_uvalue=Entry_field Confirm=widget_button(Base, value='Confirm') ;Execution will be held at XMANAGER until the modal base is killed. widget_control, Base, /REALIZE junk = widget_event(base, bad_id=bad_id) ; Block the widget using WIDGET_EVENT. ;After the modal dialog was dismissed, execution continues from here. if *Stored ne '' then Result=*Stored else Result = '' ptr_free, Stored if Result ne '' then junk = routine_names(Result, value, store=1) end ; ********************* function import_from_main, group_leader=group_leader, TITLE=TITLE, _extra=_extra compile_opt IDL2, obsolete, hidden if n_elements(_extra) ne 0 then begin junk = dialog_message(['Author: Pavel A. Romashkin, NOAA/CMDL-CIRES, 9-28-2001. ', $ 'EXPORT_TO_MAIN allows to save a local variable ', + $ 'from a routine to the main IDL level. ', 'Usage: ', 'EXPORT_TO_MAIN, My_Variable. ', $ 'If My_Variable is not defined, EXPORT_TO_MAIN returns quietly. ', $ 'Keywords (optional): ', 'TITLE - set to the title of the popup dialog, ', $ 'GROUP_LEADER - set to widget ID of a group leader base.']) return, 0 end Stored=ptr_new('') if not keyword_set(TITLE) then Label='Variable name:' else Label=TITLE ;STORED will allow to recover the result after the base is killed. Base =widget_base(group_leader=group_leader, /column, uval=Stored, title='EXP', $ event_pro='export_to_main_ev') Label = widget_label(Base, value=Label, /align_left) Entry_field = widget_text(Base, value='', xsize=5, /editable) widget_control, Label, set_uvalue=Entry_field Confirm=widget_button(Base, value='Confirm') ;Execution will be held at XMANAGER until the modal base is killed. widget_control, Base, /REALIZE junk = widget_event(base, bad_id=bad_id) ; Block the widget using WIDGET_EVENT. ;After the modal dialog was dismissed, execution continues from here. if *Stored ne '' then Result=*Stored else Result = '' ptr_free, Stored if Result ne '' then return, routine_names(Result, Fetch=1) $ else return, 0b end ; *********************