source: trunk/src/fill_GUI.m @ 472

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

many bugs repaired. series set to work in mode background

File size: 2.9 KB
Line 
1%'fill_GUI': fill a GUI with handles 'handles' from input data Param
2% -----------------------------------------------------------------------
3function errormsg=fill_GUI(Param,handles)
4%------------------------------------------------------------------------
5errormsg='';
6fields=fieldnames(Param);%list of fields in Param
7% loop on the elements of the input structure Param
8for ifield=1:numel(fields)
9    if isstruct(Param.(fields{ifield}))% case of sa sub-structure
10        if isfield(handles,fields{ifield})
11            set(handles.(fields{ifield}),'Visible','on')
12            children=get(handles.(fields{ifield}),'children');
13            for ichild=1:numel(children)
14                hchild.(get(children(ichild),'tag'))=children(ichild);
15            end
16            errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
17        end
18    else
19        hh=[];
20        input_data=Param.(fields{ifield})
21        check_done=0;
22        if isfield(handles,fields{ifield})
23            hh=handles.(fields{ifield})
24            if strcmp(get(hh,'Type'),'uitable')
25                set(hh,'Visible','on')
26                if ischar(input_data)
27                    input_data={input_data};% transform string to a single cell if needed
28                end
29                set(hh,'Data',input_data)
30                check_done=1;
31            end
32        elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}])
33            hh=handles.(['num_' fields{ifield}]);
34        end
35        if ~isempty(hh)&& ~check_done
36            set(hh,'Visible','on')
37%             input_data
38            switch get(hh,'Style')
39                case {'checkbox','radiobutton','togglebutton'}
40                    if isnumeric(input_data)
41                        set(hh,'Value',input_data)
42                    end
43                case 'edit'
44                    if isnumeric(input_data)
45                        input_data=num2str(input_data);
46                    end
47                    set(hh,'String',input_data)
48                case{'listbox','popupmenu'}
49                    input_data
50                    if isnumeric(input_data)
51                        input_data=num2str(input_data);
52                    end
53                    menu=get(hh,'String');
54                    if ischar(input_data)
55                        input_data={input_data};
56                    end
57                    values=zeros(size(input_data));
58                    for idata=1:numel(input_data)
59                        iline=find(strcmp(input_data{idata},menu));
60                        if isempty(iline)
61                            values(idata)=numel(menu)+1;
62                            menu=[menu;input_data(idata)];
63                        else
64                            values(idata)=iline;
65                        end
66                    end
67                    set(hh,'String',[menu;input_data(idata)])
68                    set(hh,'Value',values)
69            end
70        end
71    end
72end
73 
Note: See TracBrowser for help on using the repository browser.