Changeset 641 for trunk/src/uigetfile_uvmat.m
- Timestamp:
- May 21, 2013, 9:12:42 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uigetfile_uvmat.m
r635 r641 10 10 % InputDir: directory to browse at first display 11 11 12 function fileinput=uigetfile_uvmat(title,InputName) 12 function fileinput=uigetfile_uvmat(title,InputName,FilterExt) 13 if ~exist('FilterExt','var') 14 FilterExt='*'; 15 end 13 16 fileinput=''; %default file selection 14 17 if strcmp(title,'status_display') … … 59 62 uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',... 60 63 'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold'); 61 uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option, src,event),'tag','list',...64 uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option,FilterExt,src,event),'tag','list',... 62 65 'FontUnits','points','FontSize',12); 63 66 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... … … 80 83 drawnow 81 84 end 82 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName )% refresh the list of content of the current dir85 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 83 86 if ~strcmp(option,'status_display') 84 87 uiwait(hfig) … … 98 101 %------------------------------------------------------------------------ 99 102 % --- launched by refreshing the display figure 100 function refresh_GUI(hObject,InputFileName )103 function refresh_GUI(hObject,InputFileName,FilterExt) 101 104 %------------------------------------------------------------------------ 102 105 if ~exist('InputFileName','var') … … 125 128 NbOutputFile_str=num2str(NbOutputFile); 126 129 end 127 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart );% list the directory content130 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart,FilterExt);% list the directory content 128 131 129 132 %% update the waitbar … … 140 143 end 141 144 hcheck_date=findobj(hfig,'tag','check_date'); 142 [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option );% list the directory content145 [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content 143 146 end 144 147 … … 169 172 %------------------------------------------------------------------------ 170 173 % --- launched by selecting an item on the file list 171 function list_Callback(option, hObject,event)174 function list_Callback(option,filter_ext,hObject,event) 172 175 %------------------------------------------------------------------------ 173 176 hfig=get(hObject,'parent');%handle of the fig … … 214 217 hcheck_date=findobj(hfig,'tag','check_date'); 215 218 216 ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option );% list the directory content219 ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content 217 220 set(hObject,'Value',1) 218 221 set(hObject,'String',ListFiles) … … 242 245 %------------------------------------------------------------------------- 243 246 % list the content of a directory 244 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option )247 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) 245 248 %------------------------------------------------------------------------- 246 249 ListStruct=dir(DirName);% get structure of the current directory … … 253 256 ListFiles=ListCells(1,:);%list of file names 254 257 check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files 258 255 259 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display 256 260 ListDates=cell2mat(ListCells(5,:));%list of numerical dates … … 262 266 ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front 263 267 end 268 264 269 if isnumeric(sort_option)|| strcmp(sort_option,'date') 265 270 [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list … … 270 275 cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) 271 276 check_keep=cellfun('isempty', cell_remove); 277 if exist('filter_ext') 278 switch filter_ext 279 case 'image' 280 check_keep=check_keep & (cellfun(@isimage,ListFiles) |check_dir); 281 end 282 end 272 283 ListFiles=[{'+/..'} ListFiles(check_keep)]; 273 284 if check_date … … 319 330 320 331 %------------------------------------------------------------------------- 321 % launched by deleting the status figure (only used in mode series status') 332 % --- launched by deleting the status figure (only used in mode series status') 333 %------------------------------------------------------------------------- 322 334 function close(option,hObject, eventdata) 323 %------------------------------------------------------------------------- 335 324 336 if strcmp(option,'status_display') 325 337 hseries=findobj(allchild(0),'Tag','series'); … … 330 342 delete(gcbf) 331 343 344 %------------------------------------------------------------------------- 345 % --- check whether a file is has an image name extension 346 %------------------------------------------------------------------------- 347 function CheckImage=isimage(filename) 348 349 [pp,name,ext]=fileparts(filename); 350 ext 351 CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.','')));
Note: See TracChangeset
for help on using the changeset viewer.