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
RevLine 
[380]1%'fill_GUI': fill a GUI with handles 'handles' from input data Param
[360]2% -----------------------------------------------------------------------
3function errormsg=fill_GUI(Param,handles)
4%------------------------------------------------------------------------
5errormsg='';
[461]6fields=fieldnames(Param);%list of fields in Param
[472]7% loop on the elements of the input structure Param
[360]8for ifield=1:numel(fields)
[472]9    if isstruct(Param.(fields{ifield}))% case of sa sub-structure
[360]10        if isfield(handles,fields{ifield})
[361]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
[472]16            errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
[360]17        end
18    else
[361]19        hh=[];
[472]20        input_data=Param.(fields{ifield})
[379]21        check_done=0;
[361]22        if isfield(handles,fields{ifield})
[472]23            hh=handles.(fields{ifield})
[361]24            if strcmp(get(hh,'Type'),'uitable')
[379]25                set(hh,'Visible','on')
[427]26                if ischar(input_data)
[460]27                    input_data={input_data};% transform string to a single cell if needed
[427]28                end
[363]29                set(hh,'Data',input_data)
[379]30                check_done=1;
[360]31            end
[363]32        elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}])
[361]33            hh=handles.(['num_' fields{ifield}]);
34        end
[379]35        if ~isempty(hh)&& ~check_done
[361]36            set(hh,'Visible','on')
[368]37%             input_data
[379]38            switch get(hh,'Style')
[363]39                case {'checkbox','radiobutton','togglebutton'}
40                    if isnumeric(input_data)
41                        set(hh,'Value',input_data)
[361]42                    end
43                case 'edit'
[363]44                    if isnumeric(input_data)
45                        input_data=num2str(input_data);
[361]46                    end
[363]47                    set(hh,'String',input_data)
[472]48                case{'listbox','popupmenu'}
49                    input_data
[363]50                    if isnumeric(input_data)
51                        input_data=num2str(input_data);
[361]52                    end
53                    menu=get(hh,'String');
[472]54                    if ischar(input_data)
55                        input_data={input_data};
[361]56                    end
[472]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)
[360]69            end
70        end
71    end
72end
73 
Note: See TracBrowser for help on using the repository browser.