[606] | 1 | %'uigetfile_uvmat': browser faster than the Matlab fct uigetfile |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % hfig=uigetfile_uvmat(OutputDir,option) |
---|
| 4 | % |
---|
| 5 | % OUTPUT: |
---|
[609] | 6 | % fileinput: detected file name, including path |
---|
[606] | 7 | % |
---|
| 8 | % INPUT: |
---|
[609] | 9 | % title: = displayed title, 'status': display advancement of a series calculation |
---|
[606] | 10 | % InputDir: directory to browse at first display |
---|
| 11 | |
---|
[641] | 12 | function fileinput=uigetfile_uvmat(title,InputName,FilterExt) |
---|
| 13 | if ~exist('FilterExt','var') |
---|
| 14 | FilterExt='*'; |
---|
| 15 | end |
---|
[609] | 16 | fileinput=''; %default file selection |
---|
[610] | 17 | if strcmp(title,'status_display') |
---|
| 18 | option='status_display'; |
---|
[609] | 19 | else |
---|
| 20 | option='browser'; |
---|
[606] | 21 | end |
---|
[615] | 22 | InputDir=pwd;%look in the current work directory if the input file does not exist |
---|
| 23 | InputFileName='';%default |
---|
| 24 | if ischar(InputName) |
---|
| 25 | if exist(InputName,'dir') |
---|
| 26 | InputDir=InputName; |
---|
| 27 | InputFileName=''; |
---|
| 28 | elseif exist(InputName,'file') |
---|
| 29 | [InputDir,InputFileName,Ext]=fileparts(InputName); |
---|
| 30 | if isempty(InputFileName)% if InputName is already the root |
---|
| 31 | InputFileName=InputDir; |
---|
| 32 | if ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems |
---|
| 33 | InputDir=[InputDir '\'];% append '\' for a correct action of dir |
---|
| 34 | InputFileName=[InputFileName '\']; |
---|
| 35 | end |
---|
[610] | 36 | end |
---|
[615] | 37 | if isdir(InputName) |
---|
| 38 | InputFileName=['+/' InputFileName Ext]; |
---|
| 39 | end |
---|
[610] | 40 | end |
---|
[609] | 41 | end |
---|
| 42 | hfig=findobj(allchild(0),'tag',option); |
---|
[606] | 43 | if isempty(hfig) |
---|
[609] | 44 | set(0,'Unit','points') |
---|
[606] | 45 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
---|
[609] | 46 | Width=350;% fig width in points (1/72 inch) |
---|
| 47 | Height=min(0.8*ScreenSize(4),500); |
---|
| 48 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
---|
| 49 | Bottom=ScreenSize(4)-Height-40; %put fig at top right |
---|
| 50 | hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); |
---|
[611] | 51 | BackgroundColor=get(hfig,'Color'); |
---|
| 52 | uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.97 0.5 0.03],'BackgroundColor',BackgroundColor,... |
---|
| 53 | 'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
---|
[615] | 54 | uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.89 0.9 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],'Callback',@titlebox_Callback,... |
---|
[611] | 55 | 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold'); |
---|
[612] | 56 | uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.75 0.1 0.07],... |
---|
| 57 | 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward); |
---|
| 58 | uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.75 0.2 0.04],'tag','check_date','Callback',@dates_Callback,... |
---|
| 59 | 'String','dates','FontUnits','points','FontSize',12,'FontWeight','bold'); |
---|
| 60 | uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... |
---|
| 61 | 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); |
---|
| 62 | uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',... |
---|
| 63 | 'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold'); |
---|
[641] | 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',... |
---|
[609] | 65 | 'FontUnits','points','FontSize',12); |
---|
[611] | 66 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... |
---|
[609] | 67 | 'String','Close','FontWeight','bold','FontUnits','points','FontSize',12); |
---|
[611] | 68 | uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.1 0.005 0.2 0.07],'Callback',@refresh_GUI,... |
---|
[609] | 69 | 'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12); |
---|
[606] | 70 | %set(hrefresh,'UserData',StatusData) |
---|
[610] | 71 | if strcmp(option,'status_display') %put a run advancement display |
---|
[635] | 72 | set(hfig,'DeleteFcn',@(src,event)close(option,src,event)) |
---|
| 73 | uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.85 0.9 0.04]); |
---|
| 74 | uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); |
---|
| 75 | |
---|
[609] | 76 | else %put a title and additional pushbuttons |
---|
[612] | 77 | uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.75 0.6 0.03],'BackgroundColor',BackgroundColor,... |
---|
[609] | 78 | 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
---|
[612] | 79 | |
---|
[611] | 80 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.005 0.2 0.07],... |
---|
[609] | 81 | 'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir); |
---|
[606] | 82 | end |
---|
| 83 | drawnow |
---|
| 84 | end |
---|
[641] | 85 | refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir |
---|
[610] | 86 | if ~strcmp(option,'status_display') |
---|
[609] | 87 | uiwait(hfig) |
---|
[620] | 88 | if ishandle(hfig) |
---|
[611] | 89 | htitlebox=findobj(hfig,'Tag','titlebox'); |
---|
| 90 | fileinput=get(htitlebox,'String');% retrieve the input file selection |
---|
[610] | 91 | delete(hfig) |
---|
[620] | 92 | end |
---|
[609] | 93 | end |
---|
| 94 | |
---|
[615] | 95 | %------------------------------------------------------------------------ |
---|
| 96 | % --- launched by refreshing the display figure |
---|
| 97 | function titlebox_Callback(hObject,event) |
---|
| 98 | refresh_GUI(hObject) |
---|
| 99 | %------------------------------------------------------------------------ |
---|
[610] | 100 | |
---|
[606] | 101 | %------------------------------------------------------------------------ |
---|
[610] | 102 | % --- launched by refreshing the display figure |
---|
[641] | 103 | function refresh_GUI(hObject,InputFileName,FilterExt) |
---|
[610] | 104 | %------------------------------------------------------------------------ |
---|
| 105 | if ~exist('InputFileName','var') |
---|
| 106 | InputFileName=''; |
---|
| 107 | end |
---|
| 108 | hfig=get(hObject,'parent'); |
---|
[613] | 109 | hlist=findobj(hfig,'tag','list');% find the list object |
---|
| 110 | set(hlist,'BackgroundColor',[1 1 0]) |
---|
| 111 | drawnow |
---|
[611] | 112 | htitlebox=findobj(hfig,'tag','titlebox'); |
---|
| 113 | DirName=get(htitlebox,'String'); |
---|
[612] | 114 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
[635] | 115 | if strcmp(get(hfig,'Tag'),'status_display') |
---|
[610] | 116 | hseries=findobj(allchild(0),'tag','series'); |
---|
[635] | 117 | hstatus=findobj(hseries,'tag','status'); |
---|
[610] | 118 | StatusData=get(hstatus,'UserData'); |
---|
| 119 | TimeStart=0; |
---|
| 120 | if isfield(StatusData,'TimeStart') |
---|
| 121 | TimeStart=StatusData.TimeStart; |
---|
[635] | 122 | end |
---|
[610] | 123 | hlist=findobj(hfig,'tag','list'); |
---|
[635] | 124 | testrecent=0; |
---|
[610] | 125 | NbOutputFile=[]; |
---|
[635] | 126 | if isfield(StatusData,'NbOutputFile') |
---|
| 127 | NbOutputFile=StatusData.NbOutputFile; |
---|
| 128 | NbOutputFile_str=num2str(NbOutputFile); |
---|
[610] | 129 | end |
---|
[644] | 130 | [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content |
---|
[610] | 131 | |
---|
| 132 | %% update the waitbar |
---|
| 133 | hwaitbar=findobj(hfig,'tag','waitbar'); |
---|
| 134 | if ~isempty(NbOutputFile) |
---|
| 135 | BarPosition=get(hwaitbar,'Position'); |
---|
[635] | 136 | BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead |
---|
[610] | 137 | set(hwaitbar,'Position',BarPosition) |
---|
| 138 | end |
---|
[635] | 139 | else |
---|
| 140 | sort_option='name'; |
---|
| 141 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
---|
| 142 | sort_option='date'; |
---|
| 143 | end |
---|
| 144 | hcheck_date=findobj(hfig,'tag','check_date'); |
---|
[641] | 145 | [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content |
---|
[610] | 146 | end |
---|
| 147 | |
---|
[635] | 148 | set(hlist,'String',ListFiles) |
---|
| 149 | Value=[]; |
---|
| 150 | if ~isempty(InputFileName) |
---|
| 151 | Value=find(strcmp(InputFileName,ListFiles)); |
---|
| 152 | end |
---|
| 153 | if isempty(Value) |
---|
| 154 | Value=1; |
---|
| 155 | end |
---|
| 156 | set(hlist,'Value',Value) |
---|
| 157 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
---|
[610] | 158 | %------------------------------------------------------------------------ |
---|
[609] | 159 | % --- launched by selecting an item on the file list |
---|
[612] | 160 | function dates_Callback(hObject,event) |
---|
[606] | 161 | %------------------------------------------------------------------------ |
---|
[612] | 162 | hfig=get(hObject,'parent'); |
---|
| 163 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
| 164 | if get(hObject,'Value') |
---|
| 165 | set(hsort_option,'Visible','on') |
---|
| 166 | set(hsort_option,'Value',2) |
---|
| 167 | else |
---|
| 168 | set(hsort_option,'Visible','off') |
---|
| 169 | end |
---|
| 170 | refresh_GUI(hObject,[]) |
---|
| 171 | |
---|
| 172 | %------------------------------------------------------------------------ |
---|
| 173 | % --- launched by selecting an item on the file list |
---|
[641] | 174 | function list_Callback(option,filter_ext,hObject,event) |
---|
[612] | 175 | %------------------------------------------------------------------------ |
---|
[617] | 176 | hfig=get(hObject,'parent');%handle of the fig |
---|
| 177 | % if ~strcmp(get(hfig,'SelectionType'),'open') |
---|
| 178 | % return %select double click |
---|
| 179 | % end |
---|
| 180 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
---|
[615] | 181 | drawnow |
---|
[606] | 182 | list=get(hObject,'String'); |
---|
| 183 | index=get(hObject,'Value'); |
---|
[617] | 184 | |
---|
[611] | 185 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
| 186 | DirName=get(htitlebox,'String'); |
---|
[609] | 187 | SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
---|
[612] | 188 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
---|
| 189 | if ~isempty(ind_dot) |
---|
| 190 | SelectName=SelectName(1:ind_dot-1); |
---|
| 191 | end |
---|
[609] | 192 | if strcmp(SelectName,'..')% the upward dir option has been selected |
---|
[606] | 193 | FullSelectName=fileparts(DirName); |
---|
| 194 | else |
---|
[609] | 195 | FullSelectName=fullfile(DirName,SelectName); |
---|
[606] | 196 | end |
---|
| 197 | if exist(FullSelectName,'dir')% a directory has been selected |
---|
[612] | 198 | % ListFiles=dir(FullSelectName); |
---|
| 199 | % ListDisplay=cell(numel(ListFiles),1); |
---|
| 200 | % for ilist=2:numel(ListDisplay)% suppress the first line '.' |
---|
| 201 | % ListDisplay{ilist-1}=ListFiles(ilist).name; |
---|
| 202 | % end |
---|
| 203 | % set(hObject,'Value',1) |
---|
| 204 | % set(hObject,'String',ListDisplay) |
---|
| 205 | % if strcmp(selectname,'..') |
---|
| 206 | % FullSelectName=fileparts(fileparts(FullSelectName)); |
---|
| 207 | % end |
---|
[613] | 208 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
---|
| 209 | drawnow |
---|
[609] | 210 | hbackward=findobj(hfig,'Tag','backward'); |
---|
| 211 | set(hbackward,'UserData',DirName); %store the current dir for future backward action |
---|
[612] | 212 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
| 213 | sort_option='name';%default |
---|
| 214 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
---|
| 215 | sort_option='date'; |
---|
| 216 | end |
---|
| 217 | hcheck_date=findobj(hfig,'tag','check_date'); |
---|
[613] | 218 | |
---|
[641] | 219 | ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content |
---|
[606] | 220 | set(hObject,'Value',1) |
---|
| 221 | set(hObject,'String',ListFiles) |
---|
[613] | 222 | set(hObject,'BackgroundColor',[0.7 0.7 0.7]) |
---|
[611] | 223 | set(htitlebox,'String',FullSelectName)% record the new dir name |
---|
[606] | 224 | elseif exist(FullSelectName,'file')%visualise the field if it exists |
---|
| 225 | FileType=get_file_type(FullSelectName); |
---|
| 226 | if strcmp(FileType,'txt') |
---|
| 227 | edit(FullSelectName) |
---|
| 228 | elseif strcmp(FileType,'xml') |
---|
| 229 | editxml(FullSelectName) |
---|
[612] | 230 | elseif strcmp(FileType,'figure') |
---|
[606] | 231 | open(FullSelectName) |
---|
| 232 | else |
---|
| 233 | %uvmat(FullSelectName); |
---|
| 234 | switch option |
---|
[609] | 235 | case 'browser' |
---|
[612] | 236 | set(htitlebox,'String',FullSelectName); |
---|
| 237 | uiresume(hfig) |
---|
[610] | 238 | case 'status_display' |
---|
[612] | 239 | uvmat(FullSelectName); |
---|
[606] | 240 | end |
---|
| 241 | end |
---|
| 242 | end |
---|
[615] | 243 | set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end |
---|
[606] | 244 | |
---|
[610] | 245 | %------------------------------------------------------------------------- |
---|
| 246 | % list the content of a directory |
---|
[641] | 247 | function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) |
---|
[610] | 248 | %------------------------------------------------------------------------- |
---|
| 249 | ListStruct=dir(DirName);% get structure of the current directory |
---|
[635] | 250 | NumFiles=0; %default |
---|
[611] | 251 | if numel(ListStruct)<1 % case of empty dir |
---|
[610] | 252 | ListFiles={}; |
---|
| 253 | return |
---|
| 254 | end |
---|
| 255 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
---|
| 256 | ListFiles=ListCells(1,:);%list of file names |
---|
[611] | 257 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
[641] | 258 | |
---|
[610] | 259 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
---|
[635] | 260 | ListDates=cell2mat(ListCells(5,:));%list of numerical dates |
---|
| 261 | if isnumeric(sort_option) |
---|
| 262 | check_old=ListDates<sort_option-1;% -1 is put to account for a 1 s delay in the record of starting time |
---|
| 263 | NumFiles=numel(find(~check_old&~check_dir)); |
---|
| 264 | end |
---|
| 265 | if ~isempty(find(~check_dir)) |
---|
| 266 | ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front |
---|
| 267 | end |
---|
[641] | 268 | |
---|
[635] | 269 | if isnumeric(sort_option)|| strcmp(sort_option,'date') |
---|
[612] | 270 | [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list |
---|
| 271 | else |
---|
| 272 | [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list |
---|
| 273 | end |
---|
| 274 | ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file |
---|
[610] | 275 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
[612] | 276 | check_keep=cellfun('isempty', cell_remove); |
---|
[641] | 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 |
---|
[610] | 283 | ListFiles=[{'+/..'} ListFiles(check_keep)]; |
---|
[612] | 284 | if check_date |
---|
[635] | 285 | ListDateString=ListCells(2,:);%list of file dates |
---|
| 286 | if isnumeric(sort_option) |
---|
| 287 | ListDateString(check_old)={'--OLD--'}; |
---|
| 288 | end |
---|
| 289 | ListDateString(check_dir)={''}; |
---|
| 290 | ListDateString=ListDateString(index_sort);% sort the corresponding dates |
---|
| 291 | ListDateString=[{''} ListDateString(check_keep)]; |
---|
| 292 | ListFiles=[ListFiles; ListDateString]; |
---|
| 293 | ListFiles=cell2tab(ListFiles','...'); |
---|
[612] | 294 | end |
---|
[610] | 295 | |
---|
[606] | 296 | %------------------------------------------------------------------------ |
---|
| 297 | % --- launched by selecting home |
---|
| 298 | function home_dir(hObject,event) |
---|
[609] | 299 | %------------------------------------------------------------------------ |
---|
[606] | 300 | DirName=pwd; |
---|
| 301 | hfig=get(hObject,'parent'); |
---|
[613] | 302 | hlist=findobj(hfig,'tag','list');% find the list object |
---|
| 303 | set(hlist,'BackgroundColor',[1 1 0]) |
---|
| 304 | drawnow |
---|
[612] | 305 | sort_option='name';%default |
---|
| 306 | hsort_option=findobj(hfig,'tag','sort_option'); |
---|
| 307 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
---|
| 308 | sort_option='date'; |
---|
| 309 | end |
---|
| 310 | hcheck_date=findobj(hfig,'tag','check_date'); |
---|
| 311 | ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content |
---|
[611] | 312 | htitlebox=findobj(hfig,'Tag','titlebox'); |
---|
| 313 | set(htitlebox,'String',DirName)% record the new dir name |
---|
[613] | 314 | set(hlist,'Value',1) |
---|
[606] | 315 | set(hlist,'String',ListFiles) |
---|
[613] | 316 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
---|
[606] | 317 | %------------------------------------------------------------------------ |
---|
| 318 | |
---|
| 319 | %------------------------------------------------------------------------ |
---|
[609] | 320 | % --- launched by pressing the backward (<--) button |
---|
| 321 | function backward(hObject,event) |
---|
| 322 | %------------------------------------------------------------------------ |
---|
| 323 | PrevDir=get(hObject,'UserData'); |
---|
| 324 | if ~isempty(PrevDir) |
---|
| 325 | hfig=get(hObject,'parent'); |
---|
| 326 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
| 327 | set(htitlebox,'String',PrevDir) |
---|
| 328 | refresh_GUI(findobj(hfig,'Tag','refresh')) |
---|
| 329 | end |
---|
| 330 | |
---|
[606] | 331 | %------------------------------------------------------------------------- |
---|
[641] | 332 | % --- launched by deleting the status figure (only used in mode series status') |
---|
| 333 | %------------------------------------------------------------------------- |
---|
[609] | 334 | function close(option,hObject, eventdata) |
---|
[641] | 335 | |
---|
[610] | 336 | if strcmp(option,'status_display') |
---|
[635] | 337 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 338 | hstatus=findobj(hseries,'Tag','status'); |
---|
| 339 | set(hstatus,'value',0) %reset the status uicontrol in the GUI series |
---|
| 340 | set(hstatus,'BackgroundColor',[0 1 0]) |
---|
[609] | 341 | end |
---|
[606] | 342 | delete(gcbf) |
---|
| 343 | |
---|
[641] | 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,'^.',''))); |
---|