source: trunk/src/read_GUI.m @ 309

Last change on this file since 309 was 309, checked in by sommeria, 12 years ago

many bugs corrected, cleaning of civ.m, resize of the GUI civ

File size: 2.9 KB
Line 
1% -----------------------------------------------------------------------
2% --- read a GUI with handle 'handle' producing a structure 'struct'
3function struct=read_GUI(handle)
4%------------------------------------------------------------------------
5struct=[];%default
6hchild=get(handle,'children');
7for 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
18                    case {'checkbox','pushbutton','radiobutton','togglebutton'}
19                        input=get(hchild(ichild),'Value');
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
41
42                        %                         key=tag(7:end);
43                    case{'Listbox','popupmenu'}
44                        listinput=get(hchild(ichild),'String');
45                        value=get(hchild(ichild),'Value');
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
52                    otherwise
53                        check_input=0;
54                end
55                if check_input
56                    struct.(tag)=input;
57                  %  eval(['struct.' tag '=input;'])
58                end
59        end
60    end
61end
Note: See TracBrowser for help on using the repository browser.