source: trunk/src/fill_GUI.m @ 581

Last change on this file since 581 was 569, checked in by sommeria, 11 years ago

many corrections; introduction of browse_data to scan the whole set of data, used also to replicate data in calibration mode

File size: 4.0 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        check_done=0;
34        if isfield(handles,fields{ifield})
35            hh=handles.(fields{ifield});
36            if strcmp(get(hh,'Type'),'uitable')
37                set(hh,'Visible','on')
38                if ischar(input_data)
39                    input_data={input_data};% transform string to a single cell if needed
40                end
41                set(hh,'Data',input_data)
42                check_done=1;
43            end
44        elseif isnumeric(input_data)
45            if numel(input_data)>1
46                %deals with array displayed in multiple boxes labeled by an index
47                for ibox=1:numel(input_data)
48                    if isfield(handles,['num_' fields{ifield} '_' num2str(ibox)])
49                        hh(ibox)=handles.(['num_' fields{ifield} '_' num2str(ibox)]);
50                    end
51                end
52            else % single box (usual case)
53               if isfield(handles,['num_' fields{ifield}])
54                   hh=handles.(['num_' fields{ifield}]);
55               end
56            end
57        end
58        for ibox=1:numel(hh)
59        if ~isempty(hh(ibox))&& ~check_done
60            set(hh(ibox),'Visible','on')
61%             input_data
62            switch get(hh(ibox),'Style')
63                case {'checkbox','radiobutton','togglebutton'}
64                    if isnumeric(input_data)
65                        set(hh(ibox),'Value',input_data(ibox))
66                    end
67                case 'edit'
68                    input_string='';
69                    if isnumeric(input_data)
70                        if numel(input_data)>0
71                        input_string=num2str(input_data(ibox));
72                        end
73                    else
74                        input_string=input_data;
75                    end
76                    set(hh(ibox),'String',input_string)
77                case{'listbox','popupmenu'}
78                    if isnumeric(input_data)
79                        input_data=num2str(input_data);
80                    end
81                    menu=get(hh(ibox),'String');
82                    if ischar(input_data)
83                        input_data={input_data};
84                    end
85                    values=zeros(size(input_data));
86                    for idata=1:numel(input_data)
87                        iline=find(strcmp(input_data{idata},menu));
88                        if isempty(iline)
89                            values(idata)=1;
90                            menu=[input_data(idata);menu];
91                        else
92                            values(idata)=iline(1);
93                        end
94                    end
95                    set(hh(ibox),'String',menu)
96                    set(hh(ibox),'Value',values)
97            end
98        end
99        end
100    end
101end
102 
Note: See TracBrowser for help on using the repository browser.