[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 | |
---|
[609] | 12 | function fileinput=uigetfile_uvmat(title,InputName) |
---|
| 13 | fileinput=''; %default file selection |
---|
| 14 | if strcmp(title,'status') |
---|
| 15 | option='status'; |
---|
| 16 | else |
---|
| 17 | option='browser'; |
---|
[606] | 18 | end |
---|
[609] | 19 | if exist(InputName,'file')||exist(InputName,'dir') |
---|
| 20 | [InputDir,InputFileName,Ext]=fileparts(InputName); |
---|
| 21 | InputFileName=[InputFileName Ext]; |
---|
| 22 | if isdir(InputName) |
---|
| 23 | InputFileName=['+/' InputFileName]; |
---|
| 24 | end |
---|
| 25 | else |
---|
| 26 | InputDir=pwd;%look in the current work directory if the input file does not exist |
---|
| 27 | InputFileName=''; |
---|
| 28 | end |
---|
| 29 | hfig=findobj(allchild(0),'tag',option); |
---|
[606] | 30 | if isempty(hfig) |
---|
[609] | 31 | set(0,'Unit','points') |
---|
[606] | 32 | ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right |
---|
[609] | 33 | Width=350;% fig width in points (1/72 inch) |
---|
| 34 | Height=min(0.8*ScreenSize(4),500); |
---|
| 35 | Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 |
---|
| 36 | Bottom=ScreenSize(4)-Height-40; %put fig at top right |
---|
| 37 | hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); |
---|
| 38 | uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @(src,event)view_file(option,src,event),'tag','list',... |
---|
| 39 | 'FontUnits','points','FontSize',12); |
---|
| 40 | uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,... |
---|
| 41 | 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold'); |
---|
| 42 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'Callback',@(src,event)close(option,src,event),... |
---|
| 43 | 'String','Close','FontWeight','bold','FontUnits','points','FontSize',12); |
---|
| 44 | uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.1 0.01 0.2 0.07],'Callback',@refresh_GUI,... |
---|
| 45 | 'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12); |
---|
[606] | 46 | %set(hrefresh,'UserData',StatusData) |
---|
[609] | 47 | if strcmp(option,'status') %put a run advancement display |
---|
| 48 | set(hfig,'DeleteFcn',@stop_status) |
---|
[606] | 49 | uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.81 0.01 0.05],'BackgroundColor',[1 0 0],'tag','waitbar'); |
---|
| 50 | uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]); |
---|
[609] | 51 | else %put a title and additional pushbuttons |
---|
| 52 | uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.81 0.8 0.03],... |
---|
| 53 | 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); |
---|
| 54 | uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.8 0.1 0.07],... |
---|
| 55 | 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward); |
---|
| 56 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.01 0.2 0.07],... |
---|
| 57 | 'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir); |
---|
[606] | 58 | end |
---|
| 59 | drawnow |
---|
| 60 | end |
---|
[609] | 61 | refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName) |
---|
| 62 | if ~strcmp(option,'status') |
---|
| 63 | uiwait(hfig) |
---|
| 64 | end |
---|
| 65 | fileinput=get(hfig,'UserData');% retrieve the input file selection |
---|
| 66 | delete(hfig) |
---|
| 67 | |
---|
[606] | 68 | %------------------------------------------------------------------------ |
---|
[609] | 69 | % --- launched by selecting an item on the file list |
---|
[606] | 70 | function view_file(option,hObject,event) |
---|
| 71 | %------------------------------------------------------------------------ |
---|
| 72 | list=get(hObject,'String'); |
---|
| 73 | index=get(hObject,'Value'); |
---|
[609] | 74 | hfig=get(hObject,'parent');%handle of the fig |
---|
| 75 | DirName=get(hfig,'UserData'); |
---|
| 76 | SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir |
---|
| 77 | if strcmp(SelectName,'..')% the upward dir option has been selected |
---|
[606] | 78 | FullSelectName=fileparts(DirName); |
---|
| 79 | else |
---|
[609] | 80 | %ind_dot=regexp(SelectName,'\.\.\.'); |
---|
| 81 | % if ~isempty(ind_dot) |
---|
| 82 | % SelectName=SelectName(1:ind_dot-1); |
---|
| 83 | % end |
---|
| 84 | FullSelectName=fullfile(DirName,SelectName); |
---|
[606] | 85 | end |
---|
| 86 | if exist(FullSelectName,'dir')% a directory has been selected |
---|
| 87 | % ListFiles=dir(FullSelectName); |
---|
| 88 | % ListDisplay=cell(numel(ListFiles),1); |
---|
| 89 | % for ilist=2:numel(ListDisplay)% suppress the first line '.' |
---|
| 90 | % ListDisplay{ilist-1}=ListFiles(ilist).name; |
---|
| 91 | % end |
---|
| 92 | % set(hObject,'Value',1) |
---|
| 93 | % set(hObject,'String',ListDisplay) |
---|
| 94 | % if strcmp(selectname,'..') |
---|
| 95 | % FullSelectName=fileparts(fileparts(FullSelectName)); |
---|
| 96 | % end |
---|
[609] | 97 | hbackward=findobj(hfig,'Tag','backward'); |
---|
| 98 | set(hbackward,'UserData',DirName); %store the current dir for future backward action |
---|
[606] | 99 | ListFiles=list_files(FullSelectName); |
---|
| 100 | set(hObject,'Value',1) |
---|
| 101 | set(hObject,'String',ListFiles) |
---|
| 102 | set(hfig,'UserData',FullSelectName)% record the new dir name |
---|
| 103 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
| 104 | set(htitlebox,'String',FullSelectName) |
---|
| 105 | elseif exist(FullSelectName,'file')%visualise the field if it exists |
---|
| 106 | FileType=get_file_type(FullSelectName); |
---|
| 107 | if strcmp(FileType,'txt') |
---|
| 108 | edit(FullSelectName) |
---|
| 109 | elseif strcmp(FileType,'xml') |
---|
| 110 | editxml(FullSelectName) |
---|
| 111 | elseif strcmp(FileType,'figure') |
---|
| 112 | open(FullSelectName) |
---|
| 113 | else |
---|
| 114 | %uvmat(FullSelectName); |
---|
| 115 | switch option |
---|
[609] | 116 | case 'browser' |
---|
[606] | 117 | hfig=get(hObject,'parent'); |
---|
| 118 | set(hfig,'UserData',FullSelectName); |
---|
| 119 | uiresume(hfig) |
---|
[609] | 120 | case 'status' |
---|
[606] | 121 | uvmat(FullSelectName); |
---|
| 122 | end |
---|
[609] | 123 | set(gcbo,'Value',1) |
---|
[606] | 124 | end |
---|
| 125 | end |
---|
| 126 | |
---|
| 127 | %------------------------------------------------------------------------ |
---|
| 128 | % --- launched by selecting home |
---|
| 129 | function home_dir(hObject,event) |
---|
[609] | 130 | %------------------------------------------------------------------------ |
---|
[606] | 131 | DirName=pwd; |
---|
| 132 | ListFiles=list_files(DirName);% list the directory content |
---|
| 133 | hfig=get(hObject,'parent'); |
---|
| 134 | set(hfig,'UserData',DirName)% record the new dir name |
---|
| 135 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
| 136 | set(htitlebox,'String',DirName) |
---|
| 137 | hlist=findobj(hfig,'tag','list');% find the list object |
---|
| 138 | set(hlist,'String',ListFiles) |
---|
| 139 | %------------------------------------------------------------------------ |
---|
| 140 | |
---|
| 141 | %------------------------------------------------------------------------ |
---|
[609] | 142 | % --- launched by pressing the backward (<--) button |
---|
| 143 | function backward(hObject,event) |
---|
| 144 | %------------------------------------------------------------------------ |
---|
| 145 | PrevDir=get(hObject,'UserData'); |
---|
| 146 | if ~isempty(PrevDir) |
---|
| 147 | hfig=get(hObject,'parent'); |
---|
| 148 | set(hfig,'UserData',PrevDir) |
---|
| 149 | htitlebox=findobj(hfig,'tag','titlebox'); % display the new dir name |
---|
| 150 | set(htitlebox,'String',PrevDir) |
---|
| 151 | refresh_GUI(findobj(hfig,'Tag','refresh')) |
---|
| 152 | end |
---|
| 153 | |
---|
| 154 | %------------------------------------------------------------------------ |
---|
| 155 | |
---|
| 156 | %------------------------------------------------------------------------ |
---|
[606] | 157 | % --- launched by refreshing the display figure |
---|
[609] | 158 | function refresh_GUI(hObject,InputFileName) |
---|
[606] | 159 | %------------------------------------------------------------------------ |
---|
[609] | 160 | if ~exist('InputFileName','var') |
---|
| 161 | InputFileName=''; |
---|
| 162 | end |
---|
| 163 | hfig=get(hObject,'parent'); |
---|
[606] | 164 | DirName=get(hfig,'UserData'); |
---|
| 165 | ListFiles=list_files(DirName);% list the directory content |
---|
| 166 | hlist=findobj(hfig,'tag','list');% find the list object |
---|
| 167 | set(hlist,'String',ListFiles) |
---|
[609] | 168 | Value=[]; |
---|
| 169 | if ~isempty(InputFileName) |
---|
| 170 | Value=find(strcmp(InputFileName,ListFiles)); |
---|
| 171 | end |
---|
| 172 | if isempty(Value) |
---|
| 173 | Value=1; |
---|
| 174 | end |
---|
| 175 | set(hlist,'Value',Value) |
---|
[606] | 176 | return |
---|
| 177 | |
---|
| 178 | %TODO adapt to series status |
---|
| 179 | hseries=findobj(allchild(0),'tag','series'); |
---|
| 180 | hstatus=findobj(hseries,'tag','status'); |
---|
| 181 | StatusData=get(hstatus,'UserData'); |
---|
| 182 | TimeStart=0; |
---|
| 183 | if isfield(StatusData,'TimeStart') |
---|
| 184 | TimeStart=StatusData.TimeStart; |
---|
| 185 | end |
---|
| 186 | % testrecent=0; |
---|
| 187 | % datnum=zeros(numel(ListDisplay),1); |
---|
| 188 | % for ilist=1:numel(ListDisplay) |
---|
| 189 | % ListDisplay{ilist}=ListFiles(ilist).name; |
---|
| 190 | % if ListFiles(ilist).isdir |
---|
| 191 | % ListDisplay{ilist}=['/' ListDisplay{ilist}]; |
---|
| 192 | % elseif isfield(ListFiles(ilist),'datenum') |
---|
| 193 | % datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions |
---|
| 194 | % testrecent=1; |
---|
| 195 | % if datnum(ilist)<TimeStart |
---|
| 196 | % ListDisplay{ilist}=[ListDisplay{ilist} ' --OLD--']; |
---|
| 197 | % end |
---|
| 198 | % end |
---|
| 199 | % end |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | %% Look at date of creation |
---|
| 203 | ListDisplay=ListDisplay(datnum~=0); |
---|
| 204 | datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files |
---|
| 205 | |
---|
| 206 | NbOutputFile=[]; |
---|
| 207 | if isempty(datnum) |
---|
| 208 | if testrecent |
---|
| 209 | message='no result created yet'; |
---|
| 210 | else |
---|
| 211 | message=''; |
---|
| 212 | end |
---|
| 213 | else |
---|
| 214 | [first,indfirst]=min(datnum); |
---|
| 215 | [last,indlast]=max(datnum); |
---|
| 216 | NbOutputFile_str='?'; |
---|
| 217 | if isfield(StatusData,'NbOutputFile') |
---|
| 218 | NbOutputFile=StatusData.NbOutputFile; |
---|
| 219 | NbOutputFile_str=num2str(NbOutputFile); |
---|
| 220 | end |
---|
| 221 | message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification: ' ListDisplay{indfirst} ' : ' datestr(first)];... |
---|
| 222 | ['latest modification: ' ListDisplay{indlast} ' : ' datestr(last)]}; |
---|
| 223 | end |
---|
| 224 | set(htitlebox,'String', [DirName{1};message]) |
---|
| 225 | |
---|
| 226 | %% update the waitbar |
---|
| 227 | hwaitbar=findobj(hfig,'tag','waitbar'); |
---|
| 228 | if ~isempty(NbOutputFile) |
---|
| 229 | BarPosition=get(hwaitbar,'Position'); |
---|
| 230 | BarPosition(3)=0.9*numel(datnum)/NbOutputFile; |
---|
| 231 | set(hwaitbar,'Position',BarPosition) |
---|
| 232 | end |
---|
| 233 | |
---|
| 234 | %------------------------------------------------------------------------- |
---|
| 235 | % list the content of a directory |
---|
| 236 | function ListFiles=list_files(DirName) |
---|
| 237 | %------------------------------------------------------------------------- |
---|
| 238 | ListStruct=dir(DirName); |
---|
| 239 | if numel(ListStruct)<1 |
---|
| 240 | ListFiles={}; |
---|
| 241 | return |
---|
| 242 | end |
---|
| 243 | if strcmp(ListStruct(1).name,'.') |
---|
| 244 | ListStruct(1)=[];%removes the first line ='.' |
---|
| 245 | end |
---|
| 246 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
---|
| 247 | ListFiles=ListCells(1,:);%list of file names |
---|
| 248 | check_dir=cell2mat(ListCells(4,:));% check directories |
---|
[609] | 249 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
---|
[606] | 250 | [tild,index_sort]=sort(check_dir,2,'descend');% sort |
---|
| 251 | ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file |
---|
[609] | 252 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
| 253 | check_keep=cellfun('isempty', cell_remove); |
---|
| 254 | ListFiles=[{'+/..'} ListFiles(check_keep)]; |
---|
[606] | 255 | |
---|
| 256 | %------------------------------------------------------------------------- |
---|
[609] | 257 | % launched by deleting the status figure (only used in mode series status') |
---|
| 258 | function close(option,hObject, eventdata) |
---|
[606] | 259 | %------------------------------------------------------------------------- |
---|
[609] | 260 | if strcmp(option,'status') |
---|
| 261 | hseries=findobj(allchild(0),'tag','series'); |
---|
| 262 | hstatus=findobj(hfig,'Tag','status'); |
---|
| 263 | set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ |
---|
| 264 | set(hhciv.status,'BackgroundColor',[0 1 0]) |
---|
| 265 | end |
---|
[606] | 266 | delete(gcbf) |
---|
| 267 | |
---|