1 | %'uigetfile_uvmat': browser, and display of directories, faster than the Matlab fct uigetfile |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % fileinput=uigetfile_uvmat(title,InputName,FilterExt) |
---|
4 | % |
---|
5 | % OUTPUT: |
---|
6 | % fileinput: detected file name, including path |
---|
7 | % |
---|
8 | % INPUT: |
---|
9 | % title: = displayed title, |
---|
10 | % if title='status_display': display advancement of a series calculation, |
---|
11 | % else uigetfile_uvmat used as browser. |
---|
12 | % InputName: initial file or directory selection for the browser |
---|
13 | % FilterExt: string to filter the file display: |
---|
14 | % '*' (default) all files displayed |
---|
15 | % 'image': any image or movie |
---|
16 | % '.ext': display only files with extension '.ext' |
---|
17 | % 'uigetdir'; browser used to select a directory (like the matlab browser 'uigetdir') |
---|
18 | |
---|
19 | %======================================================================= |
---|
20 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
21 | % http://www.legi.grenoble-inp.fr |
---|
22 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
23 | % |
---|
24 | % This file is part of the toolbox UVMAT. |
---|
25 | % |
---|
26 | % UVMAT is free software; you can redistribute it and/or modify |
---|
27 | % it under the terms of the GNU General Public License as published |
---|
28 | % by the Free Software Foundation; either version 2 of the license, |
---|
29 | % or (at your option) any later version. |
---|
30 | % |
---|
31 | % UVMAT is distributed in the hope that it will be useful, |
---|
32 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
33 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
34 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
35 | %======================================================================= |
---|
36 | |
---|
37 | function fileinput=uigetfile_uvmat(title,InputName,FilterExt) |
---|
38 | if ~exist('FilterExt','var') |
---|
39 | FilterExt='*'; |
---|
40 | end |
---|
41 | fileinput=''; %default file selection |
---|
42 | if strcmp(title,'status_display') |
---|
43 | option='status_display'; |
---|
44 | else |
---|
45 | option='browser'; |
---|
46 | end |
---|
47 | InputDir=pwd;%look in the current work directory if the input file does not exist |
---|
48 | InputFileName='';%default |
---|
49 | if ischar(InputName) |
---|
50 | if isempty(regexp(InputName,'^http://'))%usual files |
---|
51 | if exist(InputName,'dir') |
---|
52 | InputDir=InputName; |
---|
53 | InputFileName=''; |
---|
54 | elseif exist(InputName,'file') |
---|
55 | [InputDir,InputFileName,Ext]=fileparts(InputName); |
---|
56 | if isempty(InputFileName)% if InputName is alr2eady the root |
---|
57 | InputFileName=InputDir; |
---|
58 | if ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems |
---|
59 | % InputDir=[InputDir '\'];% append '\' for a correct action of dir |
---|
60 | InputFileName=[InputFileName '\']; |
---|
61 | end |
---|
62 | end |
---|
63 | if isdir(InputName) |
---|
64 | InputFileName=['+/' InputFileName Ext]; |
---|
65 | end |
---|
66 | end |
---|
67 | if ismember(computer,{'PCWIN','PCWIN64'})%case of Windows systems |
---|
68 | InputDir=[InputDir '\'];% append '\' for a correct action of dir |
---|
69 | end |
---|
70 | else |
---|
71 | [InputDir,InputFileName,Ext]=fileparts(InputName); |
---|
72 | end |
---|
73 | end |
---|
74 | |
---|
75 | hfig=findobj(allchild(0),'tag',option);%look for existing browser fig |
---|
76 | if isempty(hfig)% create the browser fig if it does not exist |
---|
77 | set(0,'Unit','points') |
---|
78 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
---|
79 | Width=350;% fig width in points (1/72 inch) |
---|
80 | Height=min(0.8*ScreenSize(4),500); |
---|
81 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
---|
82 | Bottom=ScreenSize(4)-Height-40; %put fig at top right |
---|
83 | hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); |
---|
84 | BackgroundColor=get(hfig,'Color'); |
---|
85 | path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',... |
---|
86 | '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,... |
---|
88 | 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path'); |
---|
89 | uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],... |
---|
90 | 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward'); |
---|
91 | home_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.14 0.77 0.2 0.05],... |
---|
92 | 'String','Work dir','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir,'TooltipString','reach the current Matlab working directory'); |
---|
93 | uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.36 0.77 0.2 0.05],'Callback',@refresh_GUI,... |
---|
94 | 'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12); |
---|
95 | uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.74 0.23 0.05],'tag','sort_option','Callback',@refresh_GUI,'Visible','on',... |
---|
96 | 'String',{'sort name';'sort date'},'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''sort_option'': sort the files by names or dates'); |
---|
97 | uicontrol('Style','listbox','Units','normalized', 'Position',[0.02 0.08 0.96 0.66], 'Callback', @(src,event)list_Callback(option,FilterExt,src,event),'tag','list',... |
---|
98 | 'FontUnits','points','FontSize',12,'TooltipString','''list'':current list of directories, marked by +/, and files'); |
---|
99 | |
---|
100 | OK_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.58 0.005 0.2 0.07],'BackgroundColor',[0 1 0],... |
---|
101 | 'String','OK','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@(src,event)OK_Callback(option,FilterExt,src,event)); |
---|
102 | close_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.78 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... |
---|
103 | 'FontWeight','bold','FontUnits','points','FontSize',12); |
---|
104 | if strcmp(option,'status_display') %put a run advancement display |
---|
105 | set(hfig,'DeleteFcn',@(src,event)close(option,src,event)) |
---|
106 | uicontrol('Style','frame','Units','normalized', 'Position', [0.02 0.85 0.9 0.04]); |
---|
107 | uicontrol('Style','frame','Units','normalized', 'Position',[0.02 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); |
---|
108 | delete(home_button) |
---|
109 | set(OK_button,'String','Open') |
---|
110 | set(close_button,'String','Close') |
---|
111 | elseif strcmp(FilterExt,'uigetdir') %pick a directory |
---|
112 | set(path_title,'String',title); %show the input title for path (directory) |
---|
113 | set(OK_button,'String','Select') |
---|
114 | set(close_button,'String','Cancel') |
---|
115 | else %put a title and additional pushbuttons |
---|
116 | uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.74 0.6 0.03],'BackgroundColor',BackgroundColor,... |
---|
117 | 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
---|
118 | uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,... |
---|
119 | '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 | set(OK_button,'String','Open') |
---|
123 | set(close_button,'String','Cancel') |
---|
124 | end |
---|
125 | drawnow |
---|
126 | end |
---|
127 | refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir |
---|
128 | if ~strcmp(option,'status_display') |
---|
129 | uiwait(hfig) |
---|
130 | if ishandle(hfig) |
---|
131 | htitlebox=findobj(hfig,'Tag','titlebox'); |
---|
132 | fileinput=get(htitlebox,'String');% retrieve the input file selection |
---|
133 | delete(hfig) |
---|
134 | end |
---|
135 | end |
---|
136 | |
---|
137 | %------------------------------------------------------------------------ |
---|
138 | % --- launched by refreshing the display figure |
---|
139 | %------------------------------------------------------------------------ |
---|
140 | function titlebox_Callback(hObject,event) |
---|
141 | refresh_GUI(hObject) |
---|
142 | |
---|
143 | %------------------------------------------------------------------------ |
---|
144 | % --- launched by selecting OK (relevant for FilterExt='uigetdir') |
---|
145 | %------------------------------------------------------------------------ |
---|
146 | function OK_Callback(option,filter_ext,hObject,event) |
---|
147 | set(hObject,'backgroundColor',[1 1 0])% indicate button activation |
---|
148 | fig_struct=get(hObject,'parent'); |
---|
149 | if isstruct(fig_struct);%recent Matlab |
---|
150 | hfig=fig_struct.Number; |
---|
151 | else |
---|
152 | hfig=fig_struct; |
---|
153 | end |
---|
154 | htitlebox=findobj(hfig,'tag','titlebox'); % display the current dir name |
---|
155 | DirName=get(htitlebox,'String'); |
---|
156 | if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir |
---|
157 | hlist=findobj(hfig,'Tag','list'); |
---|
158 | list=get(hlist,'String'); |
---|
159 | index=get(hlist,'Value'); |
---|
160 | if ~isempty(regexp(list{index},'^\+/')) |
---|
161 | return % quit if a dir has been opened |
---|
162 | end |
---|
163 | %SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
---|
164 | SelectName=list{index}; |
---|
165 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
---|
166 | if ~isempty(ind_dot) |
---|
167 | SelectName=SelectName(1:ind_dot-1); |
---|
168 | end |
---|
169 | if isempty(regexp(DirName,'^http://'))% if the input dir is not a web site (begins by http://) |
---|
170 | FullSelectName=fullfile(DirName,SelectName); |
---|
171 | check_exist=exist(FullSelectName,'file'); |
---|
172 | else |
---|
173 | FullSelectName=[DirName '/' SelectName]; |
---|
174 | check_exist=1; |
---|
175 | end |
---|
176 | if check_exist |
---|
177 | switch option |
---|
178 | case 'browser' |
---|
179 | set(htitlebox,'String',FullSelectName); |
---|
180 | uiresume(hfig) |
---|
181 | case 'status_display' |
---|
182 | FileInfo=get_file_info(FullSelectName); |
---|
183 | if strcmp(FileInfo.FileType,'txt') |
---|
184 | edit(FullSelectName) |
---|
185 | elseif strcmp(FileInfo.FileType,'xml') |
---|
186 | editxml(FullSelectName) |
---|
187 | elseif strcmp(FileInfo.FileType,'figure') |
---|
188 | open(FullSelectName) |
---|
189 | else |
---|
190 | uvmat(FullSelectName); |
---|
191 | end |
---|
192 | end |
---|
193 | end |
---|
194 | end |
---|
195 | set(hObject,'backgroundColor',[0 1 0])% indicate end button activatio |
---|
196 | fig_struct=get(hObject,'parent'); |
---|
197 | if isstruct(fig_struct)%recent Matlab |
---|
198 | uiresume(fig_struct.Number) |
---|
199 | else |
---|
200 | uiresume(fig_struct) |
---|
201 | end |
---|
202 | |
---|
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 | %------------------------------------------------------------------------ |
---|
269 | % --- launched by selecting an item on the file list |
---|
270 | %------------------------------------------------------------------------ |
---|
271 | function dates_Callback(hObject,event) |
---|
272 | |
---|
273 | hfig=get(hObject,'parent'); |
---|
274 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
275 | if get(hObject,'Value') |
---|
276 | set(hsort_option,'Visible','on') |
---|
277 | set(hsort_option,'Value',2) |
---|
278 | else |
---|
279 | set(hsort_option,'Visible','off') |
---|
280 | end |
---|
281 | refresh_GUI(hObject,[]) |
---|
282 | |
---|
283 | |
---|
284 | %------------------------------------------------------------------------ |
---|
285 | % --- launched by selecting an item on the file list |
---|
286 | function list_Callback(option,filter_ext,hObject,event) |
---|
287 | %------------------------------------------------------------------------ |
---|
288 | hfig=get(hObject,'parent');%handle of the fig |
---|
289 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
---|
290 | drawnow |
---|
291 | list=get(hObject,'String'); |
---|
292 | index=get(hObject,'Value'); |
---|
293 | |
---|
294 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
295 | DirName=get(htitlebox,'String'); |
---|
296 | CheckSubDir=~isempty(regexp(list{index},'^\+')); |
---|
297 | SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
---|
298 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
---|
299 | if ~isempty(ind_dot) |
---|
300 | SelectName=SelectName(1:ind_dot-1); |
---|
301 | end |
---|
302 | if strcmp(SelectName,'..')% the upward dir option has been selected |
---|
303 | FullSelectName=fileparts(DirName); |
---|
304 | else |
---|
305 | if isempty(regexp(DirName,'^http://'))% usual files |
---|
306 | FullSelectName=fullfile(DirName,SelectName); |
---|
307 | else |
---|
308 | FullSelectName=[DirName '/' SelectName]; |
---|
309 | end |
---|
310 | end% end |
---|
311 | % end |
---|
312 | if CheckSubDir%exist(FullSelectName,'dir')% a directory has been selected |
---|
313 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
---|
314 | drawnow |
---|
315 | hbackward=findobj(hfig,'Tag','backward'); |
---|
316 | set(hbackward,'UserData',DirName); %store the current dir for future backward action |
---|
317 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
318 | sort_option='name';%default |
---|
319 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
---|
320 | sort_option='date'; |
---|
321 | end |
---|
322 | hcheck_date=findobj(hfig,'tag','check_date'); |
---|
323 | |
---|
324 | ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content |
---|
325 | set(hObject,'Value',1) |
---|
326 | set(hObject,'String',ListFiles) |
---|
327 | set(hObject,'BackgroundColor',[0.7 0.7 0.7]) |
---|
328 | set(htitlebox,'String',FullSelectName)% record the new dir name |
---|
329 | end |
---|
330 | set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end |
---|
331 | |
---|
332 | %------------------------------------------------------------------------- |
---|
333 | % list the content of a directory |
---|
334 | function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) |
---|
335 | %------------------------------------------------------------------------- |
---|
336 | ListStruct=dir_uvmat(DirName);% get structure of the current directory |
---|
337 | if ~isstruct(ListStruct) |
---|
338 | return |
---|
339 | end |
---|
340 | |
---|
341 | date_index=find(strcmp('datenum',fieldnames(ListStruct)));% find the index of the date displayin the list of fields |
---|
342 | NumFiles=0; %default |
---|
343 | if numel(ListStruct)<1 % case of empty dir |
---|
344 | ListFiles={}; |
---|
345 | return |
---|
346 | end |
---|
347 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
---|
348 | ListFiles=ListCells(1,:);%list of file names |
---|
349 | index_dir=find(strcmp('isdir',fieldnames(ListStruct))); |
---|
350 | check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files |
---|
351 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
---|
352 | if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir') |
---|
353 | if strcmp(filter_ext,'image') |
---|
354 | check_keep=cellfun(@isimage,ListFiles) ; |
---|
355 | elseif strcmp(filter_ext(1),'.') |
---|
356 | ind_ext=regexp(ListFiles,[filter_ext '$']);%look for the input file extension |
---|
357 | check_keep=~cellfun('isempty',ind_ext); |
---|
358 | end |
---|
359 | check_keep=check_keep|check_dir; |
---|
360 | ListFiles=ListFiles(check_keep); |
---|
361 | ListCells=ListCells(:,check_keep); |
---|
362 | check_dir=check_dir(check_keep); |
---|
363 | 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 dates |
---|
366 | ListDates=cell2mat(ListCells(date_index,:));%list of numerical dates |
---|
367 | if isnumeric(sort_option) |
---|
368 | check_old=ListDates<sort_option-1;% -1 is put to account for a 1 s delay in the record of starting time |
---|
369 | NumFiles=numel(find(~check_old&~check_dir)); |
---|
370 | end |
---|
371 | if ~isempty(find(~check_dir)) |
---|
372 | ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front |
---|
373 | end |
---|
374 | |
---|
375 | 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 list |
---|
377 | else |
---|
378 | [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list |
---|
379 | end |
---|
380 | ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file |
---|
381 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
382 | check_keep=cellfun('isempty', cell_remove); |
---|
383 | ListFiles=[{'+/..'} ListFiles(check_keep)]; |
---|
384 | if check_date |
---|
385 | ListDateString=ListCells(3,:);%list of file dates |
---|
386 | if isnumeric(sort_option) |
---|
387 | ListDateString(check_old)={'--OLD--'}; |
---|
388 | end |
---|
389 | ListDateString(check_dir)={''}; |
---|
390 | ListDateString=ListDateString(index_sort);% sort the corresponding dates |
---|
391 | ListDateString=[{''} ListDateString(check_keep)]; |
---|
392 | ListFiles=[ListFiles; ListDateString]; |
---|
393 | ListFiles=cell2tab(ListFiles','...'); |
---|
394 | end |
---|
395 | |
---|
396 | %------------------------------------------------------------------------ |
---|
397 | % --- launched by selecting home |
---|
398 | function home_dir(hObject,event) |
---|
399 | %------------------------------------------------------------------------ |
---|
400 | DirName=pwd; |
---|
401 | hfig=get(hObject,'parent'); |
---|
402 | hlist=findobj(hfig,'tag','list');% find the list object |
---|
403 | set(hlist,'BackgroundColor',[1 1 0]) |
---|
404 | drawnow |
---|
405 | sort_option='name';%default |
---|
406 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
407 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
---|
408 | sort_option='date'; |
---|
409 | end |
---|
410 | hcheck_date=findobj(hfig,'tag','check_date'); |
---|
411 | ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content |
---|
412 | htitlebox=findobj(hfig,'Tag','titlebox'); |
---|
413 | set(htitlebox,'String',DirName)% record the new dir name |
---|
414 | set(hlist,'Value',1) |
---|
415 | set(hlist,'String',ListFiles) |
---|
416 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
---|
417 | %------------------------------------------------------------------------ |
---|
418 | |
---|
419 | %------------------------------------------------------------------------ |
---|
420 | % --- launched by pressing the backward (<--) button |
---|
421 | function backward(hObject,event) |
---|
422 | %------------------------------------------------------------------------ |
---|
423 | PrevDir=get(hObject,'UserData'); |
---|
424 | if ~isempty(PrevDir) |
---|
425 | hfig=get(hObject,'parent'); |
---|
426 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
427 | set(htitlebox,'String',PrevDir) |
---|
428 | refresh_GUI(findobj(hfig,'Tag','refresh')) |
---|
429 | end |
---|
430 | |
---|
431 | %------------------------------------------------------------------------- |
---|
432 | % --- launched by deleting the status figure (only used in mode series status') |
---|
433 | %------------------------------------------------------------------------- |
---|
434 | function close(option,hObject, eventdata) |
---|
435 | |
---|
436 | if strcmp(option,'status_display') |
---|
437 | hseries=findobj(allchild(0),'Tag','series'); |
---|
438 | hstatus=findobj(hseries,'Tag','status'); |
---|
439 | set(hstatus,'value',0) %reset the status uicontrol in the GUI series |
---|
440 | set(hstatus,'BackgroundColor',[0 1 0]) |
---|
441 | end |
---|
442 | delete(gcbf) |
---|
443 | |
---|
444 | %------------------------------------------------------------------------- |
---|
445 | % --- check whether a file is has an image name extension |
---|
446 | %------------------------------------------------------------------------- |
---|
447 | function CheckImage=isimage(filename) |
---|
448 | |
---|
449 | [pp,name,ext]=fileparts(filename); |
---|
450 | CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.',''))); |
---|