1 | % ----------------------------------------------------------------------- |
---|
2 | % --- read a GUI with handle 'handle' producing a structure 'struct' |
---|
3 | function errormsg=fill_GUI(Param,handles) |
---|
4 | %------------------------------------------------------------------------ |
---|
5 | |
---|
6 | errormsg=''; |
---|
7 | fields=fieldnames(Param); |
---|
8 | for ifield=1:numel(fields) |
---|
9 | if isstruct(Param.(fields{ifield})) |
---|
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); |
---|
17 | end |
---|
18 | else |
---|
19 | hh=[]; |
---|
20 | input_data=Param.(fields{ifield}); |
---|
21 | if isfield(handles,fields{ifield}) |
---|
22 | hh=handles.(fields{ifield}); |
---|
23 | if strcmp(get(hh,'Type'),'uitable') |
---|
24 | set(hh,'Data',input_data) |
---|
25 | break |
---|
26 | end |
---|
27 | elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}]) |
---|
28 | hh=handles.(['num_' fields{ifield}]); |
---|
29 | end |
---|
30 | if ~isempty(hh) |
---|
31 | set(hh,'Visible','on') |
---|
32 | % input_data |
---|
33 | switch get(hh,'style') |
---|
34 | case {'checkbox','radiobutton','togglebutton'} |
---|
35 | if isnumeric(input_data) |
---|
36 | set(hh,'Value',input_data) |
---|
37 | end |
---|
38 | case 'edit' |
---|
39 | if isnumeric(input_data) |
---|
40 | input_data=num2str(input_data); |
---|
41 | end |
---|
42 | set(hh,'String',input_data) |
---|
43 | case{'Listbox','popupmenu'} |
---|
44 | if isnumeric(input_data) |
---|
45 | input_data=num2str(input_data); |
---|
46 | end |
---|
47 | menu=get(hh,'String'); |
---|
48 | iline=find(strcmp(input_data,menu)); |
---|
49 | if isempty(iline) |
---|
50 | iline=numel(menu)+1; |
---|
51 | set(hh,'String',[menu;{input_data}]) |
---|
52 | end |
---|
53 | set(hh,'Value',iline) |
---|
54 | end |
---|
55 | end |
---|
56 | end |
---|
57 | end |
---|
58 | |
---|