| 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';% use with the button 'Status Display' from the GUI 'series' |
|---|
| 44 | else |
|---|
| 45 | option='browser';% usual 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://', 'once'))%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 % files accessed on the web by Opendap |
|---|
| 71 | [InputDir,InputFileName]=fileparts(InputName); |
|---|
| 72 | end |
|---|
| 73 | end |
|---|
| 74 | |
|---|
| 75 | %% Display the browser figure |
|---|
| 76 | hfig=findobj(allchild(0),'tag',option);%look for existing browser fig |
|---|
| 77 | if isempty(hfig)% create the browser fig if it does not exist |
|---|
| 78 | set(0,'Unit','points') |
|---|
| 79 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
|---|
| 80 | Width=350;% fig width in points (1/72 inch) |
|---|
| 81 | Height=min(0.8*ScreenSize(4),500); |
|---|
| 82 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
|---|
| 83 | Bottom=ScreenSize(4)-Height-40; %put fig at top right |
|---|
| 84 | hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); |
|---|
| 85 | BackgroundColor=get(hfig,'Color'); |
|---|
| 86 | % text title |
|---|
| 87 | path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',... |
|---|
| 88 | 'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
|---|
| 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,... |
|---|
| 91 | 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path'); |
|---|
| 92 | % button for backward move in the directory tree |
|---|
| 93 | uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],... |
|---|
| 94 | 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward'); |
|---|
| 95 | home_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.14 0.77 0.2 0.05],... |
|---|
| 96 | 'String','Work dir','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir,'TooltipString','reach the current Matlab working directory'); |
|---|
| 97 | uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.36 0.77 0.2 0.05],'Callback',@refresh_GUI,... |
|---|
| 98 | 'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12); |
|---|
| 99 | uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.74 0.23 0.05],'tag','sort_option','Callback',@refresh_GUI,'Visible','on',... |
|---|
| 100 | 'String',{'sort name';'sort date'},'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''sort_option'': sort the files by names or dates'); |
|---|
| 101 | 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',... |
|---|
| 102 | 'FontUnits','points','FontSize',12,'TooltipString','''list'':current list of directories, marked by +/, and files'); |
|---|
| 103 | |
|---|
| 104 | OK_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.58 0.005 0.2 0.07],'BackgroundColor',[0 1 0],... |
|---|
| 105 | 'String','OK','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@(src,event)OK_Callback(option,FilterExt,src,event)); |
|---|
| 106 | close_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.78 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... |
|---|
| 107 | 'FontWeight','bold','FontUnits','points','FontSize',12); |
|---|
| 108 | if strcmp(option,'status_display') %put a run advancement display |
|---|
| 109 | set(hfig,'DeleteFcn',@(src,event)close(option,src,event)) |
|---|
| 110 | uicontrol('Style','frame','Units','normalized', 'Position', [0.02 0.85 0.9 0.04]); |
|---|
| 111 | uicontrol('Style','frame','Units','normalized', 'Position',[0.02 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); |
|---|
| 112 | delete(home_button) |
|---|
| 113 | set(OK_button,'String','Open') |
|---|
| 114 | set(close_button,'String','Close') |
|---|
| 115 | elseif strcmp(FilterExt,'uigetdir') %pick a directory |
|---|
| 116 | set(path_title,'String',title); %show the input title for path (directory) |
|---|
| 117 | set(OK_button,'String','Select') |
|---|
| 118 | set(close_button,'String','Cancel') |
|---|
| 119 | else %put a title and additional pushbuttons |
|---|
| 120 | uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.74 0.6 0.03],'BackgroundColor',BackgroundColor,... |
|---|
| 121 | 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
|---|
| 122 | uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,... |
|---|
| 123 | 'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates'); |
|---|
| 124 | set(OK_button,'String','Open') |
|---|
| 125 | set(close_button,'String','Cancel') |
|---|
| 126 | end |
|---|
| 127 | drawnow |
|---|
| 128 | end |
|---|
| 129 | refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir |
|---|
| 130 | if ~strcmp(option,'status_display') && strcmp(get(hfig,'Type'),'figure') |
|---|
| 131 | uiwait(hfig) |
|---|
| 132 | if ishandle(hfig) |
|---|
| 133 | htitlebox=findobj(hfig,'Tag','titlebox'); |
|---|
| 134 | fileinput=get(htitlebox,'String');% retrieve the input file selection |
|---|
| 135 | delete(hfig) |
|---|
| 136 | end |
|---|
| 137 | end |
|---|
| 138 | |
|---|
| 139 | %------------------------------------------------------------------------ |
|---|
| 140 | % --- launched by refreshing the display figure |
|---|
| 141 | %------------------------------------------------------------------------ |
|---|
| 142 | function titlebox_Callback(hObject,event) |
|---|
| 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]) |
|---|
| 216 | |
|---|
| 217 | %------------------------------------------------------------------------ |
|---|
| 218 | % --- launched by selecting OK (relevant for FilterExt='uigetdir') |
|---|
| 219 | %------------------------------------------------------------------------ |
|---|
| 220 | function OK_Callback(option,filter_ext,hObject,event) |
|---|
| 221 | set(hObject,'backgroundColor',[1 1 0])% indicate button activation |
|---|
| 222 | fig_struct=get(hObject,'parent'); |
|---|
| 223 | if isstruct(fig_struct);%recent Matlab |
|---|
| 224 | hfig=fig_struct.Number; |
|---|
| 225 | else |
|---|
| 226 | hfig=fig_struct; |
|---|
| 227 | end |
|---|
| 228 | htitlebox=findobj(hfig,'tag','titlebox'); % display the current dir name |
|---|
| 229 | DirName=get(htitlebox,'String'); |
|---|
| 230 | if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir |
|---|
| 231 | hlist=findobj(hfig,'Tag','list'); |
|---|
| 232 | list=get(hlist,'String'); |
|---|
| 233 | index=get(hlist,'Value'); |
|---|
| 234 | if ~isempty(regexp(list{index},'^\+/', 'once')) |
|---|
| 235 | return % quit if a dir has been opened |
|---|
| 236 | end |
|---|
| 237 | %SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
|---|
| 238 | SelectName=list{index}; |
|---|
| 239 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
|---|
| 240 | if ~isempty(ind_dot) |
|---|
| 241 | SelectName=SelectName(1:ind_dot-1); |
|---|
| 242 | end |
|---|
| 243 | if isempty(regexp(DirName,'^http://', 'once'))% if the input dir is not a web site (begins by http://) |
|---|
| 244 | FullSelectName=fullfile(DirName,SelectName); |
|---|
| 245 | check_exist=exist(FullSelectName,'file'); |
|---|
| 246 | else |
|---|
| 247 | FullSelectName=[DirName '/' SelectName]; |
|---|
| 248 | check_exist=1; |
|---|
| 249 | end |
|---|
| 250 | if check_exist |
|---|
| 251 | switch option |
|---|
| 252 | case 'browser' |
|---|
| 253 | set(htitlebox,'String',FullSelectName); |
|---|
| 254 | uiresume(hfig) |
|---|
| 255 | case 'status_display' |
|---|
| 256 | FileInfo=get_file_info(FullSelectName); |
|---|
| 257 | if strcmp(FileInfo.FileType,'txt') |
|---|
| 258 | edit(FullSelectName) |
|---|
| 259 | elseif strcmp(FileInfo.FileType,'xml') |
|---|
| 260 | editxml(FullSelectName) |
|---|
| 261 | elseif strcmp(FileInfo.FileType,'figure') |
|---|
| 262 | open(FullSelectName) |
|---|
| 263 | else |
|---|
| 264 | uvmat(FullSelectName); |
|---|
| 265 | end |
|---|
| 266 | end |
|---|
| 267 | end |
|---|
| 268 | end |
|---|
| 269 | set(hObject,'backgroundColor',[0 1 0])% indicate end button activatio |
|---|
| 270 | fig_struct=get(hObject,'parent'); |
|---|
| 271 | if isstruct(fig_struct)%recent Matlab |
|---|
| 272 | uiresume(fig_struct.Number) |
|---|
| 273 | else |
|---|
| 274 | uiresume(fig_struct) |
|---|
| 275 | end |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | %------------------------------------------------------------------------ |
|---|
| 279 | % --- launched by selecting an item on the file list |
|---|
| 280 | %------------------------------------------------------------------------ |
|---|
| 281 | function dates_Callback(hObject,event) |
|---|
| 282 | |
|---|
| 283 | hfig=get(hObject,'parent'); |
|---|
| 284 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 285 | if get(hObject,'Value') |
|---|
| 286 | set(hsort_option,'Visible','on') |
|---|
| 287 | set(hsort_option,'Value',2) |
|---|
| 288 | else |
|---|
| 289 | set(hsort_option,'Visible','off') |
|---|
| 290 | end |
|---|
| 291 | refresh_GUI(hObject,[]) |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | %------------------------------------------------------------------------ |
|---|
| 295 | % --- launched by selecting an item on the file list |
|---|
| 296 | function list_Callback(option,filter_ext,hObject,event) |
|---|
| 297 | %------------------------------------------------------------------------ |
|---|
| 298 | hfig=get(hObject,'parent');%handle of the fig |
|---|
| 299 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
|---|
| 300 | drawnow |
|---|
| 301 | list=get(hObject,'String'); |
|---|
| 302 | index=get(hObject,'Value'); |
|---|
| 303 | |
|---|
| 304 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
|---|
| 305 | DirName=get(htitlebox,'String'); |
|---|
| 306 | CheckSubDir=~isempty(regexp(list{index},'^\+', 'once')); |
|---|
| 307 | SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
|---|
| 308 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
|---|
| 309 | if ~isempty(ind_dot) |
|---|
| 310 | SelectName=SelectName(1:ind_dot-1); |
|---|
| 311 | end |
|---|
| 312 | if strcmp(SelectName,'..')% the upward dir option has been selected |
|---|
| 313 | FullSelectName=fileparts(DirName); |
|---|
| 314 | else |
|---|
| 315 | if isempty(regexp(DirName,'^http://', 'once'))% usual files |
|---|
| 316 | FullSelectName=fullfile(DirName,SelectName); |
|---|
| 317 | else |
|---|
| 318 | FullSelectName=[DirName '/' SelectName]; |
|---|
| 319 | end |
|---|
| 320 | end% end |
|---|
| 321 | % end |
|---|
| 322 | if CheckSubDir%exist(FullSelectName,'dir')% a directory has been selected |
|---|
| 323 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
|---|
| 324 | drawnow |
|---|
| 325 | hbackward=findobj(hfig,'Tag','backward'); |
|---|
| 326 | set(hbackward,'UserData',DirName); %store the current dir for future backward action |
|---|
| 327 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 328 | sort_option='name';%default |
|---|
| 329 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
|---|
| 330 | sort_option='date'; |
|---|
| 331 | end |
|---|
| 332 | hcheck_date=findobj(hfig,'tag','check_date'); |
|---|
| 333 | |
|---|
| 334 | ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content |
|---|
| 335 | set(hObject,'Value',1) |
|---|
| 336 | set(hObject,'String',ListFiles) |
|---|
| 337 | set(hObject,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 338 | set(htitlebox,'String',FullSelectName)% record the new dir name |
|---|
| 339 | end |
|---|
| 340 | set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end |
|---|
| 341 | |
|---|
| 342 | %------------------------------------------------------------------------- |
|---|
| 343 | % list the content of a directory |
|---|
| 344 | function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) |
|---|
| 345 | %------------------------------------------------------------------------- |
|---|
| 346 | ListFiles={};%default |
|---|
| 347 | NumFiles=0; |
|---|
| 348 | ListStruct=dir_uvmat(DirName);% get structure of the current directory |
|---|
| 349 | if ~isstruct(ListStruct) |
|---|
| 350 | return |
|---|
| 351 | end |
|---|
| 352 | |
|---|
| 353 | date_index=find(strcmp('datenum',fieldnames(ListStruct)));% find the index of the date displayin the list of fields |
|---|
| 354 | if numel(ListStruct)<1 % case of empty dir |
|---|
| 355 | return |
|---|
| 356 | end |
|---|
| 357 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
|---|
| 358 | ListFiles=ListCells(1,:);%list of file names |
|---|
| 359 | index_dir=strcmp('isdir',fieldnames(ListStruct)); |
|---|
| 360 | check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files |
|---|
| 361 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
|---|
| 362 | if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir') |
|---|
| 363 | if strcmp(filter_ext,'image') |
|---|
| 364 | check_keep=cellfun(@isimage,ListFiles) ; |
|---|
| 365 | elseif strcmp(filter_ext(1),'.') |
|---|
| 366 | ind_ext=regexp(ListFiles,[filter_ext '$']);%look for the input file extension |
|---|
| 367 | check_keep=~cellfun('isempty',ind_ext); |
|---|
| 368 | end |
|---|
| 369 | check_keep=check_keep|check_dir; |
|---|
| 370 | ListFiles=ListFiles(check_keep); |
|---|
| 371 | ListCells=ListCells(:,check_keep); |
|---|
| 372 | check_dir=check_dir(check_keep); |
|---|
| 373 | end |
|---|
| 374 | check_emptydate=cellfun('isempty',ListCells(date_index,:));% = 1 if datenum undefined |
|---|
| 375 | ListCells(date_index,check_emptydate)={0}; %set to 0 the empty dates |
|---|
| 376 | ListDates=cell2mat(ListCells(date_index,:));%list of numerical dates |
|---|
| 377 | if isnumeric(sort_option) |
|---|
| 378 | check_old=ListDates<sort_option-1;% -1 is put to account for a 1 s delay in the record of starting time |
|---|
| 379 | NumFiles=numel(find(~check_old&~check_dir)); |
|---|
| 380 | end |
|---|
| 381 | if ~isempty(find(~check_dir, 1)) |
|---|
| 382 | ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front |
|---|
| 383 | end |
|---|
| 384 | |
|---|
| 385 | if isnumeric(sort_option)|| strcmp(sort_option,'date') |
|---|
| 386 | [~,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 |
|---|
| 389 | end |
|---|
| 390 | ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file |
|---|
| 391 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
|---|
| 392 | check_keep=cellfun('isempty', cell_remove); |
|---|
| 393 | ListFiles=[{'+/..'} ListFiles(check_keep)]; |
|---|
| 394 | if check_date |
|---|
| 395 | ListDateString=ListCells(3,:);%list of file dates |
|---|
| 396 | if isnumeric(sort_option) |
|---|
| 397 | ListDateString(check_old)={'--OLD--'}; |
|---|
| 398 | end |
|---|
| 399 | ListDateString(check_dir)={''}; |
|---|
| 400 | ListDateString=ListDateString(index_sort);% sort the corresponding dates |
|---|
| 401 | ListDateString=[{''} ListDateString(check_keep)]; |
|---|
| 402 | ListFiles=[ListFiles; ListDateString]; |
|---|
| 403 | ListFiles=cell2tab(ListFiles','...'); |
|---|
| 404 | end |
|---|
| 405 | |
|---|
| 406 | %------------------------------------------------------------------------ |
|---|
| 407 | % --- launched by selecting home |
|---|
| 408 | function home_dir(hObject,event) |
|---|
| 409 | %------------------------------------------------------------------------ |
|---|
| 410 | DirName=pwd; |
|---|
| 411 | hfig=get(hObject,'parent'); |
|---|
| 412 | hlist=findobj(hfig,'tag','list');% find the list object |
|---|
| 413 | set(hlist,'BackgroundColor',[1 1 0]) |
|---|
| 414 | drawnow |
|---|
| 415 | sort_option='name';%default |
|---|
| 416 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 417 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
|---|
| 418 | sort_option='date'; |
|---|
| 419 | end |
|---|
| 420 | hcheck_date=findobj(hfig,'tag','check_date'); |
|---|
| 421 | ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content |
|---|
| 422 | htitlebox=findobj(hfig,'Tag','titlebox'); |
|---|
| 423 | set(htitlebox,'String',DirName)% record the new dir name |
|---|
| 424 | set(hlist,'Value',1) |
|---|
| 425 | set(hlist,'String',ListFiles) |
|---|
| 426 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| 427 | %------------------------------------------------------------------------ |
|---|
| 428 | |
|---|
| 429 | %------------------------------------------------------------------------ |
|---|
| 430 | % --- launched by pressing the backward (<--) button |
|---|
| 431 | function backward(hObject,event) |
|---|
| 432 | %------------------------------------------------------------------------ |
|---|
| 433 | PrevDir=get(hObject,'UserData'); |
|---|
| 434 | if ~isempty(PrevDir) |
|---|
| 435 | hfig=get(hObject,'parent'); |
|---|
| 436 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
|---|
| 437 | set(htitlebox,'String',PrevDir) |
|---|
| 438 | refresh_GUI(findobj(hfig,'Tag','refresh')) |
|---|
| 439 | end |
|---|
| 440 | |
|---|
| 441 | %------------------------------------------------------------------------- |
|---|
| 442 | % --- launched by deleting the status figure (only used in mode series status') |
|---|
| 443 | %------------------------------------------------------------------------- |
|---|
| 444 | function close(option,hObject, eventdata) |
|---|
| 445 | |
|---|
| 446 | if strcmp(option,'status_display') |
|---|
| 447 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 448 | hstatus=findobj(hseries,'Tag','status'); |
|---|
| 449 | set(hstatus,'value',0) %reset the status uicontrol in the GUI series |
|---|
| 450 | set(hstatus,'BackgroundColor',[0 1 0]) |
|---|
| 451 | end |
|---|
| 452 | delete(gcbf) |
|---|
| 453 | |
|---|
| 454 | %------------------------------------------------------------------------- |
|---|
| 455 | % --- check whether a file is has an image name extension |
|---|
| 456 | %------------------------------------------------------------------------- |
|---|
| 457 | function CheckImage=isimage(filename) |
|---|
| 458 | |
|---|
| 459 | [~,~,ext]=fileparts(filename); |
|---|
| 460 | CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.',''))); |
|---|