Changeset 1179 for trunk/src/uigetfile_uvmat.m
- Timestamp:
- Mar 23, 2025, 11:13:38 AM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uigetfile_uvmat.m
r1144 r1179 41 41 fileinput=''; %default file selection 42 42 if strcmp(title,'status_display') 43 option='status_display'; 44 else 45 option='browser'; 43 option='status_display';% use with the button 'Status Display' from the GUI 'series' 44 else 45 option='browser';% usual browser 46 46 end 47 47 InputDir=pwd;%look in the current work directory if the input file does not exist 48 48 InputFileName='';%default 49 49 if ischar(InputName) 50 if isempty(regexp(InputName,'^http://' ))%usual files50 if isempty(regexp(InputName,'^http://', 'once'))%usual files 51 51 if exist(InputName,'dir') 52 52 InputDir=InputName; … … 68 68 InputDir=[InputDir '\'];% append '\' for a correct action of dir 69 69 end 70 else 71 [InputDir,InputFileName,Ext]=fileparts(InputName); 72 end 73 end 74 70 else % files accessed on the web by Opendap 71 [InputDir,InputFileName]=fileparts(InputName); 72 end 73 end 74 75 %% Display the browser figure 75 76 hfig=findobj(allchild(0),'tag',option);%look for existing browser fig 76 77 if isempty(hfig)% create the browser fig if it does not exist … … 83 84 hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); 84 85 BackgroundColor=get(hfig,'Color'); 86 % text title 85 87 path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',... 86 88 'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); 87 htitlebox=uicontrol('Style','edit','Units','normalized', 'Position', [0.02 0.89 0.96 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,... 89 % edit box for the current folder name 90 uicontrol('Style','edit','Units','normalized', 'Position', [0.02 0.89 0.96 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,... 88 91 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path'); 92 % button for backward move in the directory tree 89 93 uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],... 90 94 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward'); … … 118 122 uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,... 119 123 'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates'); 120 % uicontrol('Style','text','Units','normalized', 'Position', [0.37 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...121 % 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');122 124 set(OK_button,'String','Open') 123 125 set(close_button,'String','Cancel') … … 126 128 end 127 129 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 128 if ~strcmp(option,'status_display') 130 if ~strcmp(option,'status_display') && strcmp(get(hfig,'Type'),'figure') 129 131 uiwait(hfig) 130 132 if ishandle(hfig) … … 140 142 function titlebox_Callback(hObject,event) 141 143 refresh_GUI(hObject) 144 145 146 %------------------------------------------------------------------------ 147 % --- launched by refreshing the display figure 148 function refresh_GUI(hObject,InputFileName,FilterExt) 149 %------------------------------------------------------------------------ 150 if ~exist('InputFileName','var') 151 InputFileName=''; 152 end 153 if ~exist('FilterExt','var') 154 FilterExt='*'; 155 end 156 if strcmp(FilterExt,'uigetdir') 157 FilterExt='*'; 158 end 159 hfig=get(hObject,'parent'); 160 hlist=findobj(hfig,'tag','list');% find the list object 161 set(hlist,'BackgroundColor',[1 1 0]) 162 drawnow 163 htitlebox=findobj(hfig,'tag','titlebox'); 164 DirName=get(htitlebox,'String'); 165 hsort_option=findobj(hfig,'tag','sort_option'); 166 167 %% case of file browser opened by Status Display in the GUI series 168 if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series 169 hseries=findobj(allchild(0),'tag','series'); 170 hstatus=findobj(hseries,'tag','status'); 171 StatusData=get(hstatus,'UserData'); 172 TimeStart=0; 173 if isfield(StatusData,'TimeStart') 174 TimeStart=StatusData.TimeStart; 175 end 176 hlist=findobj(hfig,'tag','list'); 177 NbOutputFile=[]; 178 if isfield(StatusData,'NbOutputFile') 179 NbOutputFile=StatusData.NbOutputFile; 180 end 181 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content 182 183 % update the waitbar 184 hwaitbar=findobj(hfig,'tag','waitbar'); 185 if ~isempty(NbOutputFile) 186 BarPosition=get(hwaitbar,'Position'); 187 BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead 188 set(hwaitbar,'Position',BarPosition) 189 end 190 %% case of usual browser 191 else %use as usual browser 192 sort_option='name'; 193 if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) 194 sort_option='date'; 195 end 196 hcheck_date=findobj(hfig,'tag','check_date'); 197 ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content 198 end 199 if ~isempty(DirName) && isempty(ListFiles) 200 if isempty(regexp(DirName,'^http://', 'once'))%usual files 201 ListFiles='empty folder'; 202 else 203 ListFiles='address http:// not found'; 204 end 205 end 206 set(hlist,'String',ListFiles) 207 Value=[]; 208 if ~isempty(InputFileName) 209 Value=find(strcmp(InputFileName,ListFiles)); 210 end 211 if isempty(Value) 212 Value=1; 213 end 214 set(hlist,'Value',Value) 215 set(hlist,'BackgroundColor',[0.7 0.7 0.7]) 142 216 143 217 %------------------------------------------------------------------------ … … 158 232 list=get(hlist,'String'); 159 233 index=get(hlist,'Value'); 160 if ~isempty(regexp(list{index},'^\+/' ))234 if ~isempty(regexp(list{index},'^\+/', 'once')) 161 235 return % quit if a dir has been opened 162 236 end … … 167 241 SelectName=SelectName(1:ind_dot-1); 168 242 end 169 if isempty(regexp(DirName,'^http://' ))% if the input dir is not a web site (begins by http://)243 if isempty(regexp(DirName,'^http://', 'once'))% if the input dir is not a web site (begins by http://) 170 244 FullSelectName=fullfile(DirName,SelectName); 171 245 check_exist=exist(FullSelectName,'file'); … … 201 275 end 202 276 203 %------------------------------------------------------------------------ 204 % --- launched by refreshing the display figure 205 function refresh_GUI(hObject,InputFileName,FilterExt) 206 %------------------------------------------------------------------------ 207 if ~exist('InputFileName','var') 208 InputFileName=''; 209 end 210 if ~exist('FilterExt','var') 211 FilterExt='*'; 212 end 213 if strcmp(FilterExt,'uigetdir') 214 FilterExt='*'; 215 end 216 hfig=get(hObject,'parent'); 217 hlist=findobj(hfig,'tag','list');% find the list object 218 set(hlist,'BackgroundColor',[1 1 0]) 219 drawnow 220 htitlebox=findobj(hfig,'tag','titlebox'); 221 DirName=get(htitlebox,'String'); 222 hsort_option=findobj(hfig,'tag','sort_option'); 223 % use with GUI series 224 if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series 225 hseries=findobj(allchild(0),'tag','series'); 226 hstatus=findobj(hseries,'tag','status'); 227 StatusData=get(hstatus,'UserData'); 228 TimeStart=0; 229 if isfield(StatusData,'TimeStart') 230 TimeStart=StatusData.TimeStart; 231 end 232 hlist=findobj(hfig,'tag','list'); 233 testrecent=0; 234 NbOutputFile=[]; 235 if isfield(StatusData,'NbOutputFile') 236 NbOutputFile=StatusData.NbOutputFile; 237 NbOutputFile_str=num2str(NbOutputFile); 238 end 239 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content 240 241 % update the waitbar 242 hwaitbar=findobj(hfig,'tag','waitbar'); 243 if ~isempty(NbOutputFile) 244 BarPosition=get(hwaitbar,'Position'); 245 BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead 246 set(hwaitbar,'Position',BarPosition) 247 end 248 else %use as usual browser 249 sort_option='name'; 250 if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) 251 sort_option='date'; 252 end 253 hcheck_date=findobj(hfig,'tag','check_date'); 254 [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content 255 end 256 257 set(hlist,'String',ListFiles) 258 Value=[]; 259 if ~isempty(InputFileName) 260 Value=find(strcmp(InputFileName,ListFiles)); 261 end 262 if isempty(Value) 263 Value=1; 264 end 265 set(hlist,'Value',Value) 266 set(hlist,'BackgroundColor',[0.7 0.7 0.7]) 267 268 %------------------------------------------------------------------------ 277 278 %------------------------------------------------------------------------ 269 279 % --- launched by selecting an item on the file list 270 280 %------------------------------------------------------------------------ … … 282 292 283 293 284 %------------------------------------------------------------------------ 294 %------------------------------------------------------------------------ 285 295 % --- launched by selecting an item on the file list 286 296 function list_Callback(option,filter_ext,hObject,event) … … 288 298 hfig=get(hObject,'parent');%handle of the fig 289 299 set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action 290 300 drawnow 291 301 list=get(hObject,'String'); 292 302 index=get(hObject,'Value'); 293 303 294 htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name 304 htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name 295 305 DirName=get(htitlebox,'String'); 296 CheckSubDir=~isempty(regexp(list{index},'^\+' ));306 CheckSubDir=~isempty(regexp(list{index},'^\+', 'once')); 297 307 SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir 298 308 ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' … … 303 313 FullSelectName=fileparts(DirName); 304 314 else 305 if isempty(regexp(DirName,'^http://' ))% usual files315 if isempty(regexp(DirName,'^http://', 'once'))% usual files 306 316 FullSelectName=fullfile(DirName,SelectName); 307 317 else … … 321 331 end 322 332 hcheck_date=findobj(hfig,'tag','check_date'); 323 333 324 334 ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content 325 335 set(hObject,'Value',1) … … 330 340 set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end 331 341 332 %------------------------------------------------------------------------- 342 %------------------------------------------------------------------------- 333 343 % list the content of a directory 334 344 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) 335 345 %------------------------------------------------------------------------- 346 ListFiles={};%default 347 NumFiles=0; 336 348 ListStruct=dir_uvmat(DirName);% get structure of the current directory 337 349 if ~isstruct(ListStruct) 338 350 return 339 351 end 340 352 341 353 date_index=find(strcmp('datenum',fieldnames(ListStruct)));% find the index of the date displayin the list of fields 342 NumFiles=0; %default343 354 if numel(ListStruct)<1 % case of empty dir 344 ListFiles={};345 355 return 346 356 end 347 357 ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray 348 358 ListFiles=ListCells(1,:);%list of file names 349 index_dir= find(strcmp('isdir',fieldnames(ListStruct)));359 index_dir=strcmp('isdir',fieldnames(ListStruct)); 350 360 check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files 351 361 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display … … 362 372 check_dir=check_dir(check_keep); 363 373 end 364 check_emptydate=cellfun('isempty',ListCells(date_index,:));% = 1 if datenum undefined 365 ListCells(date_index, find(check_emptydate))={0}; %set to 0 the empty dates374 check_emptydate=cellfun('isempty',ListCells(date_index,:));% = 1 if datenum undefined 375 ListCells(date_index,check_emptydate)={0}; %set to 0 the empty dates 366 376 ListDates=cell2mat(ListCells(date_index,:));%list of numerical dates 367 377 if isnumeric(sort_option) … … 369 379 NumFiles=numel(find(~check_old&~check_dir)); 370 380 end 371 if ~isempty(find(~check_dir ))372 ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front381 if ~isempty(find(~check_dir, 1)) 382 ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front 373 383 end 374 384 375 385 if isnumeric(sort_option)|| strcmp(sort_option,'date') 376 [ tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list377 else 378 [ tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list386 [~,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list 387 else 388 [~,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list 379 389 end 380 390 ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file … … 447 457 function CheckImage=isimage(filename) 448 458 449 [ pp,name,ext]=fileparts(filename);459 [~,~,ext]=fileparts(filename); 450 460 CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.','')));
Note: See TracChangeset
for help on using the changeset viewer.