[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) |
---|
[323] | 23 | input=get(hchild(ichild),'String'); |
---|
[281] | 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'); |
---|
[323] | 46 | if ~isempty(listinput) |
---|
[309] | 47 | input=listinput(value); |
---|
[323] | 48 | end |
---|
[309] | 49 | separator=regexp(tag,'_'); |
---|
| 50 | if strcmp(tag(1:separator),'num_') |
---|
| 51 | input=str2double(input);% transform to numerical values if the uicontrol tag begins with 'num_' |
---|
| 52 | tag=tag(separator+1:end); |
---|
| 53 | end |
---|
[281] | 54 | otherwise |
---|
| 55 | check_input=0; |
---|
| 56 | end |
---|
| 57 | if check_input |
---|
[292] | 58 | struct.(tag)=input; |
---|
| 59 | % eval(['struct.' tag '=input;']) |
---|
[281] | 60 | end |
---|
| 61 | end |
---|
| 62 | end |
---|
| 63 | end |
---|