[380] | 1 | %'fill_GUI': fill a GUI with handles 'handles' from input data Param |
---|
[360] | 2 | % ----------------------------------------------------------------------- |
---|
| 3 | function errormsg=fill_GUI(Param,handles) |
---|
| 4 | %------------------------------------------------------------------------ |
---|
| 5 | errormsg=''; |
---|
| 6 | fields=fieldnames(Param); |
---|
| 7 | for ifield=1:numel(fields) |
---|
| 8 | if isstruct(Param.(fields{ifield})) |
---|
| 9 | if isfield(handles,fields{ifield}) |
---|
[361] | 10 | set(handles.(fields{ifield}),'Visible','on') |
---|
| 11 | children=get(handles.(fields{ifield}),'children'); |
---|
| 12 | for ichild=1:numel(children) |
---|
| 13 | hchild.(get(children(ichild),'tag'))=children(ichild); |
---|
| 14 | end |
---|
| 15 | errormsg=fill_GUI(Param.(fields{ifield}),hchild); |
---|
[360] | 16 | end |
---|
| 17 | else |
---|
[361] | 18 | hh=[]; |
---|
[363] | 19 | input_data=Param.(fields{ifield}); |
---|
[379] | 20 | check_done=0; |
---|
[361] | 21 | if isfield(handles,fields{ifield}) |
---|
| 22 | hh=handles.(fields{ifield}); |
---|
| 23 | if strcmp(get(hh,'Type'),'uitable') |
---|
[379] | 24 | set(hh,'Visible','on') |
---|
[427] | 25 | if ischar(input_data) |
---|
| 26 | input_data={input_data}% transform string to a single cell if needed |
---|
| 27 | end |
---|
[363] | 28 | set(hh,'Data',input_data) |
---|
[379] | 29 | check_done=1; |
---|
[360] | 30 | end |
---|
[363] | 31 | elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}]) |
---|
[361] | 32 | hh=handles.(['num_' fields{ifield}]); |
---|
| 33 | end |
---|
[379] | 34 | if ~isempty(hh)&& ~check_done |
---|
[361] | 35 | set(hh,'Visible','on') |
---|
[368] | 36 | % input_data |
---|
[379] | 37 | switch get(hh,'Style') |
---|
[363] | 38 | case {'checkbox','radiobutton','togglebutton'} |
---|
| 39 | if isnumeric(input_data) |
---|
| 40 | set(hh,'Value',input_data) |
---|
[361] | 41 | end |
---|
| 42 | case 'edit' |
---|
[363] | 43 | if isnumeric(input_data) |
---|
| 44 | input_data=num2str(input_data); |
---|
[361] | 45 | end |
---|
[363] | 46 | set(hh,'String',input_data) |
---|
[361] | 47 | case{'Listbox','popupmenu'} |
---|
[363] | 48 | if isnumeric(input_data) |
---|
| 49 | input_data=num2str(input_data); |
---|
[361] | 50 | end |
---|
| 51 | menu=get(hh,'String'); |
---|
[363] | 52 | iline=find(strcmp(input_data,menu)); |
---|
[361] | 53 | if isempty(iline) |
---|
| 54 | iline=numel(menu)+1; |
---|
[363] | 55 | set(hh,'String',[menu;{input_data}]) |
---|
[361] | 56 | end |
---|
| 57 | set(hh,'Value',iline) |
---|
[360] | 58 | end |
---|
| 59 | end |
---|
| 60 | end |
---|
| 61 | end |
---|
| 62 | |
---|