Changeset 651 for trunk/src/uigetfile_uvmat.m
- Timestamp:
- Jun 25, 2013, 12:48:10 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uigetfile_uvmat.m
r648 r651 15 15 % 'image': any image or movie 16 16 % '.ext': display only files with extension '.ext' 17 % 'uigetdir'; browser used to select a directory (like the matlab browser 'uigetdir') 17 18 18 19 function fileinput=uigetfile_uvmat(title,InputName,FilterExt) … … 52 53 Width=350;% fig width in points (1/72 inch) 53 54 Height=min(0.8*ScreenSize(4),500); 54 Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 55 Left=ScreenSize(3)- Width-40; %right edge close to the right, with margin=40 55 56 Bottom=ScreenSize(4)-Height-40; %put fig at top right 56 57 hfig=figure('name',option,'tag',option,'MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height],'UserData',InputDir); 57 58 BackgroundColor=get(hfig,'Color'); 58 uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.97 0.5 0.03],'BackgroundColor',BackgroundColor,... 59 'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); 60 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,... 61 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold'); 62 uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.75 0.1 0.07],... 63 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward); 64 uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.75 0.2 0.04],'tag','check_date','Callback',@dates_Callback,... 65 'String','dates','FontUnits','points','FontSize',12,'FontWeight','bold'); 66 uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... 67 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); 68 uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',... 69 'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold'); 70 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',... 71 'FontUnits','points','FontSize',12); 72 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... 59 path_title=uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.97 0.9 0.03],'BackgroundColor',BackgroundColor,'Tag','Path_title',... 60 'String','path:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); 61 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,... 62 'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''titlebox'':current path'); 63 uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.02 0.77 0.1 0.05],... 64 'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward,'TooltipString','move backward'); 65 home_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.35 0.005 0.3 0.07],... 66 'String','Work dir','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir,'TooltipString','reach the current Matlab working directory'); 67 68 uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.75 0.23 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',... 69 'String',{'sort name';'sort date'},'FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''sort_option'': sort the files by names or dates'); 70 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',... 71 'FontUnits','points','FontSize',12,'TooltipString','''list'':current list of directories, marked by +/, and files'); 72 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.78 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... 73 73 'String','Close','FontWeight','bold','FontUnits','points','FontSize',12); 74 uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0. 10.005 0.2 0.07],'Callback',@refresh_GUI,...74 uicontrol('Style','pushbutton','Tag','refresh','Units','normalized','Position', [0.02 0.005 0.2 0.07],'Callback',@refresh_GUI,... 75 75 'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',12); 76 OK_button=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.75 0.81 0.23 0.07],'BackgroundColor',[0 1 0],... 77 'String','OK','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@(src,event)OK_Callback(option,FilterExt,src,event)); 76 78 %set(hrefresh,'UserData',StatusData) 77 79 if strcmp(option,'status_display') %put a run advancement display 78 80 set(hfig,'DeleteFcn',@(src,event)close(option,src,event)) 79 uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.85 0.9 0.04]); 80 uicontrol('Style','frame','Units','normalized', 'Position',[0.05 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); 81 81 uicontrol('Style','frame','Units','normalized', 'Position', [0.02 0.85 0.9 0.04]); 82 uicontrol('Style','frame','Units','normalized', 'Position',[0.02 0.85 0.01 0.04],'BackgroundColor',[1 0 0],'tag','waitbar'); 83 % uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... 84 % 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); 85 delete(home_button) 86 set(OK_button,'String','OPEN') 87 elseif strcmp(FilterExt,'uigetdir') %pick a directory 88 set(path_title,'String',title); %show the input title for path (directory) 82 89 else %put a title and additional pushbuttons 83 uicontrol('Style','text','Units','normalized', 'Position', [0. 15 0.750.6 0.03],'BackgroundColor',BackgroundColor,...90 uicontrol('Style','text','Units','normalized', 'Position', [0.02 0.74 0.6 0.03],'BackgroundColor',BackgroundColor,... 84 91 'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); 85 86 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.005 0.2 0.07],... 87 'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir); 92 uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.78 0.23 0.04],'tag','check_date','Callback',@dates_Callback,... 93 'String','show dates','FontUnits','points','FontSize',12,'FontWeight','bold','TooltipString','''check_date'':press button to display dates'); 94 % uicontrol('Style','text','Units','normalized', 'Position', [0.37 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,... 95 % 'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right'); 96 88 97 end 89 98 drawnow 90 99 end 91 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 92 if ~strcmp(option,'status_display') 100 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 101 if ~strcmp(option,'status_display') 93 102 uiwait(hfig) 94 103 if ishandle(hfig) 95 htitlebox=findobj(hfig,'Tag','titlebox');96 fileinput=get(htitlebox,'String');% retrieve the input file selection97 delete(hfig)104 htitlebox=findobj(hfig,'Tag','titlebox'); 105 fileinput=get(htitlebox,'String');% retrieve the input file selection 106 delete(hfig) 98 107 end 99 108 end … … 101 110 %------------------------------------------------------------------------ 102 111 % --- launched by refreshing the display figure 112 %------------------------------------------------------------------------ 103 113 function titlebox_Callback(hObject,event) 104 114 refresh_GUI(hObject) 105 %------------------------------------------------------------------------ 115 116 %------------------------------------------------------------------------ 117 % --- launched by selecting OK (relevant for FilterExt='uigetdir') 118 %------------------------------------------------------------------------ 119 function OK_Callback(option,filter_ext,hObject,event) 120 hfig=get(hObject,'parent');%handle of the fig 121 % if ~strcmp(get(hfig,'SelectionType'),'open') 122 % return %select double click 123 % end 124 %set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action 125 % drawnow 126 htitlebox=findobj(hfig,'tag','titlebox'); % display the current dir name 127 DirName=get(htitlebox,'String'); 128 129 if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir 130 hlist=findobj(hfig,'Tag','list'); 131 list=get(hlist,'String'); 132 index=get(hlist,'Value'); 133 SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir 134 ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond '...' 135 if ~isempty(ind_dot) 136 SelectName=SelectName(1:ind_dot-1); 137 end 138 % if strcmp(SelectName,'..')% the upward dir option has been selected 139 % FullSelectName=fileparts(DirName); 140 % else 141 FullSelectName=fullfile(DirName,SelectName); 142 % end 143 if exist(FullSelectName,'file') 144 switch option 145 case 'browser' 146 set(htitlebox,'String',FullSelectName); 147 uiresume(hfig) 148 case 'status_display' 149 FileType=get_file_type(FullSelectName); 150 if strcmp(FileType,'txt') 151 edit(FullSelectName) 152 elseif strcmp(FileType,'xml') 153 editxml(FullSelectName) 154 elseif strcmp(FileType,'figure') 155 open(FullSelectName) 156 else 157 uvmat(FullSelectName); 158 end 159 end 160 end 161 end 162 %set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end 163 164 uiresume(get(hObject,'parent')) 106 165 107 166 %------------------------------------------------------------------------ … … 113 172 end 114 173 if ~exist('FilterExt','var') 174 FilterExt='*'; 175 end 176 if strcmp(FilterExt,'uigetdir') 115 177 FilterExt='*'; 116 178 end … … 165 227 set(hlist,'Value',Value) 166 228 set(hlist,'BackgroundColor',[0.7 0.7 0.7]) 229 167 230 %------------------------------------------------------------------------ 168 231 % --- launched by selecting an item on the file list 232 %------------------------------------------------------------------------ 169 233 function dates_Callback(hObject,event) 170 %------------------------------------------------------------------------ 234 171 235 hfig=get(hObject,'parent'); 172 236 hsort_option=findobj(hfig,'tag','sort_option'); … … 178 242 end 179 243 refresh_GUI(hObject,[]) 244 180 245 181 246 %------------------------------------------------------------------------ … … 205 270 end 206 271 if exist(FullSelectName,'dir')% a directory has been selected 207 % ListFiles=dir(FullSelectName);208 % ListDisplay=cell(numel(ListFiles),1);209 % for ilist=2:numel(ListDisplay)% suppress the first line '.'210 % ListDisplay{ilist-1}=ListFiles(ilist).name;211 % end212 % set(hObject,'Value',1)213 % set(hObject,'String',ListDisplay)214 % if strcmp(selectname,'..')215 % FullSelectName=fileparts(fileparts(FullSelectName));216 % end217 272 set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action 218 273 drawnow … … 231 286 set(hObject,'BackgroundColor',[0.7 0.7 0.7]) 232 287 set(htitlebox,'String',FullSelectName)% record the new dir name 233 elseif exist(FullSelectName,'file')%visualise the field if it exists234 switch option235 case 'browser'236 set(htitlebox,'String',FullSelectName);237 uiresume(hfig)238 case 'status_display'239 FileType=get_file_type(FullSelectName);240 if strcmp(FileType,'txt')241 edit(FullSelectName)242 elseif strcmp(FileType,'xml')243 editxml(FullSelectName)244 elseif strcmp(FileType,'figure')245 open(FullSelectName)246 else247 uvmat(FullSelectName);248 end249 end250 288 end 251 289 set(hObject,'BackgroundColor',[0.7 0.7 0.7])% paint list in grey to indicate action end … … 265 303 check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files 266 304 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display 267 if exist('filter_ext','var') && ~strcmp(filter_ext,'*') 305 if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir') 268 306 if strcmp(filter_ext,'image') 269 307 check_keep=cellfun(@isimage,ListFiles) ; … … 277 315 check_dir=check_dir(check_keep); 278 316 end 317 check_emptydate=cellfun('isempty',ListCells(5,:));% = 1 if datenum undefined 318 ListCells(5,find(check_emptydate))={0}; %set to 0 the empty dates 279 319 ListDates=cell2mat(ListCells(5,:));%list of numerical dates 280 320 if isnumeric(sort_option)
Note: See TracChangeset
for help on using the changeset viewer.