Pro thm_ui_set_tlimits_event, event
@tplot_com
Common tlimits_saved, t0_sav, t1_sav, t0_init, t1_init
Common saved_time_sel, time_selected
err_xxx = 0
catch, err_xxx
If(err_xxx Ne 0) Then Begin
catch, /cancel
help, /last_message, output = err_msg
For j = 0, n_elements(err_msg)-1 Do print, err_msg[j]
If(is_struct(state) Eq 0) Then Begin
widget_control, event.top, get_uval = state, /no_copy
Endif
thm_ui_update_progress, state.gui_id, 'Error, No Time limits chosen'
thm_ui_update_history, state.gui_id, [';*** FYI', ';'+err_msg, 'No Time Limits Chosen']
widget_control, state.messw, set_val = 'Error, No Time limits chosen'
widget_control, event.top, /destroy
Return
Endif
If(TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') Then Begin
If(is_struct(state) Eq 0) Then $
widget_control, event.top, get_uval = state, /no_copy
gui_id = state.gui_id & messw = state.messw
widget_control, event.top, set_uval = state, /no_copy
If(is_struct(wstate)) Then $
widget_control, gui_id, set_uval = wstate, /no_copy
thm_ui_update_progress, message_wid = messw, gui_id, 'No Time limits chosen'
widget_control, event.top, /destroy
Return
Endif
widget_control, event.id, get_uval = uval
If(uval Eq 'CANCEL') Then Begin
widget_control, event.top, get_uval = state, /no_copy
gui_id = state.gui_id & messw = state.messw
widget_control, event.top, set_uval = state, /no_copy
thm_ui_update_progress, message_wid = messw, gui_id, 'No Time limits chosen'
widget_control, event.top, /destroy
Endif Else If(uval Eq 'EXIT') Then Begin
widget_control, event.top, get_uval = state, /no_copy
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'End Choosing time limits'
h = 'tlimit, '+''''+time_string(t0_sav)+''''+', '+ $
''''+time_string(t1_sav)+''''
thm_ui_update_history, state.gui_id, h
widget_control, state.gui_id, get_uval = wstate, /no_copy
wstate.pstate.st_time = min([t0_sav, t1_sav])
wstate.pstate.en_time = max([t0_sav, t1_sav])
t0_sav = wstate.pstate.st_time
t1_sav = wstate.pstate.en_time
pstate = wstate.pstate
If(ptr_valid(wstate.active_vnames)) Then Begin
tvn = *wstate.active_vnames
Endif Else tvn = '*'
widget_control, state.gui_id, set_uval = wstate, /no_copy
widget_control, event.top, set_uval = state, /no_copy
do_tplot = 1b
cwno = pstate.current_wno
cwno_tplot = -1
If(is_struct(tplot_vars)) Then Begin
If(is_struct(tplot_vars.settings)) Then $
If(tag_exist(tplot_vars.settings, 'window')) Then $
cwno_tplot = tplot_vars.settings.window
Endif
If(cwno Eq cwno_tplot And cwno Eq !d.window And !d.window Ne -1) Then do_tplot = 0b
If(do_tplot) Then Begin
window, cwno, xsize = pstate.windowsize[0], ysize = pstate.windowsize[1]
tplot, tvn
Endif
tlimit, t0_sav, t1_sav
widget_control, event.top, /destroy
Endif Else If(uval Eq 'STTIME_DISPLAY') Then Begin
widget_control, event.top, get_uval = state, /no_copy
widget_control, event.id, get_val = temp_string
t0 = thm_ui_timefix(temp_string)
If(event.type Le 2) Then Begin
If(is_string(t0)) Then Begin
t0_sav = time_double(t0)
If(t1_sav Le t0_sav) Then Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'End Time is LE Start Time'
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Valid Start Time selected'
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Bad time selection, No action taken'
Endelse
Endif
widget_control, event.top, set_uval = state, /no_copy
Endif Else If(uval Eq 'ENTIME_DISPLAY') Then Begin
widget_control, event.top, get_uval = state, /no_copy
widget_control, event.id, get_val = temp_string
t1 = thm_ui_timefix(temp_string)
If(event.type Le 2) Then Begin
If(is_string(t1)) Then Begin
t1_sav = time_double(t1)
If(t1_sav Le t0_sav) Then Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'End Time is LE Start Time'
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Valid End Time selected'
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Bad time selection, No action taken'
Endelse
Endif
widget_control, event.top, set_uval = state, /no_copy
Endif Else Begin
widget_control, event.top, get_uval = state, /no_copy
For j = 0, n_elements(state.button_arr)-1 Do $
widget_control, state.button_arr[j], sensitive = 0
Case uval Of
'STTIME':Begin
thm_ui_tselect, init_time = t0_sav
t0 = time_selected
If(is_struct(t0)) Then Begin
t0_sav = time_double(t0)
widget_control, state.sttime_display, set_val = time_string(t0_sav)
If(t1_sav Le t0_sav) Then Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'End Time is LE Start Time'
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Valid Start Time selected'
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Bad time selection, No action taken'
Endelse
End
'ENTIME':Begin
thm_ui_tselect, init_time = t1_sav
t1 = time_selected
If(is_struct(t1)) Then Begin
t1_sav = time_double(t1)
widget_control, state.entime_display, set_val = time_string(t1_sav)
If(t1_sav Le t0_sav) Then Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'End Time is LE Start Time'
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Valid End Time selected'
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Bad time selection, No action taken'
Endelse
End
'TLIMIT':Begin
widget_control, state.gui_id, get_uval = wstate, /no_copy
If(ptr_valid(wstate.active_vnames)) Then Begin
tvn = *wstate.active_vnames
Endif Else tvn = ''
pstate = wstate.pstate
widget_control, state.gui_id, set_uval = wstate, /no_copy
If(pstate.ptyp Eq 'SCREEN') Then Begin
If(is_string(tvn)) Then Begin
do_tplot = 1b
cwno = pstate.current_wno
cwno_tplot = -1
If(is_struct(tplot_vars)) Then Begin
If(is_struct(tplot_vars.settings)) Then Begin
If(tag_exist(tplot_vars.settings, 'window')) Then $
cwno_tplot = tplot_vars.settings.window
Endif
Endif
If(cwno Eq cwno_tplot And cwno Eq !d.window And !d.window Ne -1) Then Begin
If(is_struct(tplot_vars)) Then Begin
If(is_struct(tplot_vars.options)) Then Begin
tvn_t = tplot_vars.options.varnames
If(n_elements(tvn_t) Eq n_elements(tvn)) Then Begin
do_tplot = 0b
For j = 0, n_elements(tvn)-1 Do If(tvn[j] Ne tvn_t[j]) Then do_tplot = 1b
Endif
Endif
Endif
Endif
If(do_tplot) Then Begin
window, cwno, xsize = pstate.windowsize[0], ysize = pstate.windowsize[1]
tplot, tvn
Endif
trange_new = -1
ctime, trange_new, npoints = 2
If(n_elements(trange_new) Eq 2) Then Begin
t0_sav = trange_new[0] & t1_sav = trange_new[1]
widget_control, state.sttime_display, set_val = time_string(t0_sav)
widget_control, state.entime_display, set_val = time_string(t1_sav)
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Bad time Selection '
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'No Active Dataset, No time selection '
Endelse
Endif Else Begin
thm_ui_update_progress, message_wid = state.messw, state.gui_id, $
'Please set SCREEN plot for time selection '
Endelse
End
'RESET_TLIMIT':Begin
t0_sav = t0_init & t1_sav = t1_init
widget_control, state.sttime_display, set_val = time_string(t0_init)
widget_control, state.entime_display, set_val = time_string(t1_init)
End
Endcase
For j = 0, n_elements(state.button_arr)-1 Do $
widget_control, state.button_arr[j], sensitive = 1
widget_control, event.top, set_uval = state, /no_copy
Endelse
End
Pro thm_ui_set_tlimits, proc_id
Common tlimits_saved, t0_sav, t1_sav, t0_init, t1_init
timesel = widget_base(/col, /align_center, $
title = 'THEMIS: Time Selection Widget', $
/tlb_kill_request_events)
timebase = widget_base(timesel, /row, /align_left, $
title = 'Time Selection Widget')
timeselbase = widget_base(timebase, /column, /align_left, frame = 5)
sttime_button = widget_base(timeselbase, /col, /align_left)
sttimebut = widget_button(sttime_button, val = ' Choose Start time ', $
uval = 'STTIME', /align_left)
entime_button = widget_base(timeselbase, /col, /align_left)
entimebut = widget_button(entime_button, val = ' Choose End time ', $
uval = 'ENTIME', /align_left)
timedisplaybase = widget_base(timebase, /column, /align_left, frame = 5)
widget_control, proc_id, get_uval = pstate, /no_copy
widget_control, pstate.cw, get_uval = wstate, /no_copy
gui_id = pstate.cw
messw = pstate.messw
If(n_elements(t0_sav) Eq 0 Or n_elements(t1_sav) Eq 0) Then Begin
t0_sav = wstate.pstate.st_time & t1_sav = wstate.pstate.en_time
Endif
If(n_elements(t0_init) Eq 0 Or n_elements(t1_init) Eq 0) Then Begin
t0_init = wstate.st_time & t1_init = wstate.en_time
Endif
widget_control, pstate.cw, set_uval = wstate, /no_copy
widget_control, proc_id, set_uval = pstate, /no_copy
sttime_display = widget_text(timedisplaybase, /edit, $
uval = 'STTIME_DISPLAY', $
val = time_string(t0_sav), $
xsize = 30, /all_events)
entime_display = widget_text(timedisplaybase, /edit, $
uval = 'ENTIME_DISPLAY', $
val = time_string(t1_sav), $
xsize = 30, /all_events)
xbutton0 = widget_base(timebase, /col, /align_center)
tlimitbut = widget_button(xbutton0, val = ' Tlimits from Cursor ', $
uval = 'TLIMIT', /align_center)
tlimitresetbut = widget_button(xbutton0, val = ' Reset to Init value ', $
uval = 'RESET_TLIMIT', /align_center)
xbutton = widget_base(timesel, /row, /align_center)
cancelbut = widget_button(xbutton, val = ' Cancel ', $
uval = 'CANCEL', /align_center)
exitbut = widget_button(xbutton, val = ' Accept and Close ', $
uval = 'EXIT', /align_center)
button_arr = [sttimebut, entimebut, tlimitbut, tlimitresetbut, exitbut, $
cancelbut, sttime_display, entime_display]
state = {proc_id:proc_id, $
gui_id:gui_id, $
messw:messw, $
sttime_display:sttime_display, $
entime_display:entime_display, $
button_arr:button_arr}
widget_control, timesel, set_uval = state, /no_copy
widget_control, timesel, /realize
xmanager, 'thm_ui_set_tlimits', timesel, /no_block
Return
End