1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
function varargout = planche_2(varargin)
if nargin <= 1 % LAUNCH GUI
if nargin == 0
initial_dir = 'base_de_donnée';
elseif nargin == 1 & exist(varargin{1},'dir')
initial_dir = varargin{1};
else
errordlg('Input argument must be a valid directory','Input Argument Error!')
return
end
% Open FIG-file
fig = openfig(mfilename,'reuse'); % Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
% Populate the listbox
load_listbox(initial_dir,handles)
% Return figure handle as first output argument
if nargout > 0
varargout{1} = fig;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
% ------------------------------------------------------------
% Callback for list box - open .fig with guide, otherwise use open
% ------------------------------------------------------------
function varargout = listbox1_Callback(h, eventdata, handles, varargin)
if strcmp(get(handles.figure1,'SelectionType'),'open')
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
filename = file_list{index_selected};
if handles.is_dir(handles.sorted_index(index_selected))
cd (filename)
load_listbox(pwd,handles)
else
[path,name,ext,ver] = fileparts(filename);
switch ext
case '.bmp'
%guide (filename)
X=imread(filename);
%set(gca,'CData',imshow(X));
%imshow(X);
imshow(X,'Parent',gca);
otherwise
try
open(filename)
catch
errordlg(lasterr,'File Type Error','modal')
end
end
end
end
% ------------------------------------------------------------
% lecture du répertoire courant
% ------------------------------------------------------------
function load_listbox(dir_path,handles)
% cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = [sorted_index];
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,'Value',1)
set(handles.text1,'String',pwd) |