| [646] | 1 | %'uigetfile_uvmat': browser, and display of directories, faster than the Matlab fct uigetfile |
|---|
| [606] | 2 | %------------------------------------------------------------------------ |
|---|
| [648] | 3 | % fileinput=uigetfile_uvmat(title,InputName,FilterExt) |
|---|
| [606] | 4 | % |
|---|
| 5 | % OUTPUT: |
|---|
| [609] | 6 | % fileinput: detected file name, including path |
|---|
| [606] | 7 | % |
|---|
| 8 | % INPUT: |
|---|
| [648] | 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' |
|---|
| [651] | 17 | % 'uigetdir'; browser used to select a directory (like the matlab browser 'uigetdir') |
|---|
| [606] | 18 | |
|---|
| [809] | 19 | %======================================================================= |
|---|
| [1027] | 20 | % Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
|---|
| [809] | 21 | % http://www.legi.grenoble-inp.fr |
|---|
| 22 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.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 | |
|---|
| [641] | 37 | function fileinput=uigetfile_uvmat(title,InputName,FilterExt) |
|---|
| 38 | if ~exist('FilterExt','var') |
|---|
| 39 | FilterExt='*'; |
|---|
| 40 | end |
|---|
| [609] | 41 | fileinput=''; %default file selection |
|---|
| [610] | 42 | if strcmp(title,'status_display') |
|---|
| 43 | option='status_display'; |
|---|
| [609] | 44 | else |
|---|
| 45 | option='browser'; |
|---|
| [606] | 46 | end |
|---|
| [615] | 47 | InputDir=pwd;%look in the current work directory if the input file does not exist |
|---|
| 48 | InputFileName='';%default |
|---|
| 49 | if ischar(InputName) |
|---|
| [1022] | 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 already 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 |
|---|
| [615] | 62 | end |
|---|
| [1022] | 63 | if isdir(InputName) |
|---|
| 64 | InputFileName=['+/' InputFileName Ext]; |
|---|
| 65 | end |
|---|
| [610] | 66 | end |
|---|
| [1022] | 67 | if ismember(computer,{'PCWIN','PCWIN64'})%case of Windows systems |
|---|
| 68 | InputDir=[InputDir '\'];% append '\' for a correct action of dir |
|---|
| [615] | 69 | end |
|---|
| [1022] | 70 | else |
|---|
| 71 | [InputDir,InputFileName,Ext]=fileparts(InputName); |
|---|
| [610] | 72 | end |
|---|
| [609] | 73 | end |
|---|
| [1022] | 74 | |
|---|
| [1037] | 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 |
|---|
| [609] | 77 | set(0,'Unit','points') |
|---|
| [606] | 78 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
|---|
| [609] | 79 | Width=350;% fig width in points (1/72 inch) |
|---|
| 80 | Height=min(0.8*ScreenSize(4),500); |
|---|
| [651] | 81 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
|---|
| [609] | 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); |
|---|
| [611] | 84 | BackgroundColor=get(hfig,'Color'); |
|---|
| [651] | 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'); |
|---|
| [653] | 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','off',... |
|---|
| [651] | 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'); |
|---|
| [653] | 99 | |
|---|
| 100 | OK_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.58 0.005 0.2 0.07],'BackgroundColor',[0 1 0],... |
|---|
| [651] | 101 | 'String','OK','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@(src,event)OK_Callback(option,FilterExt,src,event)); |
|---|
| [653] | 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); |
|---|
| [606] | 104 | %set(hrefresh,'UserData',StatusData) |
|---|
| [610] | 105 | if strcmp(option,'status_display') %put a run advancement display |
|---|
| [635] | 106 | set(hfig,'DeleteFcn',@(src,event)close(option,src,event)) |
|---|
| [651] | 107 | uicontrol('Style','frame','Units','normalized', 'Position', [0.02 0.85 0.9 0.04]); |
|---|
| 108 | uicontrol('Style','frame','Units','normalized', 'Position',[0.02 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); |
|---|
| 109 | % uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... |
|---|
| 110 | % 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); |
|---|
| 111 | delete(home_button) |
|---|
| [653] | 112 | set(OK_button,'String','Open') |
|---|
| 113 | set(close_button,'String','Close') |
|---|
| [651] | 114 | elseif strcmp(FilterExt,'uigetdir') %pick a directory |
|---|
| 115 | set(path_title,'String',title); %show the input title for path (directory) |
|---|
| [653] | 116 | set(OK_button,'String','Select') |
|---|
| 117 | set(close_button,'String','Cancel') |
|---|
| [609] | 118 | else %put a title and additional pushbuttons |
|---|
| [651] | 119 | uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.74 0.6 0.03],'BackgroundColor',BackgroundColor,... |
|---|
| [609] | 120 | 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
|---|
| [651] | 121 | uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,... |
|---|
| 122 | 'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates'); |
|---|
| 123 | % uicontrol('Style','text','Units','normalized', 'Position', [0.37 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... |
|---|
| 124 | % 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); |
|---|
| [653] | 125 | set(OK_button,'String','Open') |
|---|
| 126 | set(close_button,'String','Cancel') |
|---|
| [606] | 127 | end |
|---|
| 128 | drawnow |
|---|
| 129 | end |
|---|
| [651] | 130 | refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir |
|---|
| 131 | if ~strcmp(option,'status_display') |
|---|
| [609] | 132 | uiwait(hfig) |
|---|
| [620] | 133 | if ishandle(hfig) |
|---|
| [651] | 134 | htitlebox=findobj(hfig,'Tag','titlebox'); |
|---|
| 135 | fileinput=get(htitlebox,'String');% retrieve the input file selection |
|---|
| 136 | delete(hfig) |
|---|
| [620] | 137 | end |
|---|
| [609] | 138 | end |
|---|
| 139 | |
|---|
| [615] | 140 | %------------------------------------------------------------------------ |
|---|
| 141 | % --- launched by refreshing the display figure |
|---|
| [651] | 142 | %------------------------------------------------------------------------ |
|---|
| [615] | 143 | function titlebox_Callback(hObject,event) |
|---|
| 144 | refresh_GUI(hObject) |
|---|
| [651] | 145 | |
|---|
| 146 | %------------------------------------------------------------------------ |
|---|
| 147 | % --- launched by selecting OK (relevant for FilterExt='uigetdir') |
|---|
| [615] | 148 | %------------------------------------------------------------------------ |
|---|
| [651] | 149 | function OK_Callback(option,filter_ext,hObject,event) |
|---|
| [714] | 150 | set(hObject,'backgroundColor',[1 1 0])% indicate button activation |
|---|
| [1037] | 151 | fig_struct=get(hObject,'parent'); |
|---|
| 152 | if isstruct(fig_struct);%recent Matlab |
|---|
| 153 | hfig=fig_struct.Number; |
|---|
| 154 | else |
|---|
| 155 | hfig=fig_struct; |
|---|
| 156 | end |
|---|
| [651] | 157 | htitlebox=findobj(hfig,'tag','titlebox'); % display the current dir name |
|---|
| 158 | DirName=get(htitlebox,'String'); |
|---|
| 159 | if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir |
|---|
| 160 | hlist=findobj(hfig,'Tag','list'); |
|---|
| 161 | list=get(hlist,'String'); |
|---|
| 162 | index=get(hlist,'Value'); |
|---|
| [664] | 163 | if ~isempty(regexp(list{index},'^\+/')) |
|---|
| 164 | return % quit if a dir has been opened |
|---|
| 165 | end |
|---|
| 166 | %SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
|---|
| 167 | SelectName=list{index}; |
|---|
| [651] | 168 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
|---|
| 169 | if ~isempty(ind_dot) |
|---|
| 170 | SelectName=SelectName(1:ind_dot-1); |
|---|
| 171 | end |
|---|
| [1022] | 172 | if isempty(regexp(DirName,'^http://'))% if the input dir is not a web site (begins by http://) |
|---|
| 173 | FullSelectName=fullfile(DirName,SelectName); |
|---|
| 174 | check_exist=exist(FullSelectName,'file'); |
|---|
| 175 | else |
|---|
| 176 | FullSelectName=[DirName '/' SelectName]; |
|---|
| 177 | check_exist=1; |
|---|
| 178 | end |
|---|
| 179 | if check_exist |
|---|
| [651] | 180 | switch option |
|---|
| 181 | case 'browser' |
|---|
| 182 | set(htitlebox,'String',FullSelectName); |
|---|
| 183 | uiresume(hfig) |
|---|
| 184 | case 'status_display' |
|---|
| [784] | 185 | FileInfo=get_file_info(FullSelectName); |
|---|
| [783] | 186 | if strcmp(FileInfo.FileType,'txt') |
|---|
| [651] | 187 | edit(FullSelectName) |
|---|
| [783] | 188 | elseif strcmp(FileInfo.FileType,'xml') |
|---|
| [651] | 189 | editxml(FullSelectName) |
|---|
| [783] | 190 | elseif strcmp(FileInfo.FileType,'figure') |
|---|
| [651] | 191 | open(FullSelectName) |
|---|
| 192 | else |
|---|
| 193 | uvmat(FullSelectName); |
|---|
| 194 | end |
|---|
| 195 | end |
|---|
| 196 | end |
|---|
| 197 | end |
|---|
| [1031] | 198 | set(hObject,'backgroundColor',[0 1 0])% indicate end button activatio |
|---|
| [1050] | 199 | fig_struct=get(hObject,'parent'); |
|---|
| 200 | if isstruct(fig_struct);%recent Matlab |
|---|
| 201 | uiresume(fig_struct.Number) |
|---|
| 202 | else |
|---|
| 203 | uiresume(fig_struct) |
|---|
| 204 | end |
|---|
| [651] | 205 | |
|---|
| [1022] | 206 | %------------------------------------------------------------------------ |
|---|
| [610] | 207 | % --- launched by refreshing the display figure |
|---|
| [641] | 208 | function refresh_GUI(hObject,InputFileName,FilterExt) |
|---|
| [610] | 209 | %------------------------------------------------------------------------ |
|---|
| 210 | if ~exist('InputFileName','var') |
|---|
| 211 | InputFileName=''; |
|---|
| 212 | end |
|---|
| [648] | 213 | if ~exist('FilterExt','var') |
|---|
| 214 | FilterExt='*'; |
|---|
| 215 | end |
|---|
| [651] | 216 | if strcmp(FilterExt,'uigetdir') |
|---|
| 217 | FilterExt='*'; |
|---|
| 218 | end |
|---|
| [610] | 219 | hfig=get(hObject,'parent'); |
|---|
| [613] | 220 | hlist=findobj(hfig,'tag','list');% find the list object |
|---|
| 221 | set(hlist,'BackgroundColor',[1 1 0]) |
|---|
| 222 | drawnow |
|---|
| [611] | 223 | htitlebox=findobj(hfig,'tag','titlebox'); |
|---|
| 224 | DirName=get(htitlebox,'String'); |
|---|
| [612] | 225 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| [1022] | 226 | % use with GUI series |
|---|
| 227 | if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series |
|---|
| [610] | 228 | hseries=findobj(allchild(0),'tag','series'); |
|---|
| [635] | 229 | hstatus=findobj(hseries,'tag','status'); |
|---|
| [610] | 230 | StatusData=get(hstatus,'UserData'); |
|---|
| 231 | TimeStart=0; |
|---|
| 232 | if isfield(StatusData,'TimeStart') |
|---|
| 233 | TimeStart=StatusData.TimeStart; |
|---|
| [635] | 234 | end |
|---|
| [610] | 235 | hlist=findobj(hfig,'tag','list'); |
|---|
| [1022] | 236 | testrecent=0; |
|---|
| [610] | 237 | NbOutputFile=[]; |
|---|
| [635] | 238 | if isfield(StatusData,'NbOutputFile') |
|---|
| 239 | NbOutputFile=StatusData.NbOutputFile; |
|---|
| 240 | NbOutputFile_str=num2str(NbOutputFile); |
|---|
| [610] | 241 | end |
|---|
| [644] | 242 | [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content |
|---|
| [610] | 243 | |
|---|
| [1022] | 244 | % update the waitbar |
|---|
| [610] | 245 | hwaitbar=findobj(hfig,'tag','waitbar'); |
|---|
| 246 | if ~isempty(NbOutputFile) |
|---|
| 247 | BarPosition=get(hwaitbar,'Position'); |
|---|
| [635] | 248 | BarPosition(3)=0.9*max(0.01,NumFiles/NbOutputFile);% the bar width cannot be set to 0, set to 0.01 instead |
|---|
| [610] | 249 | set(hwaitbar,'Position',BarPosition) |
|---|
| 250 | end |
|---|
| [1022] | 251 | else %use as usual browser |
|---|
| [635] | 252 | sort_option='name'; |
|---|
| 253 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
|---|
| 254 | sort_option='date'; |
|---|
| 255 | end |
|---|
| 256 | hcheck_date=findobj(hfig,'tag','check_date'); |
|---|
| [641] | 257 | [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content |
|---|
| [610] | 258 | end |
|---|
| 259 | |
|---|
| [635] | 260 | set(hlist,'String',ListFiles) |
|---|
| 261 | Value=[]; |
|---|
| 262 | if ~isempty(InputFileName) |
|---|
| 263 | Value=find(strcmp(InputFileName,ListFiles)); |
|---|
| 264 | end |
|---|
| 265 | if isempty(Value) |
|---|
| 266 | Value=1; |
|---|
| 267 | end |
|---|
| 268 | set(hlist,'Value',Value) |
|---|
| 269 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| [651] | 270 | |
|---|
| [610] | 271 | %------------------------------------------------------------------------ |
|---|
| [609] | 272 | % --- launched by selecting an item on the file list |
|---|
| [651] | 273 | %------------------------------------------------------------------------ |
|---|
| [612] | 274 | function dates_Callback(hObject,event) |
|---|
| [651] | 275 | |
|---|
| [612] | 276 | hfig=get(hObject,'parent'); |
|---|
| 277 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 278 | if get(hObject,'Value') |
|---|
| 279 | set(hsort_option,'Visible','on') |
|---|
| 280 | set(hsort_option,'Value',2) |
|---|
| 281 | else |
|---|
| 282 | set(hsort_option,'Visible','off') |
|---|
| 283 | end |
|---|
| 284 | refresh_GUI(hObject,[]) |
|---|
| 285 | |
|---|
| [651] | 286 | |
|---|
| [612] | 287 | %------------------------------------------------------------------------ |
|---|
| 288 | % --- launched by selecting an item on the file list |
|---|
| [641] | 289 | function list_Callback(option,filter_ext,hObject,event) |
|---|
| [612] | 290 | %------------------------------------------------------------------------ |
|---|
| [617] | 291 | hfig=get(hObject,'parent');%handle of the fig |
|---|
| 292 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
|---|
| [615] | 293 | drawnow |
|---|
| [606] | 294 | list=get(hObject,'String'); |
|---|
| 295 | index=get(hObject,'Value'); |
|---|
| [617] | 296 | |
|---|
| [611] | 297 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
|---|
| 298 | DirName=get(htitlebox,'String'); |
|---|
| [1022] | 299 | CheckSubDir=~isempty(regexp(list{index},'^\+')); |
|---|
| [609] | 300 | SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
|---|
| [612] | 301 | ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' |
|---|
| 302 | if ~isempty(ind_dot) |
|---|
| 303 | SelectName=SelectName(1:ind_dot-1); |
|---|
| 304 | end |
|---|
| [609] | 305 | if strcmp(SelectName,'..')% the upward dir option has been selected |
|---|
| [606] | 306 | FullSelectName=fileparts(DirName); |
|---|
| 307 | else |
|---|
| [1022] | 308 | if isempty(regexp(DirName,'^http://'))% usual files |
|---|
| 309 | FullSelectName=fullfile(DirName,SelectName); |
|---|
| 310 | else |
|---|
| 311 | FullSelectName=[DirName '/' SelectName]; |
|---|
| 312 | end |
|---|
| [606] | 313 | end |
|---|
| [1022] | 314 | if CheckSubDir%exist(FullSelectName,'dir')% a directory has been selected |
|---|
| [613] | 315 | set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action |
|---|
| 316 | drawnow |
|---|
| [609] | 317 | hbackward=findobj(hfig,'Tag','backward'); |
|---|
| 318 | set(hbackward,'UserData',DirName); %store the current dir for future backward action |
|---|
| [612] | 319 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 320 | sort_option='name';%default |
|---|
| 321 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
|---|
| 322 | sort_option='date'; |
|---|
| 323 | end |
|---|
| 324 | hcheck_date=findobj(hfig,'tag','check_date'); |
|---|
| [613] | 325 | |
|---|
| [641] | 326 | ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content |
|---|
| [606] | 327 | set(hObject,'Value',1) |
|---|
| 328 | set(hObject,'String',ListFiles) |
|---|
| [613] | 329 | set(hObject,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| [611] | 330 | set(htitlebox,'String',FullSelectName)% record the new dir name |
|---|
| [606] | 331 | end |
|---|
| [615] | 332 | set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end |
|---|
| [606] | 333 | |
|---|
| [610] | 334 | %------------------------------------------------------------------------- |
|---|
| 335 | % list the content of a directory |
|---|
| [641] | 336 | function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) |
|---|
| [610] | 337 | %------------------------------------------------------------------------- |
|---|
| [1022] | 338 | ListStruct=dir_uvmat(DirName);% get structure of the current directory |
|---|
| [635] | 339 | NumFiles=0; %default |
|---|
| [611] | 340 | if numel(ListStruct)<1 % case of empty dir |
|---|
| [610] | 341 | ListFiles={}; |
|---|
| 342 | return |
|---|
| 343 | end |
|---|
| 344 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
|---|
| 345 | ListFiles=ListCells(1,:);%list of file names |
|---|
| [1030] | 346 | index_dir=find(strcmp('isdir',fieldnames(ListStruct))); |
|---|
| 347 | check_dir=cell2mat(ListCells(index_dir,:));% =1 for directories, =0 for files |
|---|
| [1022] | 348 | % for ilist=1:numel(check_dir) |
|---|
| 349 | % if check_dir(ilist) |
|---|
| [610] | 350 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
|---|
| [1022] | 351 | % end |
|---|
| 352 | % end |
|---|
| [651] | 353 | if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir') |
|---|
| [648] | 354 | if strcmp(filter_ext,'image') |
|---|
| 355 | check_keep=cellfun(@isimage,ListFiles) ; |
|---|
| 356 | elseif strcmp(filter_ext(1),'.') |
|---|
| 357 | ind_ext=regexp(ListFiles,[filter_ext '$']);%look for the input file extension |
|---|
| 358 | check_keep=~cellfun('isempty',ind_ext); |
|---|
| 359 | end |
|---|
| 360 | check_keep=check_keep|check_dir; |
|---|
| 361 | ListFiles=ListFiles(check_keep); |
|---|
| 362 | ListCells=ListCells(:,check_keep); |
|---|
| 363 | check_dir=check_dir(check_keep); |
|---|
| 364 | end |
|---|
| [651] | 365 | check_emptydate=cellfun('isempty',ListCells(5,:));% = 1 if datenum undefined |
|---|
| 366 | ListCells(5,find(check_emptydate))={0}; %set to 0 the empty dates |
|---|
| [635] | 367 | ListDates=cell2mat(ListCells(5,:));%list of numerical dates |
|---|
| 368 | if isnumeric(sort_option) |
|---|
| 369 | check_old=ListDates<sort_option-1;% -1 is put to account for a 1 s delay in the record of starting time |
|---|
| 370 | NumFiles=numel(find(~check_old&~check_dir)); |
|---|
| 371 | end |
|---|
| 372 | if ~isempty(find(~check_dir)) |
|---|
| 373 | ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front |
|---|
| 374 | end |
|---|
| [641] | 375 | |
|---|
| [635] | 376 | if isnumeric(sort_option)|| strcmp(sort_option,'date') |
|---|
| [612] | 377 | [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list |
|---|
| 378 | else |
|---|
| 379 | [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list |
|---|
| 380 | end |
|---|
| 381 | ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file |
|---|
| [610] | 382 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
|---|
| [612] | 383 | check_keep=cellfun('isempty', cell_remove); |
|---|
| [610] | 384 | ListFiles=[{'+/..'} ListFiles(check_keep)]; |
|---|
| [612] | 385 | if check_date |
|---|
| [635] | 386 | ListDateString=ListCells(2,:);%list of file dates |
|---|
| 387 | if isnumeric(sort_option) |
|---|
| 388 | ListDateString(check_old)={'--OLD--'}; |
|---|
| 389 | end |
|---|
| 390 | ListDateString(check_dir)={''}; |
|---|
| 391 | ListDateString=ListDateString(index_sort);% sort the corresponding dates |
|---|
| 392 | ListDateString=[{''} ListDateString(check_keep)]; |
|---|
| 393 | ListFiles=[ListFiles; ListDateString]; |
|---|
| 394 | ListFiles=cell2tab(ListFiles','...'); |
|---|
| [612] | 395 | end |
|---|
| [610] | 396 | |
|---|
| [606] | 397 | %------------------------------------------------------------------------ |
|---|
| 398 | % --- launched by selecting home |
|---|
| 399 | function home_dir(hObject,event) |
|---|
| [609] | 400 | %------------------------------------------------------------------------ |
|---|
| [606] | 401 | DirName=pwd; |
|---|
| 402 | hfig=get(hObject,'parent'); |
|---|
| [613] | 403 | hlist=findobj(hfig,'tag','list');% find the list object |
|---|
| 404 | set(hlist,'BackgroundColor',[1 1 0]) |
|---|
| 405 | drawnow |
|---|
| [612] | 406 | sort_option='name';%default |
|---|
| 407 | hsort_option=findobj(hfig,'tag','sort_option'); |
|---|
| 408 | if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2) |
|---|
| 409 | sort_option='date'; |
|---|
| 410 | end |
|---|
| 411 | hcheck_date=findobj(hfig,'tag','check_date'); |
|---|
| 412 | ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content |
|---|
| [611] | 413 | htitlebox=findobj(hfig,'Tag','titlebox'); |
|---|
| 414 | set(htitlebox,'String',DirName)% record the new dir name |
|---|
| [613] | 415 | set(hlist,'Value',1) |
|---|
| [606] | 416 | set(hlist,'String',ListFiles) |
|---|
| [613] | 417 | set(hlist,'BackgroundColor',[0.7 0.7 0.7]) |
|---|
| [606] | 418 | %------------------------------------------------------------------------ |
|---|
| 419 | |
|---|
| 420 | %------------------------------------------------------------------------ |
|---|
| [609] | 421 | % --- launched by pressing the backward (<--) button |
|---|
| 422 | function backward(hObject,event) |
|---|
| 423 | %------------------------------------------------------------------------ |
|---|
| 424 | PrevDir=get(hObject,'UserData'); |
|---|
| 425 | if ~isempty(PrevDir) |
|---|
| 426 | hfig=get(hObject,'parent'); |
|---|
| 427 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
|---|
| 428 | set(htitlebox,'String',PrevDir) |
|---|
| 429 | refresh_GUI(findobj(hfig,'Tag','refresh')) |
|---|
| 430 | end |
|---|
| 431 | |
|---|
| [606] | 432 | %------------------------------------------------------------------------- |
|---|
| [641] | 433 | % --- launched by deleting the status figure (only used in mode series status') |
|---|
| 434 | %------------------------------------------------------------------------- |
|---|
| [609] | 435 | function close(option,hObject, eventdata) |
|---|
| [641] | 436 | |
|---|
| [610] | 437 | if strcmp(option,'status_display') |
|---|
| [635] | 438 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 439 | hstatus=findobj(hseries,'Tag','status'); |
|---|
| 440 | set(hstatus,'value',0) %reset the status uicontrol in the GUI series |
|---|
| 441 | set(hstatus,'BackgroundColor',[0 1 0]) |
|---|
| [609] | 442 | end |
|---|
| [606] | 443 | delete(gcbf) |
|---|
| 444 | |
|---|
| [641] | 445 | %------------------------------------------------------------------------- |
|---|
| 446 | % --- check whether a file is has an image name extension |
|---|
| 447 | %------------------------------------------------------------------------- |
|---|
| 448 | function CheckImage=isimage(filename) |
|---|
| 449 | |
|---|
| 450 | [pp,name,ext]=fileparts(filename); |
|---|
| [809] | 451 | CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.',''))); |
|---|