source: trunk/src/fill_GUI.m @ 527

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

improvement of calc-field and combination of two fields

File size: 4.1 KB
Line 
1%'fill_GUI': fill a GUI with a set of parameters from a Matlab structure
2% -----------------------------------------------------------------------
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%
13function errormsg=fill_GUI(Param,handles)
14%------------------------------------------------------------------------
15errormsg='';
16fields=fieldnames(Param);%list of fields in Param
17% loop on the elements of the input structure Param
18for ifield=1:numel(fields)
19    % case of a sub-structure --> fill a panel
20    if isstruct(Param.(fields{ifield}))% case of a sub-structure
21        if isfield(handles,fields{ifield})
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
27            errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
28        end
29    % case of an element
30    else
31        hh=[];
32        input_data=Param.(fields{ifield});
33%                     display(fields{ifield})
34%                     display(input_data)
35        check_done=0;
36        if isfield(handles,fields{ifield})
37            hh=handles.(fields{ifield});
38            if strcmp(get(hh,'Type'),'uitable')
39                set(hh,'Visible','on')
40                if ischar(input_data)
41                    input_data={input_data};% transform string to a single cell if needed
42                end
43                set(hh,'Data',input_data)
44                check_done=1;
45            end
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
59        end
60        for ibox=1:numel(hh)
61        if ~isempty(hh(ibox))&& ~check_done
62            set(hh(ibox),'Visible','on')
63%             input_data
64            switch get(hh(ibox),'Style')
65                case {'checkbox','radiobutton','togglebutton'}
66                    if isnumeric(input_data)
67                        set(hh(ibox),'Value',input_data(ibox))
68                    end
69                case 'edit'
70                    input_string='';
71                    if isnumeric(input_data)
72                        if numel(input_data)>0
73                        input_string=num2str(input_data(ibox));
74                        end
75                    else
76                        input_string=input_data;
77                    end
78                    set(hh(ibox),'String',input_string)
79                case{'listbox','popupmenu'}
80                    if isnumeric(input_data)
81                        input_data=num2str(input_data);
82                    end
83                    menu=get(hh(ibox),'String');
84                    if ischar(input_data)
85                        input_data={input_data};
86                    end
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)
91                            values(idata)=1;
92                            menu=[input_data(idata);menu];
93                        else
94                            values(idata)=iline(1);
95                        end
96                    end
97                    set(hh(ibox),'String',menu)
98                    set(hh(ibox),'Value',values)
99            end
100        end
101        end
102    end
103end
104 
Note: See TracBrowser for help on using the repository browser.