source: trunk/src/fill_GUI.m @ 497

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

cleaning and small bug repair.
pb of histogram for filter data solved
display of uicontrol by right mouse selection improved

File size: 3.2 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    if isstruct(Param.(fields{ifield}))% case of sa sub-structure
20        if isfield(handles,fields{ifield})
21            set(handles.(fields{ifield}),'Visible','on')
22            children=get(handles.(fields{ifield}),'children');
23            for ichild=1:numel(children)
24                hchild.(get(children(ichild),'tag'))=children(ichild);
25            end
26            errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
27        end
28    else
29        hh=[];
30        input_data=Param.(fields{ifield});
31        check_done=0;
32        if isfield(handles,fields{ifield})
33            hh=handles.(fields{ifield});
34            if strcmp(get(hh,'Type'),'uitable')
35                set(hh,'Visible','on')
36                if ischar(input_data)
37                    input_data={input_data};% transform string to a single cell if needed
38                end
39                set(hh,'Data',input_data)
40                check_done=1;
41            end
42        elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}])
43            hh=handles.(['num_' fields{ifield}]);
44        end
45        if ~isempty(hh)&& ~check_done
46            set(hh,'Visible','on')
47%             input_data
48            switch get(hh,'Style')
49                case {'checkbox','radiobutton','togglebutton'}
50                    if isnumeric(input_data)
51                        set(hh,'Value',input_data)
52                    end
53                case 'edit'
54                    if isnumeric(input_data)
55                        input_data=num2str(input_data);
56                    end
57                    set(hh,'String',input_data)
58                case{'listbox','popupmenu'}
59                    if isnumeric(input_data)
60                        input_data=num2str(input_data);
61                    end
62                    menu=get(hh,'String');
63                    if ischar(input_data)
64                        input_data={input_data};
65                    end
66                    values=zeros(size(input_data));
67                    for idata=1:numel(input_data)
68                        iline=find(strcmp(input_data{idata},menu));
69                        if isempty(iline)
70                            values(idata)=1;
71                            menu=[input_data(idata);menu];
72                        else
73                            values(idata)=iline(1);
74                        end
75                    end
76                    set(hh,'String',menu)
77                    set(hh,'Value',values)
78            end
79        end
80    end
81end
82 
Note: See TracBrowser for help on using the repository browser.