[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 |
---|
[363] | 18 | case {'checkbox','radiobutton','togglebutton'} |
---|
[295] | 19 | input=get(hchild(ichild),'Value'); |
---|
[281] | 20 | case 'edit' |
---|
[363] | 21 | separator=regexp(tag,'^num_'); |
---|
[281] | 22 | if isempty(separator) |
---|
[323] | 23 | input=get(hchild(ichild),'String'); |
---|
[281] | 24 | else |
---|
[363] | 25 | input=str2double(get(hchild(ichild),'String')); |
---|
| 26 | tag=regexprep(tag,'^num_',''); |
---|
| 27 | %deal with undefined input: retrieve the default value stored as UserData |
---|
| 28 | if isnan(input) |
---|
| 29 | input=get(hchild(ichild),'UserData'); |
---|
| 30 | set(hchild(ichild),'String',num2str(input)) |
---|
[281] | 31 | end |
---|
[363] | 32 | end |
---|
| 33 | case{'listbox','popupmenu'} |
---|
[295] | 34 | listinput=get(hchild(ichild),'String'); |
---|
| 35 | value=get(hchild(ichild),'Value'); |
---|
[323] | 36 | if ~isempty(listinput) |
---|
[363] | 37 | input=listinput{value}; |
---|
| 38 | else |
---|
| 39 | check_input=0; |
---|
[323] | 40 | end |
---|
[363] | 41 | separator=regexp(tag,'^num_'); |
---|
| 42 | if ~isempty(separator) |
---|
[309] | 43 | input=str2double(input);% transform to numerical values if the uicontrol tag begins with 'num_' |
---|
[363] | 44 | tag=regexprep(tag,'^num_',''); |
---|
[309] | 45 | end |
---|
[281] | 46 | otherwise |
---|
| 47 | check_input=0; |
---|
| 48 | end |
---|
| 49 | if check_input |
---|
[292] | 50 | struct.(tag)=input; |
---|
[281] | 51 | end |
---|
[350] | 52 | case 'uitable' |
---|
[363] | 53 | struct.(tag)=get(hchild(ichild),'Data'); |
---|
[281] | 54 | end |
---|
| 55 | end |
---|
| 56 | end |
---|