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