source: trunk/src/read_GUI.m @ 346

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

GUI uvmat modified by introduction of a pannel InputFile?, NomType? now explicitley written in a edit box NomType? on this panel.

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),'String');
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                        if ~isempty(listinput)
47                        input=listinput(value);
48                        end
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
54                    otherwise
55                        check_input=0;
56                end
57                if check_input
58                    struct.(tag)=input;
59                  %  eval(['struct.' tag '=input;'])
60                end
61        end
62    end
63end
Note: See TracBrowser for help on using the repository browser.