;+ ; NAME: ; qView_PickFiles ; PURPOSE: ; Called by qView_Event to process message from the Pick Files widget. ; Selects first and last image file using the IDL 'pickfile' dialog. ; Only the first and last selected files are used. ; CATEGORY: ; Widget qView ; CALLING SEQUENCE: PRO qView_PickFiles, state ; INPUTS: ; state scalar, structure ; contains IDs for all qView widgets ; OUTPUTS: ; (to widget) ; CALLS: ; GetFileSpec, SetFileSpec, FindAllFiles, SuperArray, img_read ; qView_InitBox, qView_UpdateFiles, hide_env, unhide_env ; INCLUDE: @compile_opt.pro ; On error, return to caller ; PROCEDURE: ; > The user value of state.wid_filter is used to initialize the 'pickfile' dialog ; > Up to two files are selected by user. ; > If no files are selected, return without modifying anything ; > The selected files must have the same file type. If not an error message ; and nothing is modified. ; > The directory and file type of the first selected file is used to ; update the value of state.wid_filter. The updated value is also stored ; in the user value of state.wid_filter, to indicate a valid filter (i.e. at ; least one file matches the filter). Effectively all files ; in a specific directory with a specific extension are picked up. ; > FindAllFiles is called to find all files matching the updated filter ; (there will always be at least one). ; > The file names returned by FindAllFiles are sorted and stored in ; in the user value of state.wid_pick ; > The values of state.frstfile and state.lastfile are updated ; with the sequence number in the sorted list of files of the first ; and second selected file (!!! the first file in the list has sequence ; number one, ONE MORE than the IDL array index). ; STATE INFO USED: ; widget_control, state.wid_filter, get_value=filter ; STATE INFO MODIFIED: ; (only if a valid selection is made) ; widget_control, state.wid_filter, set_value=hide_env(filter), set_uvalue=filter ; widget_control, state.wid_frst, set_value=frst ; widget_control, state.wid_last, set_value=last ; widget_control, state.wid_pick, set_uvalue=allfiles, /no_copy ; MODIFICATION HISTORY: ; JAN-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- widget_control, state.wid_folder, get_value=folder widget_control, state.wid_filter, get_value=filter filter = filepath(root=unhide_env(folder[0]),filter[0]) SetFileSpec, filter filedir = GetFileSpec(upto='directory',/asfile) filenam = GetFileSpec(part='name') IF filenam EQ '' THEN filenam = '*' filetyp = GetFileSpec(part='type') allfiles = dialog_pickfile(path=filedir,filter=filenam+filetyp, $ /multiple,group=state.wid_pick, $ title='Select files to read') IF allfiles[0] EQ '' THEN RETURN ; No files selected type = GetFileSpec(allfiles, part='type') IF n_elements(uniq(type,sort(type))) NE 1 THEN BEGIN type = dialog_message('Selected files must have the same extension') RETURN ENDIF ; All files included have the same type as the first selected file. ; The file name will still include a wild card SetFileSpec, allfiles[0] filedir = GetFileSpec(upto='directory') filetyp = GetFileSpec(part='type') filter = filedir+filenam+filetyp nfiles = n_elements(allfiles) IF nfiles EQ 2 THEN BEGIN files = allfiles[sort(allfiles)] ; FindAllFiles returns at least one valid file (i.e. nfiles >= 1), unless there are ; an awful lot of files matching the wildcard (in which case nfiles=0). filter = filedir+filenam+filetyp allfiles = FindAllFiles(filter, count=nfiles,nodir=strpos(filetyp,'.*') NE -1) IF nfiles EQ 0 AND filenam EQ '*' THEN BEGIN ; Kludge for directories with lots of files. Search the directory without ; specifying a wildcard. If all files found have the same extension then keep going. allfiles = FindAllFiles(filedir, count=nfiles, /nodir) IF nfiles GT 0 THEN BEGIN tmp = GetFileSpec(allfiles, part='type') tmp = tmp[uniq(tmp,sort(tmp))] IF n_elements(tmp) NE 1 OR tmp[0] NE filetyp THEN BEGIN allfiles = '' nfiles = 0 ENDIF ENDIF ENDIF CASE nfiles EQ 0 OF 0: allfiles = allfiles[sort(allfiles)] ; Sort file names 1: tmp = dialog_message('Probably too many files matching '+hide_env(filter)) ENDCASE ENDIF ELSE BEGIN allfiles = allfiles[sort(allfiles)] ; Sort file names files = allfiles[ [0,nfiles-1] ] ENDELSE SetFileSpec, filter widget_control, state.wid_folder, set_value=hide_env(GetFileSpec(upto='directory')) widget_control, state.wid_filter, set_value=GetFileSpec(from='name'), set_uvalue=filter IF nfiles NE 0 THEN BEGIN allfiles = SuperArray(allfiles, 3, /trail) allfiles[*,1:2] = '' ; Room for image info string and time files = strlowcase(files) all = strlowcase(allfiles) frst = (where(all[*,0] eq files[0]))[0] last = (where(all[*,0] eq files[1]))[0] widget_control, state.wid_ftsext, get_value=exten_no IF img_read(allfiles[frst,0], img, /pseudo, img_info=img_info, exten_no=exten_no) THEN BEGIN allfiles[frst,1:2] = img_info qView_InitBox, state, size(img,/dim) ENDIF widget_control, state.wid_frst, set_value=frst widget_control, state.wid_last, set_value=last widget_control, state.wid_pick, set_uvalue=allfiles, /no_copy qView_UpdateFiles, state ENDIF RETURN & END