;------------------------------------------------------------- ;+ ; NAME: ; W_DATATABLE ; ; PURPOSE: ; creates a simple datatable with an OK and Cancel button ; and handles the events of this widget. ; ; CATEGORY: ; general purpose widgets - modal widgets ; ; CALLING SEQUENCE: ; dlg = W_DATATABLE(parent, [keywords]) ; ; INPUTS: ; PARENT --> widget ID of the parent widget ; ; KEYWORD PARAMETERS: ; TITLE --> window title for the datatableor window (default blank) ; ; TEXT --> short descriptive text above the table (string or string array) ; ; DATA --> 2 dimensional data array to be displayed. If void, a single ; value of -999.99 should be displayed (not tested) ; ; C_HEADER --> string array with column headers. If number of elements does ; not match the first dimension of the DATA array, an empty string ; array is generated. ; ; R_HEADER --> string array with column headers. If number of elements does ; not match the first dimension of the DATA array, a string array with ; consecutive integers is generated. ; ; FORMAT --> format array ; ; GROUP_LEADER --> if this widget shall be used as a simple display ; window, you can specify a GROUP_LEADER (= widget-ID of a ; dialog box). The window will then disappear as soon as the ; dialog box is closed. NOTE: the OK and Cancel buttons will ; not be shown in this case. ; ; OUTPUTS: ; w_datatable returns a widget ID of the datatableor. For implementation ; see example below. ; ; SUBROUTINES: ; DATATABLE_EVENT --> handles datatableor events. Reacts only to OK or Cancel. ; ; REQUIREMENTS: ; ; NOTES: ; ; EXAMPLE: ; ; MODIFICATION HISTORY: ; mgs, 06 Jan 1998: VERSION 1.00 ; ;- ; Copyright (C) 1997, Martin Schultz, Harvard University ; This software is provided as is without any warranty ; whatsoever. It may be freely used, copied or distributed ; for non-commercial purposes. This copyright notice must be ; kept with any copy of this software. If this software shall ; be used commercially or sold as part of a larger package, ; please contact the author to arrange payment. ; Bugs and comments should be directed to mgs@io.harvard.edu ; with subject "IDL routine w_datatable" ;------------------------------------------------------------- FUNCTION datatable_event, event ; somewhat rudimentary now. Returned information is not used ! ; Possible extensions include: ; allow inserting of new variables or cases (must take care of hidden or not ; selected values upon return) parent=event.handler ; Retrieve the structure from the child that contains the sub ids. stash = WIDGET_INFO(parent, /CHILD) WIDGET_CONTROL, stash, GET_UVALUE=state, /NO_COPY passevent = 0 ; ---------------------------------- ; button pressed ("OK" or "Cancel") ; ---------------------------------- if(event.id eq state.bID) then begin widget_control,state.tableID,get_value=data info = data value = 1-event.value ; OK=1, Cancel=0 passevent = 1 ; this terminates the dialog endif ; Restore the state structure WIDGET_CONTROL, stash, SET_UVALUE=state, /NO_COPY if (passevent) then $ return, { ID:parent, TOP:event.top, HANDLER:0L, VALUE:value , $ INFO:info } $ else $ return,0 END ;----------------------------------------------------------------------------- FUNCTION w_datatable, TITLE=title, TEXT=text, UVALUE=uval, $ GROUP_LEADER=group_leader, YOFFSET=yoffset, $ DATA=data, C_HEADER=c_header, R_HEADER=r_header, $ FORMAT=format ON_ERROR,2 ; return to caller ; Defaults for keywords IF NOT (KEYWORD_SET(uval)) THEN uval = 0 if (not keyword_set(title)) then title = ' ' if (not keyword_set(text)) then text = '' if (not keyword_set(group_leader)) then group_leader = 0 if (not keyword_set(yoffset)) then yoffset = 0 if (n_elements(data) lt 2) then data = [ -999.99 ] s = size(data) if (s(0) gt 2) then $ message,"Table works only up to 2 dimensions !" if (s(0) eq 1) then s(2) = 1 ; fake 2 dimensional array if (n_elements(c_header) ne s(1)) then c_header = strarr(s(1)) if (n_elements(c_header) eq 1) then c_header = [ c_header ] if (n_elements(r_header) ne s(2)) then r_header = string(indgen(s(2))+1) if (n_elements(r_header) eq 1) then r_header = [ r_header ] if (group_leader gt 0) then tlb_attr = 3 else tlb_attr=0 base = WIDGET_BASE(TITLE=title, UVALUE = uval, $ frame = 3, /column, YOFFSET=yoffset, $ EVENT_FUNC = "datatable_event", GROUP_LEADER=group_leader, $ tlb_frame_attr = tlb_attr ) textf = widget_text(base,value=text,frame=0) xsize = 2 > n_elements(c_header) xscrollsize = xsize < 16 ysize = 8 > n_elements(r_header) yscrollsize = ysize < 40 tablef = widget_table(base,value=data,format=format, $ column_labels=c_header,row_labels=r_header, $ xsize=xsize,x_scroll_size=xscrollsize, $ ysize=ysize,y_scroll_size=yscrollsize,/scroll ) if (group_leader eq 0) then $ buttons = cw_bgroup(base,/row,['OK','Cancel']) $ else $ buttons = -1 state = { bID:buttons, tableID:tablef } ; Save out the initial state structure into the first childs UVALUE. WIDGET_CONTROL, WIDGET_INFO(base, /CHILD), SET_UVALUE=state, /NO_COPY RETURN, base END