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