[281] | 1 | % -------------------------------------------------------------------- |
---|
| 2 | % --- read a GUI with handle 'handle' producing a structure 'struct' |
---|
| 3 | function struct=read_GUI(handle) |
---|
[287] | 4 | struct=[];%default |
---|
[281] | 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 |
---|
[295] | 17 | case {'checkbox','pushbutton','radiobutton','togglebutton'} |
---|
| 18 | input=get(hchild(ichild),'Value'); |
---|
[281] | 19 | case 'edit' |
---|
| 20 | separator=regexp(tag,'_'); |
---|
| 21 | if isempty(separator) |
---|
| 22 | input=get(hchild(ichild),'Value'); |
---|
| 23 | else |
---|
| 24 | switch(tag(1:separator)) |
---|
| 25 | case 'num_' |
---|
| 26 | input=str2double(get(hchild(ichild),'String')); |
---|
| 27 | tag=tag(separator+1:end); |
---|
| 28 | %deal with undefined input: retrieve the default value stored as UserData |
---|
| 29 | if isnan(input) |
---|
| 30 | input=get(hchild(ichild),'UserData'); |
---|
| 31 | set(hchild(ichild),'String',num2str(input)) |
---|
| 32 | end |
---|
| 33 | case 'txt_' |
---|
| 34 | input=get(hchild(ichild),'String'); |
---|
| 35 | tag=tag(separator+1:end); |
---|
| 36 | otherwise |
---|
| 37 | input=get(hchild(ichild),'String'); |
---|
| 38 | end |
---|
| 39 | end |
---|
[295] | 40 | |
---|
[281] | 41 | % key=tag(7:end); |
---|
[295] | 42 | case{'Listbox','popupmenu'} |
---|
| 43 | listinput=get(hchild(ichild),'String'); |
---|
| 44 | value=get(hchild(ichild),'Value'); |
---|
| 45 | input=listinput(value); |
---|
[281] | 46 | otherwise |
---|
| 47 | check_input=0; |
---|
| 48 | end |
---|
| 49 | if check_input |
---|
[292] | 50 | struct.(tag)=input; |
---|
| 51 | % eval(['struct.' tag '=input;']) |
---|
[281] | 52 | end |
---|
| 53 | end |
---|
| 54 | end |
---|
| 55 | end |
---|