Changeset 609 for trunk/src/uigetfile_uvmat.m
- Timestamp:
- Apr 9, 2013, 8:20:00 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uigetfile_uvmat.m
r606 r609 4 4 % 5 5 % OUTPUT: 6 % hfig: handles of the browser fig, the selected file name is obtained as File=get(hfig,'UserData')6 % fileinput: detected file name, including path 7 7 % 8 8 % INPUT: 9 % option: ='file browser': usual browser, 'seriesstatus': display advancement of a series calculation9 % title: = displayed title, 'status': display advancement of a series calculation 10 10 % InputDir: directory to browse at first display 11 11 12 13 function hfig=uigetfile_uvmat(option,InputDir) 14 if ~exist(InputDir,'dir') 15 InputDir=pwd; 16 end 17 hfig=findobj(allchild(0),'name',option); 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'; 18 end 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); 18 30 if isempty(hfig) 31 set(0,'Unit','points') 19 32 ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right 20 hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Position',[ScreenSize(3)-600 ScreenSize(4)-640 560 600],'DeleteFcn',@stop_status,'UserData',InputDir); 21 uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @(src,event)view_file(option,src,event),'tag','list','FontSize',12); 22 uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',InputDir,'FontSize',12,'FontWeight','bold'); 23 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@stop_status); 24 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.1 0.01 0.2 0.07],'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@refresh_GUI); 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); 25 46 %set(hrefresh,'UserData',StatusData) 26 if strcmp(option,'series status') %put a run advancement display 47 if strcmp(option,'status') %put a run advancement display 48 set(hfig,'DeleteFcn',@stop_status) 27 49 uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.81 0.01 0.05],'BackgroundColor',[1 0 0],'tag','waitbar'); 28 50 uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]); 29 else %put a title 30 uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.81 0.9 0.03],'String','select an input file:',... 31 'FontSize',14,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); 32 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.01 0.2 0.07],'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir); 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); 33 58 end 34 59 drawnow 35 60 end 36 refresh_GUI(hfig) 37 38 %------------------------------------------------------------------------ 39 % --- launched by selecting a file on the list 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 68 %------------------------------------------------------------------------ 69 % --- launched by selecting an item on the file list 40 70 function view_file(option,hObject,event) 41 71 %------------------------------------------------------------------------ 42 72 list=get(hObject,'String'); 43 73 index=get(hObject,'Value'); 44 hfig=get(hObject,'parent'); 45 DirName=get( get(hObject,'parent'),'UserData');46 SelectName=regexprep(list{index},'^ /','');% remove the/ used to mark dir47 if strcmp(SelectName,'..') 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 48 78 FullSelectName=fileparts(DirName); 49 79 else 50 %ind_dot=regexp(SelectName,'\.\.\.');51 % if ~isempty(ind_dot)52 % SelectName=SelectName(1:ind_dot-1);53 % end54 FullSelectName=fullfile(DirName,SelectName);80 %ind_dot=regexp(SelectName,'\.\.\.'); 81 % if ~isempty(ind_dot) 82 % SelectName=SelectName(1:ind_dot-1); 83 % end 84 FullSelectName=fullfile(DirName,SelectName); 55 85 end 56 86 if exist(FullSelectName,'dir')% a directory has been selected … … 65 95 % FullSelectName=fileparts(fileparts(FullSelectName)); 66 96 % end 97 hbackward=findobj(hfig,'Tag','backward'); 98 set(hbackward,'UserData',DirName); %store the current dir for future backward action 67 99 ListFiles=list_files(FullSelectName); 68 100 set(hObject,'Value',1) … … 82 114 %uvmat(FullSelectName); 83 115 switch option 84 case ' filebrowser'116 case 'browser' 85 117 hfig=get(hObject,'parent'); 86 118 set(hfig,'UserData',FullSelectName); 87 119 uiresume(hfig) 88 case 's eries status'120 case 'status' 89 121 uvmat(FullSelectName); 90 122 end 91 end92 set(gcbo,'Value',1)123 set(gcbo,'Value',1) 124 end 93 125 end 94 126 … … 96 128 % --- launched by selecting home 97 129 function home_dir(hObject,event) 130 %------------------------------------------------------------------------ 98 131 DirName=pwd; 99 100 132 ListFiles=list_files(DirName);% list the directory content 101 133 hfig=get(hObject,'parent'); … … 108 140 109 141 %------------------------------------------------------------------------ 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 %------------------------------------------------------------------------ 110 157 % --- launched by refreshing the display figure 111 function refresh_GUI(hfig,event) 112 %------------------------------------------------------------------------ 158 function refresh_GUI(hObject,InputFileName) 159 %------------------------------------------------------------------------ 160 if ~exist('InputFileName','var') 161 InputFileName=''; 162 end 163 hfig=get(hObject,'parent'); 113 164 DirName=get(hfig,'UserData'); 114 165 ListFiles=list_files(DirName);% list the directory content 115 166 hlist=findobj(hfig,'tag','list');% find the list object 116 167 set(hlist,'String',ListFiles) 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) 117 176 return 118 177 … … 188 247 ListFiles=ListCells(1,:);%list of file names 189 248 check_dir=cell2mat(ListCells(4,:));% check directories 190 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+',' /$0');% put '/' in front of dir name display249 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display 191 250 [tild,index_sort]=sort(check_dir,2,'descend');% sort 192 251 ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file 193 cell_remove=regexp(ListFiles,'^(-|\.| /\.)');% remove strings beginning by '/.',';' or '-'194 check_ remove=cellfun('isempty',cell_remove);195 ListFiles=[{' /..'} ListFiles(check_remove)];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)]; 196 255 197 256 %------------------------------------------------------------------------- 198 % launched by deleting the status figure 199 function stop_status(hObject, eventdata)257 % launched by deleting the status figure (only used in mode series status') 258 function close(option,hObject, eventdata) 200 259 %------------------------------------------------------------------------- 201 hciv=findobj(allchild(0),'tag','series'); 202 hhciv=guidata(hciv); 203 set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ 204 set(hhciv.status,'BackgroundColor',[0 1 0]) 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 205 266 delete(gcbf) 206 267
Note: See TracChangeset
for help on using the changeset viewer.