source: trunk/src/fill_GUI.m @ 529

Last change on this file since 529 was 515, checked in by sommeria, 12 years ago

improvement of calc-field and combination of two fields

File size: 4.1 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});
[515]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'
[515]70                    input_string='';
[363]71                    if isnumeric(input_data)
[515]72                        if numel(input_data)>0
[500]73                        input_string=num2str(input_data(ibox));
[515]74                        end
[500]75                    else
76                        input_string=input_data;
[361]77                    end
[500]78                    set(hh(ibox),'String',input_string)
[472]79                case{'listbox','popupmenu'}
[363]80                    if isnumeric(input_data)
81                        input_data=num2str(input_data);
[361]82                    end
[500]83                    menu=get(hh(ibox),'String');
[472]84                    if ischar(input_data)
85                        input_data={input_data};
[361]86                    end
[472]87                    values=zeros(size(input_data));
88                    for idata=1:numel(input_data)
89                        iline=find(strcmp(input_data{idata},menu));
90                        if isempty(iline)
[476]91                            values(idata)=1;
92                            menu=[input_data(idata);menu];
[472]93                        else
[476]94                            values(idata)=iline(1);
[472]95                        end
96                    end
[500]97                    set(hh(ibox),'String',menu)
98                    set(hh(ibox),'Value',values)
[360]99            end
100        end
[500]101        end
[360]102    end
103end
104 
Note: See TracBrowser for help on using the repository browser.