📄 fmri_getfiles.m
字号:
function [num_scans,selected_path,selected_files,filter_pattern] = ...
fmri_getfiles(varargin)
%
% USAGE: [selected_path,selected_files,filter_pattern] = ...
% fmri_getfiles(fig_title,dirname,pattern,selected_files)
%
% Allow user to select a set of files from a single directory.
%
% Example:
%
% [num_scans,s_path,s_files] = ...
% fmri_getfiles('Select Data File','/usr','*.img');
%
%
% -- Created June 2001 by Wilkin Chau, Rotman Research Institute
%
if nargin == 0 | ischar(varargin{1}) % create fmri_getfiles figure
dir_name = '';
filter_pattern = '*';
selected_files = [];
if (nargin == 0),
fig_title = 'Select Files';
else
fig_title = varargin{1};
if (nargin > 1), dir_name = varargin{2}; end;
if (nargin > 2), filter_pattern = varargin{3}; end;
if (nargin > 3), selected_files = varargin{4}; end;
end;
init(fig_title,dir_name,filter_pattern,selected_files);
uiwait; % wait for user finish
h = findobj(gcf,'Tag','FileList');
list_files = get(h,'String');
if isempty(list_files)
selected_files = [];
else
selected_idx = get(h,'Value');
selected_files = list_files(selected_idx);
end;
num_scans = getappdata(gcf,'NumScans');
selected_path = getappdata(gcf,'SelectedDirectory');
filter_pattern = getappdata(gcf,'FilterPattern');
cd(getappdata(gcf,'StartDirectory'));
close(gcf);
return;
end;
% clear the message line,
%
h = findobj(gcf,'Tag','MessageLine');
set(h,'String','');
action = varargin{1}{1};
if strcmp(action,'CreateEditFilter'),
filter_pattern = getappdata(gcf,'FilterPattern');
dir_name = pwd;
if isempty(dir_name),
dir_name = filesep;
end;
set(gcbo,'String',fullfile(dir_name, filter_pattern));
elseif strcmp(action,'UpdateDirectoryList'),
UpdateDirectoryList;
elseif strcmp(action,'UpdateFileList'),
UpdateFileList;
elseif strcmp(action,'EditFilter'),
EditFilter;
elseif strcmp(action,'delete_fig'),
delete_fig;
elseif strcmp(action,'SELECT_BUTTON_PRESSED'),
SelectAllFiles;
elseif strcmp(action,'DONE_BUTTON_PRESSED'),
h = findobj(gcf,'Tag','NumFiles');
NumFiles = get(h,'value');
h = findobj(gcf,'Tag','NumScans');
NumScans = get(h,'value');
if (NumFiles==1 & NumScans>=1) | (NumFiles>1 & NumScans==NumFiles)
h = findobj(gcf,'Tag','FilterEdit');
[filepath,filename,fileext] = fileparts(get(h,'String'));
setappdata(gcf,'NumScans',NumScans);
setappdata(gcf,'SelectedDirectory',filepath);
setappdata(gcf,'FilterPattern',[filename fileext]);
uiresume;
else
msg = 'Accept only 1 multiple scan file or more single scan file.';
set(findobj(gcf,'Tag','MessageLine'),'String',msg);
return;
end
elseif strcmp(action,'CANCEL_BUTTON_PRESSED'),
setappdata(gcf,'NumScans',[]);
setappdata(gcf,'SelectedDirectory',[]);
setappdata(gcf,'FilterPattern',[]);
set(findobj(gcf,'Tag','FileList'),'String','');
uiresume;
end;
return;
% --------------------------------------------------------------------
function init(fig_title,dir_name,filter_pattern,selected_files),
StartDirectory = pwd;
if isempty(StartDirectory),
StartDirectory = filesep;
end;
save_setting_status = 'on';
fmri_getfiles_pos = [];
try
load('pls_profile');
catch
end
if ~isempty(fmri_getfiles_pos) & strcmp(save_setting_status,'on')
pos = fmri_getfiles_pos;
else
w = 0.55;
h = 0.7;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
end
h0 = figure('parent',0, 'Color',[0.8 0.8 0.8], ...
'Units','normal', ...
'Name',fig_title, ...
'NumberTitle','off', ...
'MenuBar','none', ...
'Position',pos, ...
'deleteFcn','fmri_getfiles({''delete_fig''});', ...
'WindowStyle', 'modal', ...
'Tag','GetFilesFigure', ...
'ToolBar','none');
left_margin = 0.06;
text_height = 0.06;
x = left_margin;
y = 0.9;
w = 1 - x*2;
h = text_height;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Filter Label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','Filter', ...
'Tag','FilterLabel');
y = y-.06;
pos = [x y w h];
e_h = uicontrol('Parent',h0, ... % Filter Edit
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'fontunit','normal', ...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String', '', ...
'CreateFcn','fmri_getfiles({''CreateEditFilter''});', ...
'Callback','fmri_getfiles({''EditFilter''});', ...
'Tag','FilterEdit');
y = y -.08;
w = .5 - left_margin - .02;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Directory Label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal',...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Directories', ...
'Tag','DirectoryLabel');
x = .5;
w = .5 - left_margin;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % File Label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Files', ...
'Tag','FileLabel');
x = left_margin;
y = .25;
w = .5 - left_margin - .02;
h = .5;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Directory Listbox
'Style','listbox', ...
'Units','normal', ...
'fontunit','normal',...
'FontSize',.06, ...
'HorizontalAlignment','left', ...
'Interruptible', 'off', ...
'ListboxTop',1, ...
'Position',pos, ...
'String', '', ...
'Value',[], ...
'Callback','fmri_getfiles({''UpdateDirectoryList''});', ...
'Tag','DirectoryList');
x = .5;
w = .5 - left_margin;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % File Listbox
'Style','listbox', ...
'Units','normal', ...
'fontunit','normal', ...
'FontSize',.06, ...
'Min',0, ...
'Max',10, ...
'HorizontalAlignment','left', ...
'ListboxTop',1, ...
'Position',pos, ...
'String', '', ...
'CreateFcn','fmri_getfiles({''CreateFileList''});', ...
'Callback','fmri_getfiles({''UpdateFileList''});', ...
'Tag','FileList');
x = left_margin;
y = y - .08;
w = .3;
h = text_height;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Number of Selected Files
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'ListboxTop',1, ...
'Position',pos, ...
'String', 'Selected Files: ', ...
'value', [], ...
'Tag','NumFiles');
x = x + w;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % Number of Selected Scans
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',.5, ...
'HorizontalAlignment','left', ...
'ListboxTop',1, ...
'Position',pos, ...
'String', 'Selected Scans: ', ...
'value', [], ...
'Tag','NumScans');
w = .2;
x = 1 - left_margin - w;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % SELECT
'Units','normal', ...
'fontunit','normal',...
'FontSize',.5, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
'String','Select All', ...
'Callback','fmri_getfiles({''SELECT_BUTTON_PRESSED''});', ...
'Tag','SELECTButton');
x = left_margin + .15;
y = y - .08;
w = .2;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % DONE
'Units','normal', ...
'fontunit','normal',...
'FontSize',.5, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -