source: trunk/src/fill_GUI.m @ 591

Last change on this file since 591 was 591, checked in by sommeria, 11 years ago

various updates, in particular modification of series to do calculations in the cluster

File size: 4.5 KB
RevLine 
[497]1%'fill_GUI': fill a GUI with a set of parameters from a Matlab structure
[360]2% -----------------------------------------------------------------------
[591]3% function errormsg=fill_GUI(Param,GUI_handle)
[497]4% OUPUT:
5% errormsg: error message, ='' by default
6%
7% INPUT:
8% Param: matlab structure containing the information to display in the GUI
9% handles: Matlab structure containing the handles of the GUI elements
10%
11% see also the reverse function read_GUI.m
12%
[591]13function errormsg=fill_GUI(Param,GUI_handle)
[360]14%------------------------------------------------------------------------
15errormsg='';
[591]16handles=guidata(GUI_handle);
17UserData=get(GUI_handle,'UserData');
[461]18fields=fieldnames(Param);%list of fields in Param
[472]19% loop on the elements of the input structure Param
[360]20for ifield=1:numel(fields)
[500]21    % case of a sub-structure --> fill a panel
22    if isstruct(Param.(fields{ifield}))% case of a sub-structure
[360]23        if isfield(handles,fields{ifield})
[361]24            set(handles.(fields{ifield}),'Visible','on')
[591]25%             children=get(handles.(fields{ifield}),'children');
26%             for ichild=1:numel(children)
27%                 hchild.(get(children(ichild),'tag'))=children(ichild);
28%             end
29         %   errormsg=fill_GUI(Param.(fields{ifield}),hchild);% apply the function to the substructure
30         errormsg=fill_GUI(Param.(fields{ifield}),handles.(fields{ifield}));% apply the function to the substructure
31           % if the input sub-structure fits with a tag name of the GUI and a
32         % substructure of UserData
33        elseif isfield(UserData,fields{ifield})&& isfield(handles,fields{ifield})&&isfield(Param.(fields{ifield}),'Name')
34            UserData.(fields{ifield})=Param.(fields{ifield});
35            set(handles.(fields{ifield}),'String',Param.(fields{ifield}).Name)
[360]36        end
[500]37    % case of an element
[360]38    else
[361]39        hh=[];
[497]40        input_data=Param.(fields{ifield});
[379]41        check_done=0;
[361]42        if isfield(handles,fields{ifield})
[497]43            hh=handles.(fields{ifield});
[361]44            if strcmp(get(hh,'Type'),'uitable')
[379]45                set(hh,'Visible','on')
[427]46                if ischar(input_data)
[460]47                    input_data={input_data};% transform string to a single cell if needed
[427]48                end
[363]49                set(hh,'Data',input_data)
[379]50                check_done=1;
[360]51            end
[500]52        elseif isnumeric(input_data)
53            if numel(input_data)>1
54                %deals with array displayed in multiple boxes labeled by an index
55                for ibox=1:numel(input_data)
56                    if isfield(handles,['num_' fields{ifield} '_' num2str(ibox)])
57                        hh(ibox)=handles.(['num_' fields{ifield} '_' num2str(ibox)]);
58                    end
59                end
60            else % single box (usual case)
61               if isfield(handles,['num_' fields{ifield}])
62                   hh=handles.(['num_' fields{ifield}]);
63               end
64            end
[361]65        end
[500]66        for ibox=1:numel(hh)
67        if ~isempty(hh(ibox))&& ~check_done
68            set(hh(ibox),'Visible','on')
[368]69%             input_data
[500]70            switch get(hh(ibox),'Style')
[363]71                case {'checkbox','radiobutton','togglebutton'}
72                    if isnumeric(input_data)
[500]73                        set(hh(ibox),'Value',input_data(ibox))
[361]74                    end
75                case 'edit'
[515]76                    input_string='';
[363]77                    if isnumeric(input_data)
[515]78                        if numel(input_data)>0
[500]79                        input_string=num2str(input_data(ibox));
[515]80                        end
[500]81                    else
82                        input_string=input_data;
[361]83                    end
[500]84                    set(hh(ibox),'String',input_string)
[472]85                case{'listbox','popupmenu'}
[363]86                    if isnumeric(input_data)
87                        input_data=num2str(input_data);
[361]88                    end
[500]89                    menu=get(hh(ibox),'String');
[472]90                    if ischar(input_data)
91                        input_data={input_data};
[361]92                    end
[472]93                    values=zeros(size(input_data));
94                    for idata=1:numel(input_data)
95                        iline=find(strcmp(input_data{idata},menu));
96                        if isempty(iline)
[476]97                            values(idata)=1;
98                            menu=[input_data(idata);menu];
[472]99                        else
[476]100                            values(idata)=iline(1);
[472]101                        end
102                    end
[500]103                    set(hh(ibox),'String',menu)
104                    set(hh(ibox),'Value',values)
[360]105            end
106        end
[500]107        end
[360]108    end
109end
110 
Note: See TracBrowser for help on using the repository browser.