source: trunk/src/fill_GUI.m @ 501

Last change on this file since 501 was 500, checked in by sommeria, 12 years ago

various bug corrections

File size: 3.9 KB
RevLine 
[497]1%'fill_GUI': fill a GUI with a set of parameters from a Matlab structure
[360]2% -----------------------------------------------------------------------
[497]3% function errormsg=fill_GUI(Param,handles)
4% OUPUT:
5% errormsg: error message, ='' by default
6%
7% INPUT:
8% Param: matlab structure containing the information to display in the GUI
9% handles: Matlab structure containing the handles of the GUI elements
10%
11% see also the reverse function read_GUI.m
12%
[360]13function errormsg=fill_GUI(Param,handles)
14%------------------------------------------------------------------------
15errormsg='';
[461]16fields=fieldnames(Param);%list of fields in Param
[472]17% loop on the elements of the input structure Param
[360]18for ifield=1:numel(fields)
[500]19    % case of a sub-structure --> fill a panel
20    if isstruct(Param.(fields{ifield}))% case of a sub-structure
[360]21        if isfield(handles,fields{ifield})
[361]22            set(handles.(fields{ifield}),'Visible','on')
23            children=get(handles.(fields{ifield}),'children');
24            for ichild=1:numel(children)
25                hchild.(get(children(ichild),'tag'))=children(ichild);
26            end
[472]27            errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
[360]28        end
[500]29    % case of an element
[360]30    else
[361]31        hh=[];
[497]32        input_data=Param.(fields{ifield});
[500]33                    display(fields{ifield})
34                    display(input_data)
[379]35        check_done=0;
[361]36        if isfield(handles,fields{ifield})
[497]37            hh=handles.(fields{ifield});
[361]38            if strcmp(get(hh,'Type'),'uitable')
[379]39                set(hh,'Visible','on')
[427]40                if ischar(input_data)
[460]41                    input_data={input_data};% transform string to a single cell if needed
[427]42                end
[363]43                set(hh,'Data',input_data)
[379]44                check_done=1;
[360]45            end
[500]46        elseif isnumeric(input_data)
47            if numel(input_data)>1
48                %deals with array displayed in multiple boxes labeled by an index
49                for ibox=1:numel(input_data)
50                    if isfield(handles,['num_' fields{ifield} '_' num2str(ibox)])
51                        hh(ibox)=handles.(['num_' fields{ifield} '_' num2str(ibox)]);
52                    end
53                end
54            else % single box (usual case)
55               if isfield(handles,['num_' fields{ifield}])
56                   hh=handles.(['num_' fields{ifield}]);
57               end
58            end
[361]59        end
[500]60        for ibox=1:numel(hh)
61        if ~isempty(hh(ibox))&& ~check_done
62            set(hh(ibox),'Visible','on')
[368]63%             input_data
[500]64            switch get(hh(ibox),'Style')
[363]65                case {'checkbox','radiobutton','togglebutton'}
66                    if isnumeric(input_data)
[500]67                        set(hh(ibox),'Value',input_data(ibox))
[361]68                    end
69                case 'edit'
[363]70                    if isnumeric(input_data)
[500]71                        input_string=num2str(input_data(ibox));
72                    else
73                        input_string=input_data;
[361]74                    end
[500]75                    set(hh(ibox),'String',input_string)
[472]76                case{'listbox','popupmenu'}
[363]77                    if isnumeric(input_data)
78                        input_data=num2str(input_data);
[361]79                    end
[500]80                    menu=get(hh(ibox),'String');
[472]81                    if ischar(input_data)
82                        input_data={input_data};
[361]83                    end
[472]84                    values=zeros(size(input_data));
85                    for idata=1:numel(input_data)
86                        iline=find(strcmp(input_data{idata},menu));
87                        if isempty(iline)
[476]88                            values(idata)=1;
89                            menu=[input_data(idata);menu];
[472]90                        else
[476]91                            values(idata)=iline(1);
[472]92                        end
93                    end
[500]94                    set(hh(ibox),'String',menu)
95                    set(hh(ibox),'Value',values)
[360]96            end
97        end
[500]98        end
[360]99    end
100end
101 
Note: See TracBrowser for help on using the repository browser.