source: trunk/src/read_GUI.m @ 364

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

civ2 introduced in civ_matlab (still bugs)
bugs corrected in civ and fill_GUI, read_GUI
comments in get_field

File size: 2.5 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','radiobutton','togglebutton'}
19                        input=get(hchild(ichild),'Value');
20                    case 'edit'
21                        separator=regexp(tag,'^num_');
22                        if isempty(separator)
23                            input=get(hchild(ichild),'String');
24                        else
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))
31                            end
32                        end                       
33                    case{'listbox','popupmenu'}
34                        listinput=get(hchild(ichild),'String');
35                        value=get(hchild(ichild),'Value');
36                        if ~isempty(listinput)
37                            input=listinput{value};
38                        else
39                            check_input=0;
40                        end
41                        separator=regexp(tag,'^num_');
42                        if ~isempty(separator)
43                            input=str2double(input);% transform to numerical values if the uicontrol tag begins with 'num_'
44                            tag=regexprep(tag,'^num_','');
45                        end
46                    otherwise
47                        check_input=0;
48                end
49                if check_input
50                    struct.(tag)=input;
51                end
52            case 'uitable'
53                struct.(tag)=get(hchild(ichild),'Data');
54        end
55    end
56end
Note: See TracBrowser for help on using the repository browser.