| 1 | % -------------------------------------------------------------------- |
|---|
| 2 | % --- read a GUI with handle 'handle' producing a structure 'struct' |
|---|
| 3 | function struct=read_GUI(handle) |
|---|
| 4 | struct=[];%default |
|---|
| 5 | hchild=get(handle,'children'); |
|---|
| 6 | for ichild=1:numel(hchild) |
|---|
| 7 | if strcmp(get(hchild(ichild),'Visible'),'on') |
|---|
| 8 | object_type=get(hchild(ichild),'Type'); |
|---|
| 9 | tag=get(hchild(ichild),'tag'); |
|---|
| 10 | switch object_type |
|---|
| 11 | case 'uipanel' |
|---|
| 12 | eval(['struct.' tag '=read_GUI(hchild(ichild));']) |
|---|
| 13 | case 'uicontrol' |
|---|
| 14 | object_style=get(hchild(ichild),'Style'); |
|---|
| 15 | check_input=1;%default |
|---|
| 16 | switch object_style |
|---|
| 17 | case 'edit' |
|---|
| 18 | separator=regexp(tag,'_'); |
|---|
| 19 | if isempty(separator) |
|---|
| 20 | input=get(hchild(ichild),'Value'); |
|---|
| 21 | else |
|---|
| 22 | switch(tag(1:separator)) |
|---|
| 23 | case 'num_' |
|---|
| 24 | input=str2double(get(hchild(ichild),'String')); |
|---|
| 25 | tag=tag(separator+1:end); |
|---|
| 26 | %deal with undefined input: retrieve the default value stored as UserData |
|---|
| 27 | if isnan(input) |
|---|
| 28 | input=get(hchild(ichild),'UserData'); |
|---|
| 29 | set(hchild(ichild),'String',num2str(input)) |
|---|
| 30 | end |
|---|
| 31 | case 'txt_' |
|---|
| 32 | input=get(hchild(ichild),'String'); |
|---|
| 33 | tag=tag(separator+1:end); |
|---|
| 34 | otherwise |
|---|
| 35 | input=get(hchild(ichild),'String'); |
|---|
| 36 | end |
|---|
| 37 | end |
|---|
| 38 | case 'checkbox' |
|---|
| 39 | input=get(hchild(ichild),'Value'); |
|---|
| 40 | % key=tag(7:end); |
|---|
| 41 | otherwise |
|---|
| 42 | check_input=0; |
|---|
| 43 | end |
|---|
| 44 | if check_input |
|---|
| 45 | ['struct.' tag '=input;'] |
|---|
| 46 | eval(['struct.' tag '=input;']) |
|---|
| 47 | end |
|---|
| 48 | end |
|---|
| 49 | end |
|---|
| 50 | end |
|---|