[497] | 1 | %'fill_GUI': fill a GUI with a set of parameters from a Matlab structure |
---|
[360] | 2 | % ----------------------------------------------------------------------- |
---|
[497] | 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 | % |
---|
[360] | 13 | function errormsg=fill_GUI(Param,handles) |
---|
| 14 | %------------------------------------------------------------------------ |
---|
| 15 | errormsg=''; |
---|
[461] | 16 | fields=fieldnames(Param);%list of fields in Param |
---|
[472] | 17 | % loop on the elements of the input structure Param |
---|
[360] | 18 | for ifield=1:numel(fields) |
---|
[472] | 19 | if isstruct(Param.(fields{ifield}))% case of sa sub-structure |
---|
[360] | 20 | if isfield(handles,fields{ifield}) |
---|
[361] | 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 |
---|
[472] | 26 | errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure |
---|
[360] | 27 | end |
---|
| 28 | else |
---|
[361] | 29 | hh=[]; |
---|
[497] | 30 | input_data=Param.(fields{ifield}); |
---|
[379] | 31 | check_done=0; |
---|
[361] | 32 | if isfield(handles,fields{ifield}) |
---|
[497] | 33 | hh=handles.(fields{ifield}); |
---|
[361] | 34 | if strcmp(get(hh,'Type'),'uitable') |
---|
[379] | 35 | set(hh,'Visible','on') |
---|
[427] | 36 | if ischar(input_data) |
---|
[460] | 37 | input_data={input_data};% transform string to a single cell if needed |
---|
[427] | 38 | end |
---|
[363] | 39 | set(hh,'Data',input_data) |
---|
[379] | 40 | check_done=1; |
---|
[360] | 41 | end |
---|
[363] | 42 | elseif isnumeric(input_data) && isfield(handles,['num_' fields{ifield}]) |
---|
[361] | 43 | hh=handles.(['num_' fields{ifield}]); |
---|
| 44 | end |
---|
[379] | 45 | if ~isempty(hh)&& ~check_done |
---|
[361] | 46 | set(hh,'Visible','on') |
---|
[368] | 47 | % input_data |
---|
[379] | 48 | switch get(hh,'Style') |
---|
[363] | 49 | case {'checkbox','radiobutton','togglebutton'} |
---|
| 50 | if isnumeric(input_data) |
---|
| 51 | set(hh,'Value',input_data) |
---|
[361] | 52 | end |
---|
| 53 | case 'edit' |
---|
[363] | 54 | if isnumeric(input_data) |
---|
| 55 | input_data=num2str(input_data); |
---|
[361] | 56 | end |
---|
[363] | 57 | set(hh,'String',input_data) |
---|
[472] | 58 | case{'listbox','popupmenu'} |
---|
[363] | 59 | if isnumeric(input_data) |
---|
| 60 | input_data=num2str(input_data); |
---|
[361] | 61 | end |
---|
| 62 | menu=get(hh,'String'); |
---|
[472] | 63 | if ischar(input_data) |
---|
| 64 | input_data={input_data}; |
---|
[361] | 65 | end |
---|
[472] | 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) |
---|
[476] | 70 | values(idata)=1; |
---|
| 71 | menu=[input_data(idata);menu]; |
---|
[472] | 72 | else |
---|
[476] | 73 | values(idata)=iline(1); |
---|
[472] | 74 | end |
---|
| 75 | end |
---|
[476] | 76 | set(hh,'String',menu) |
---|
[472] | 77 | set(hh,'Value',values) |
---|
[360] | 78 | end |
---|
| 79 | end |
---|
| 80 | end |
---|
| 81 | end |
---|
| 82 | |
---|