| 1 | %'fill_GUI': fill a GUI with handles 'handles' from input data Param |
|---|
| 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}) |
|---|
| 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); |
|---|
| 16 | end |
|---|
| 17 | else |
|---|
| 18 | hh=[]; |
|---|
| 19 | input_data=Param.(fields{ifield}); |
|---|
| 20 | check_done=0; |
|---|
| 21 | if isfield(handles,fields{ifield}) |
|---|
| 22 | hh=handles.(fields{ifield}); |
|---|
| 23 | if strcmp(get(hh,'Type'),'uitable') |
|---|
| 24 | set(hh,'Visible','on') |
|---|
| 25 | if ischar(input_data) |
|---|
| 26 | input_data={input_data}% transform string to a single cell if needed |
|---|
| 27 | end |
|---|
| 28 | set(hh,'Data',input_data) |
|---|
| 29 | check_done=1; |
|---|
| 30 | end |
|---|
| 31 | elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}]) |
|---|
| 32 | hh=handles.(['num_' fields{ifield}]); |
|---|
| 33 | end |
|---|
| 34 | if ~isempty(hh)&& ~check_done |
|---|
| 35 | set(hh,'Visible','on') |
|---|
| 36 | % input_data |
|---|
| 37 | switch get(hh,'Style') |
|---|
| 38 | case {'checkbox','radiobutton','togglebutton'} |
|---|
| 39 | if isnumeric(input_data) |
|---|
| 40 | set(hh,'Value',input_data) |
|---|
| 41 | end |
|---|
| 42 | case 'edit' |
|---|
| 43 | if isnumeric(input_data) |
|---|
| 44 | input_data=num2str(input_data); |
|---|
| 45 | end |
|---|
| 46 | set(hh,'String',input_data) |
|---|
| 47 | case{'Listbox','popupmenu'} |
|---|
| 48 | if isnumeric(input_data) |
|---|
| 49 | input_data=num2str(input_data); |
|---|
| 50 | end |
|---|
| 51 | menu=get(hh,'String'); |
|---|
| 52 | iline=find(strcmp(input_data,menu)); |
|---|
| 53 | if isempty(iline) |
|---|
| 54 | iline=numel(menu)+1; |
|---|
| 55 | set(hh,'String',[menu;{input_data}]) |
|---|
| 56 | end |
|---|
| 57 | set(hh,'Value',iline) |
|---|
| 58 | end |
|---|
| 59 | end |
|---|
| 60 | end |
|---|
| 61 | end |
|---|
| 62 | |
|---|