tomwalters@0
|
1 %
|
tomwalters@0
|
2 %
|
bleeck@3
|
3 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
4 % (c) 2011, University of Southampton
|
bleeck@3
|
5 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
6 % download of current version is on the soundsoftware site:
|
bleeck@3
|
7 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
8 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
9
|
tomwalters@0
|
10
|
tomwalters@0
|
11 function varargout = parametergui(varargin)
|
tomwalters@0
|
12 % all action from a parametergui.
|
tomwalters@0
|
13 %
|
tomwalters@0
|
14 % parametergui_MAINFCN provides these command line APIs for dealing with parameterguis
|
tomwalters@0
|
15 %
|
tomwalters@0
|
16 % parametergui, by itself, creates a new parametergui or raises the existing
|
tomwalters@0
|
17 % singleton*.
|
tomwalters@0
|
18 %
|
tomwalters@0
|
19 % H = parametergui returns the handle to a new parametergui or the handle to
|
tomwalters@0
|
20 % the existing singleton*.
|
tomwalters@0
|
21 %
|
tomwalters@0
|
22 % parametergui(parameter_structure) creates a new window with the guis
|
tomwalters@0
|
23 % for each parameter
|
tomwalters@0
|
24 %
|
tomwalters@0
|
25 % parametergui('CALLBACK',hObject,eventData,handles,...) calls the local
|
tomwalters@0
|
26 % function named CALLBACK in parametergui.M with the given input arguments.
|
tomwalters@0
|
27 %
|
tomwalters@0
|
28 % parametergui('Property','Value',...) creates a new parametergui or raises the
|
tomwalters@0
|
29 % existing singleton*. Starting from the left, property value pairs are
|
tomwalters@0
|
30 % applied to the parametergui before untitled_OpeningFunction gets called. An
|
tomwalters@0
|
31 % unrecognized property name or invalid value makes property application
|
tomwalters@0
|
32 % stop. All inputs are passed to untitled_OpeningFcn via varargin.
|
tomwalters@0
|
33 %
|
tomwalters@0
|
34 % Copyright 1984-2002 The MathWorks, Inc.
|
tomwalters@0
|
35 % $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
|
tomwalters@0
|
36 %
|
tomwalters@0
|
37 % Copyright 2004 Stefan Bleeck
|
tomwalters@0
|
38 % $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
|
tomwalters@0
|
39
|
tomwalters@0
|
40
|
tomwalters@0
|
41
|
tomwalters@0
|
42 % find out, if we want a new window or the old one:
|
tomwalters@0
|
43 if length(varargin)==1 && ~isempty(varargin{1})
|
tomwalters@0
|
44 parametergui_Singleton = 0; % normally we want a new window
|
tomwalters@0
|
45 all_childs=get(0,'children');
|
tomwalters@0
|
46 this_name=getname(varargin{1});
|
tomwalters@0
|
47 for i=1:length(all_childs)
|
tomwalters@0
|
48 name=get(all_childs(i),'name');
|
tomwalters@0
|
49 if strcmp(name,this_name)
|
tomwalters@0
|
50 parametergui_Singleton = 1; % but if there is a copy already, take that window instead
|
tomwalters@0
|
51 % and bring it to the front
|
tomwalters@0
|
52 figure(all_childs(i));
|
tomwalters@0
|
53 break
|
tomwalters@0
|
54 end
|
tomwalters@0
|
55 end
|
tomwalters@0
|
56 else
|
tomwalters@0
|
57 parametergui_Singleton = 1; % but if there is a copy already, take that window instead
|
tomwalters@0
|
58 end
|
tomwalters@0
|
59
|
tomwalters@0
|
60 parametergui_State = struct('parametergui_Name', mfilename, ...
|
tomwalters@0
|
61 'parametergui_Singleton', parametergui_Singleton, ...
|
tomwalters@0
|
62 'parametergui_OpeningFcn', @parametergui_OpeningFcn, ...
|
tomwalters@0
|
63 'parametergui_OutputFcn', @parametergui_OutputFcn, ...
|
tomwalters@0
|
64 'parametergui_LayoutFcn', @parametergui_LayoutFcn, ...
|
tomwalters@0
|
65 'parametergui_Callback', []);
|
tomwalters@0
|
66 if nargin && ischar(varargin{1})
|
tomwalters@0
|
67 parametergui_State.parametergui_Callback = str2func(varargin{1});
|
tomwalters@0
|
68 end
|
tomwalters@0
|
69
|
tomwalters@0
|
70 if nargout
|
tomwalters@0
|
71 [varargout{1:nargout}] = parametergui_mainfcn(parametergui_State, varargin{:});
|
tomwalters@0
|
72 else
|
tomwalters@0
|
73 parametergui_mainfcn(parametergui_State, varargin{:});
|
tomwalters@0
|
74 end
|
tomwalters@0
|
75
|
tomwalters@0
|
76
|
tomwalters@0
|
77 % --- Executes just before parametergui is made visible.
|
tomwalters@0
|
78 function parametergui_OpeningFcn(hObject, eventdata, handles, varargin) %#ok
|
tomwalters@0
|
79 % This function has no output args, see OutputFcn.
|
tomwalters@0
|
80 % hObject handle to figure
|
tomwalters@0
|
81 % eventdata reserved - to be defined in a future version of MATLAB
|
tomwalters@0
|
82 % handles structure with handles and user data (see guidata)
|
tomwalters@0
|
83 % varargin command line arguments to parametergui (see VARARGIN)
|
tomwalters@0
|
84
|
tomwalters@0
|
85 % Choose default command line output for parametergui
|
tomwalters@0
|
86 handles.output = hObject;
|
tomwalters@0
|
87
|
tomwalters@0
|
88
|
tomwalters@0
|
89 % copy the params in place
|
tomwalters@0
|
90 % params=varargin{1};
|
tomwalters@0
|
91 % handles.params=params;
|
tomwalters@0
|
92
|
tomwalters@0
|
93 % Update handles structure
|
tomwalters@0
|
94 guidata(hObject, handles);
|
tomwalters@0
|
95
|
tomwalters@0
|
96 global result;
|
tomwalters@0
|
97 % UIWAIT makes parametergui wait for user response (see UIRESUME)
|
tomwalters@0
|
98
|
tomwalters@0
|
99 % result=getdefaultvalue(handles.params);
|
tomwalters@0
|
100
|
tomwalters@0
|
101
|
tomwalters@0
|
102 if strcmp(getmode(handles.params),'modal')
|
tomwalters@0
|
103 % set the first focus
|
tomwalters@0
|
104 focus=getfirstfocus(handles.params);
|
tomwalters@0
|
105 if ~isempty(focus)
|
tomwalters@0
|
106 hand=gethandle(handles.params,focus);
|
tomwalters@0
|
107 if ishandle(hand)
|
tomwalters@0
|
108 uicontrol(hand);
|
tomwalters@0
|
109 end
|
tomwalters@0
|
110 end
|
tomwalters@0
|
111
|
tomwalters@0
|
112 uiwait(handles.figure1);
|
tomwalters@0
|
113 end
|
tomwalters@0
|
114
|
tomwalters@0
|
115 % % set the userdata to the parameters so that they can be accessed from other programs
|
tomwalters@0
|
116 % set(handles.figure1,'userdata',handles.params);
|
tomwalters@0
|
117 % w=get(handles.figure1,'userdata');
|
tomwalters@0
|
118 %%%% that doesnt work because of an obvious bug in matlab. The set routine
|
tomwalters@0
|
119 %%%% calls the params set not the windows set
|
tomwalters@0
|
120
|
tomwalters@0
|
121
|
tomwalters@0
|
122 % --- Outputs from this function are returned to the command line.
|
tomwalters@0
|
123 function varargout = parametergui_OutputFcn(hObject, eventdata, handles) %#ok
|
tomwalters@0
|
124 % varargout cell array for returning output args (see VARARGOUT);
|
tomwalters@0
|
125 % hObject handle to figure
|
tomwalters@0
|
126 % eventdata reserved - to be defined in a future version of MATLAB
|
tomwalters@0
|
127 % handles structure with handles and user data (see guidata)
|
tomwalters@0
|
128
|
tomwalters@0
|
129
|
tomwalters@0
|
130 % Get default command line output from handles structure
|
tomwalters@0
|
131 global result;
|
tomwalters@0
|
132 % if isfield(result,'handles')
|
tomwalters@0
|
133 % % matlab doesnt call the callback routine when closed, so update all values
|
tomwalters@0
|
134 % % first:
|
tomwalters@0
|
135 % generic_Callback([], 'onlyupdate', result.handles);
|
tomwalters@0
|
136 % end
|
tomwalters@0
|
137
|
tomwalters@0
|
138
|
tomwalters@0
|
139 varargout{1} = result;
|
tomwalters@0
|
140
|
tomwalters@0
|
141
|
tomwalters@0
|
142 % --- Executes on button press in pushbutton1.
|
tomwalters@0
|
143 function generic_Callback(hObject, eventdata, handles)
|
tomwalters@0
|
144 global result;
|
tomwalters@0
|
145 if ischar(eventdata) && strcmp(eventdata,'default')
|
tomwalters@0
|
146 p=getdefaultbutton(handles.params); % its as if the button was pressed
|
tomwalters@0
|
147 hObject=p.handle{1};
|
tomwalters@0
|
148 end
|
tomwalters@0
|
149 if ischar(eventdata) && strcmp(eventdata,'onlyupdate')
|
tomwalters@0
|
150 p=get(handles.params);
|
tomwalters@0
|
151 hObject=p{1}.handle{1};
|
tomwalters@0
|
152 end
|
tomwalters@0
|
153 centry=getentrybyhandle(handles.params,hObject);
|
tomwalters@0
|
154 if isempty(centry)
|
tomwalters@0
|
155 disp('clicked on something outside')
|
tomwalters@0
|
156 return
|
tomwalters@0
|
157 end
|
tomwalters@0
|
158
|
tomwalters@0
|
159 params=handles.params;
|
tomwalters@0
|
160 entryparams=get(params);
|
tomwalters@0
|
161 data=getuserdata(params);
|
tomwalters@0
|
162 callback=centry.callback;
|
tomwalters@0
|
163 nr_params=length(entryparams);
|
tomwalters@0
|
164
|
tomwalters@0
|
165 % second go through all fields and update the value. This is neccessary to
|
tomwalters@0
|
166 % make sure to update the values in the params-structure when altered from
|
tomwalters@0
|
167 % outside
|
tomwalters@0
|
168 for iii=1:nr_params
|
tomwalters@0
|
169 % param=entryparams{iii};
|
tomwalters@0
|
170 type=entryparams{iii}.type;
|
tomwalters@0
|
171 handleb=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel);
|
tomwalters@0
|
172 switch type
|
tomwalters@0
|
173 case {'pop-up menu'}
|
tomwalters@0
|
174 vals=get(handleb,'string');
|
tomwalters@0
|
175 nrval=get(handleb,'value');
|
tomwalters@0
|
176 value=vals{nrval};
|
tomwalters@0
|
177 params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel); % set the string value
|
tomwalters@0
|
178 case {'bool','radiobutton'}
|
tomwalters@0
|
179 value=get(handleb,'value');
|
tomwalters@0
|
180 params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel);
|
tomwalters@0
|
181
|
tomwalters@0
|
182 % bool items can enable or disable other items:
|
tomwalters@0
|
183 for i=1:length(entryparams{iii}.enables)
|
tomwalters@0
|
184 params=enable(params,entryparams{iii}.enables{i},value,entryparams{iii}.enables_inbox{i});
|
tomwalters@0
|
185 end
|
tomwalters@0
|
186 for i=1:length(entryparams{iii}.disables)
|
tomwalters@0
|
187 params=enable(params,entryparams{iii}.disables{i},1-value,entryparams{iii}.disables_inbox{i});
|
tomwalters@0
|
188 end
|
tomwalters@0
|
189 case {'filename','string','directoryname'}
|
tomwalters@0
|
190 stringvalue=get(handleb,'string');
|
tomwalters@0
|
191 params=set(params,entryparams{iii}.text,stringvalue,entryparams{iii}.panel);
|
tomwalters@0
|
192 case {'slider'}
|
tomwalters@0
|
193 % user could have clicked on the slider or on the edit
|
tomwalters@0
|
194 secombi=entryparams{iii}.slidereditcombi;
|
tomwalters@0
|
195 hand1=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,1);
|
tomwalters@0
|
196 hand2=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,3);
|
tomwalters@0
|
197 if hObject==hand1
|
tomwalters@0
|
198 strval=get(hand1,'string');
|
tomwalters@0
|
199 val=str2num(strval);
|
tomwalters@0
|
200 secombi=slidereditcontrol_set_raweditvalue(secombi,val);
|
tomwalters@0
|
201 else
|
tomwalters@0
|
202 val=get(hand2,'value');
|
tomwalters@0
|
203 secombi=slidereditcontrol_set_rawslidervalue(secombi,val);
|
tomwalters@0
|
204 end
|
tomwalters@0
|
205 val=slidereditcontrol_get_value(secombi);
|
tomwalters@0
|
206 selectedunit=getcurrentunit(params,entryparams{iii}.text);
|
tomwalters@0
|
207 toval=val*secombi.editscaler;
|
tomwalters@0
|
208 params=setas(params,entryparams{iii}.text,toval,selectedunit,entryparams{iii}.panel); % set the real value
|
tomwalters@0
|
209 case {'float'}
|
tomwalters@0
|
210 set(handleb,'backgroundcolor','w');
|
tomwalters@0
|
211 set(handleb,'foregroundcolor','k');
|
tomwalters@0
|
212 strvalue=get(handleb,'string'); % value is a string, lets see what we make of it
|
tomwalters@0
|
213 if ~strcmp(strvalue,'auto')
|
tomwalters@0
|
214 selectedunit=getcurrentunit(params,entryparams{iii}.text);
|
tomwalters@0
|
215 units=entryparams{iii}.unittype;
|
tomwalters@0
|
216 if isa(units,'unit_none')
|
tomwalters@0
|
217 testvalue=str2num(strvalue); % its a float, it must have a value
|
tomwalters@0
|
218 realvalue=testvalue;
|
tomwalters@0
|
219 selectedunit='';
|
tomwalters@0
|
220 else
|
tomwalters@0
|
221 params=setas(params,entryparams{iii}.text,strvalue,selectedunit,entryparams{iii}.panel); % set the real value
|
tomwalters@0
|
222 testvalue=getas(params,entryparams{iii}.text,entryparams{iii}.orgunit);
|
tomwalters@0
|
223 realvalue=str2num(strvalue);
|
tomwalters@0
|
224 end
|
tomwalters@0
|
225 if isempty(testvalue)
|
tomwalters@0
|
226 set(handleb,'backgroundcolor','g');
|
tomwalters@0
|
227 set(handleb,'foregroundcolor','r');
|
tomwalters@0
|
228 uicontrol(handleb);
|
tomwalters@0
|
229 errordlg(sprintf('no valid value for ''%s''',entryparams{iii}.text));
|
tomwalters@0
|
230 return
|
tomwalters@0
|
231 end
|
tomwalters@0
|
232 if min(testvalue)<entryparams{iii}.minvalue || max(testvalue)>entryparams{iii}.maxvalue
|
tomwalters@0
|
233 set(handleb,'backgroundcolor','g');
|
tomwalters@0
|
234 set(handleb,'foregroundcolor','r');
|
tomwalters@0
|
235 uicontrol(handleb);
|
tomwalters@0
|
236 if testvalue<entryparams{iii}.minvalue
|
tomwalters@0
|
237 errordlg(sprintf('''%s'' must be bigger then %f %s',entryparams{iii}.text,entryparams{iii}.minvalue,selectedunit));
|
tomwalters@0
|
238 else
|
tomwalters@0
|
239 errordlg(sprintf('''%s'' must be smaller then %f %s',entryparams{iii}.text,entryparams{iii}.maxvalue,selectedunit));
|
tomwalters@0
|
240 end
|
tomwalters@0
|
241 return
|
tomwalters@0
|
242 end
|
tomwalters@0
|
243 params=setas(params,entryparams{iii}.text,strvalue,selectedunit,entryparams{iii}.panel); % set the real value
|
tomwalters@0
|
244 else
|
tomwalters@0
|
245 set(handleb,'backgroundcolor','w');
|
tomwalters@0
|
246 set(handleb,'foregroundcolor','k');
|
tomwalters@0
|
247 end
|
tomwalters@0
|
248
|
tomwalters@0
|
249 case {'int'}
|
tomwalters@0
|
250 strvalue=get(handleb,'string'); % value is a string, lets see what we make of it
|
tomwalters@0
|
251 set(handleb,'backgroundcolor','w');
|
tomwalters@0
|
252 set(handleb,'foregroundcolor','k');
|
tomwalters@0
|
253 if strcmp(strvalue,'auto')
|
tomwalters@0
|
254 params=set(params,entryparams{iii}.text,'auto',entryparams{iii}.panel);
|
tomwalters@0
|
255 else
|
tomwalters@0
|
256 testvalue=str2num(strvalue); % its a float, it must have a value (str2double does produce a NAN then!)
|
tomwalters@0
|
257 if isempty(testvalue)
|
tomwalters@0
|
258 testvalue=[]; % could be empty, sometimes useful...
|
tomwalters@0
|
259 else
|
tomwalters@0
|
260 if min(testvalue)<entryparams{iii}.minvalue || max(testvalue)>entryparams{iii}.maxvalue
|
tomwalters@0
|
261 set(handleb,'foregroundcolor','g');
|
tomwalters@0
|
262 set(handleb,'backgroundcolor','r');
|
tomwalters@0
|
263 uicontrol(handleb);
|
tomwalters@0
|
264 if testvalue<entryparams{iii}.minvalue
|
tomwalters@0
|
265 errordlg(sprintf('''%s'' must be bigger then %d',entryparams{iii}.text,entryparams{iii}.minvalue+1));
|
tomwalters@0
|
266 else
|
tomwalters@0
|
267 errordlg(sprintf('''%s'' must be smaller then %d',entryparams{iii}.text,entryparams{iii}.maxvalue+1));
|
tomwalters@0
|
268 end
|
tomwalters@0
|
269 return
|
tomwalters@0
|
270 end
|
tomwalters@0
|
271 end
|
tomwalters@0
|
272 if isempty(strfind(strvalue,':'))
|
tomwalters@0
|
273 value=round(testvalue); % its an integer!
|
tomwalters@0
|
274 params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel);
|
tomwalters@0
|
275 else
|
tomwalters@0
|
276 params=set(params,entryparams{iii}.text,strvalue,entryparams{iii}.panel);
|
tomwalters@0
|
277 end
|
tomwalters@0
|
278 end
|
tomwalters@0
|
279 end
|
tomwalters@0
|
280 end
|
tomwalters@0
|
281
|
tomwalters@0
|
282 % first find out if the response is towards a change of a unit. then only
|
tomwalters@0
|
283 % change the string
|
tomwalters@0
|
284 for iii=1:nr_params
|
tomwalters@0
|
285 param=entryparams{iii};
|
tomwalters@0
|
286 type=param.type;
|
tomwalters@0
|
287 if strcmp(type,'float') || strcmp(type,'slider')
|
tomwalters@0
|
288 handleb2=gethandle(params,param.text,param.panel,2);
|
tomwalters@0
|
289 if hObject==handleb2 % yes, user changed a unit
|
tomwalters@0
|
290 [selectedunit,fullunitname]=getcurrentunit(params,param.text);
|
tomwalters@0
|
291 if ~ischar(param.rawvalue)
|
tomwalters@0
|
292 newvalue=tounits(param.unittype,param.rawvalue,selectedunit); %the unit in which the min and max values are defined
|
tomwalters@0
|
293 setas(params,param.text,newvalue,selectedunit,param.panel);
|
tomwalters@0
|
294 end
|
tomwalters@0
|
295 % make a new tooltip
|
tomwalters@0
|
296 unittype=getname(param.unittype);
|
tomwalters@0
|
297 tooltips=sprintf('%s measured in %s (%s)',unittype,selectedunit,fullunitname);
|
tomwalters@0
|
298 set(handleb2,'tooltip',tooltips);
|
tomwalters@0
|
299
|
tomwalters@0
|
300 if strcmp(type,'slider') % change the slidercontrol to the new multiplier
|
tomwalters@0
|
301 editscaler=tounits(param.unittype,1,selectedunit);
|
tomwalters@0
|
302 se=param.slidereditcombi;
|
tomwalters@0
|
303 se.editscaler=editscaler;
|
tomwalters@0
|
304 params=setslidereditcontrol(params,param.text,se,param.panel);
|
tomwalters@0
|
305 end
|
tomwalters@0
|
306 handles.params=params;
|
tomwalters@0
|
307 guidata(hObject, handles); % Update handles structure
|
tomwalters@0
|
308 return
|
tomwalters@0
|
309 end
|
tomwalters@0
|
310 end
|
tomwalters@0
|
311 end
|
tomwalters@0
|
312
|
tomwalters@0
|
313 %third do something with the action
|
tomwalters@0
|
314 type=centry.type;
|
tomwalters@0
|
315 gethandle(params,centry.text,centry.panel);
|
tomwalters@0
|
316 switch type
|
tomwalters@0
|
317 case 'button'
|
tomwalters@0
|
318 result=params;
|
tomwalters@0
|
319 eval(callback);
|
tomwalters@0
|
320 return
|
tomwalters@0
|
321 case {'filename','directoryname'}
|
tomwalters@0
|
322 hand=gethandle(params,centry.text,centry.panel,1);
|
tomwalters@0
|
323 hand2=gethandle(params,centry.text,centry.panel,2);
|
tomwalters@0
|
324 % analyse the old file for pathes so that the filebox starts
|
tomwalters@0
|
325 % correct:
|
tomwalters@0
|
326 if hand2==hObject % the button was pressed
|
tomwalters@0
|
327 oldname=get(params,centry.text,centry.panel);
|
tomwalters@0
|
328 [filedir,x,x,x]=fileparts(oldname);
|
tomwalters@0
|
329 if strcmp(type,'filename')
|
tomwalters@0
|
330 % we want to allow files that do not exist jet therefore calling
|
tomwalters@0
|
331 % uiput, not uiget
|
tomwalters@0
|
332 if exist(filedir,'dir')
|
tomwalters@0
|
333 olddir=cd(filedir);
|
tomwalters@0
|
334 else
|
tomwalters@0
|
335 olddir=pwd;
|
tomwalters@0
|
336 end
|
tomwalters@0
|
337 [nam,dir]=uiputfile('*.*','select a file');
|
tomwalters@0
|
338 if ~isequal(nam,0)
|
tomwalters@0
|
339 fullname=fullfile(dir,nam);
|
tomwalters@0
|
340 set(hand,'string',fullname);
|
tomwalters@0
|
341 else
|
tomwalters@0
|
342 fullname=oldname;
|
tomwalters@0
|
343 end
|
tomwalters@0
|
344 cd(olddir);
|
tomwalters@0
|
345 else % must be directory
|
tomwalters@0
|
346 olddir=cd(filedir);
|
tomwalters@0
|
347 ret=uigetdir(filedir,'select a directory');
|
tomwalters@0
|
348 if ~isequal(ret,0)
|
tomwalters@0
|
349 fullname=ret;
|
tomwalters@0
|
350 else
|
tomwalters@0
|
351 fullname=oldname;
|
tomwalters@0
|
352 end
|
tomwalters@0
|
353 cd(olddir);
|
tomwalters@0
|
354 end
|
tomwalters@0
|
355 params=set(params,centry.text,fullname,centry.panel);
|
tomwalters@0
|
356 params=settooltip(params,centry.text,fullname,centry.panel);
|
tomwalters@0
|
357 else
|
tomwalters@0
|
358 fullname=get(hand,'string');
|
tomwalters@0
|
359 params=set(params,centry.text,fullname,centry.panel);
|
tomwalters@0
|
360 params=settooltip(params,centry.text,fullname,centry.panel);
|
tomwalters@0
|
361 end
|
tomwalters@0
|
362 end
|
tomwalters@0
|
363
|
tomwalters@0
|
364 % find out if it was a 'other...' line of a buttonrow
|
tomwalters@0
|
365 entry=getentrybyhandle(params,hObject);
|
tomwalters@0
|
366 if strcmp(entry.type,'radiobutton') && strcmp(entry.text,'other...')
|
tomwalters@0
|
367 buttonhand=gethandle(params,entry.text,entry.panel,1);
|
tomwalters@0
|
368 clickedinbox=entry.panel;
|
tomwalters@0
|
369 % set all to 0 except of other...
|
tomwalters@0
|
370
|
tomwalters@0
|
371 for j=1:nr_params
|
tomwalters@0
|
372 paramas=entryparams{j};
|
tomwalters@0
|
373 if strcmp(paramas.type,'radiobutton') && strcmp(paramas.panel,clickedinbox)
|
tomwalters@0
|
374 curhand=gethandle(params,paramas.text,clickedinbox);
|
tomwalters@0
|
375 set(curhand,'value',0);
|
tomwalters@0
|
376 params=set(params,entryparams{j}.text,0,clickedinbox);
|
tomwalters@0
|
377 end
|
tomwalters@0
|
378 end
|
tomwalters@0
|
379 set(buttonhand,'value',1); % set the one you clicked on to 1
|
tomwalters@0
|
380 params=set(params,entry.text,1,entry.panel);
|
tomwalters@0
|
381 otherhand=gethandle(params,entry.text,entry.panel,2);
|
tomwalters@0
|
382 otherstr=get(otherhand,'string');
|
tomwalters@0
|
383 params=setuserdata(params,otherstr,entry.text,entry.panel);
|
tomwalters@0
|
384 set(otherhand,'back','y');
|
tomwalters@0
|
385 end
|
tomwalters@0
|
386
|
tomwalters@0
|
387 % every item can have a callback
|
tomwalters@0
|
388 if ~isempty(callback);
|
tomwalters@0
|
389 eval(callback);
|
tomwalters@0
|
390 end
|
tomwalters@0
|
391
|
tomwalters@0
|
392 handles.params=params;
|
tomwalters@0
|
393 % save for later (the rückgabewert)
|
tomwalters@0
|
394 result=params;
|
tomwalters@0
|
395
|
tomwalters@0
|
396 guidata(hObject, handles); % Update handles structure
|
tomwalters@0
|
397
|
tomwalters@0
|
398
|
tomwalters@0
|
399 % --- Creates and returns a handle to the parametergui figure.
|
tomwalters@0
|
400 function guihandle = parametergui_LayoutFcn(policy)
|
tomwalters@0
|
401 % policy - create a new figure or use a singleton. 'new' or 'reuse'.
|
tomwalters@0
|
402
|
tomwalters@0
|
403 persistent hsingleton;
|
tomwalters@0
|
404 if strcmpi(policy, 'reuse') && ishandle(hsingleton)
|
tomwalters@0
|
405 guihandle = hsingleton;
|
tomwalters@0
|
406 return;
|
tomwalters@0
|
407 end
|
tomwalters@0
|
408 % collect my own params to generate parmeters on the fly
|
tomwalters@0
|
409 global params
|
tomwalters@0
|
410
|
tomwalters@0
|
411 % now build from bottom to top a line of text and an edit box for each
|
tomwalters@0
|
412 % parameter
|
tomwalters@0
|
413
|
tomwalters@0
|
414 % first find out, what the longest name is
|
tomwalters@0
|
415 % maxxlen=5; % the longest text in width
|
tomwalters@0
|
416 % maxylen=5; % the preliminary height of the window
|
tomwalters@0
|
417 rowheight=2.1; % how high every row is
|
tomwalters@0
|
418 elementhigth=1.6; % how high every element is
|
tomwalters@0
|
419 edit_width=14; % how wide an edit box is
|
tomwalters@0
|
420 unit_width=12; % the width of a unit
|
tomwalters@0
|
421 stringedit_width=30;
|
tomwalters@0
|
422 spacebetweentextandedit=5; % space between text and edit box
|
tomwalters@0
|
423 leftoffset=2; % offset of text to the left boundary (and right as well)
|
tomwalters@0
|
424 buttonoffset=3; % how far the buttons are away from the left edge
|
tomwalters@0
|
425 spacearoundtext=1.5; % a space around either side of each text
|
tomwalters@0
|
426 filenamelength=35; % how long the entry for a filename is
|
tomwalters@0
|
427 yoffset=(rowheight-elementhigth)/2; % brings everything to the middle
|
tomwalters@0
|
428 rightoffset=2; % a few spaces to the right edge of the screen
|
tomwalters@0
|
429 all_y_offset=1; % shift all entries a bit down.
|
tomwalters@0
|
430 extrabuttondown=0.5; % shift buttons an extra bit down
|
tomwalters@0
|
431
|
tomwalters@0
|
432 entryparams=get(params);
|
tomwalters@0
|
433 nr_params=length(entryparams);
|
tomwalters@0
|
434
|
tomwalters@0
|
435 % first go through and find the biggest text entry to define the width of
|
tomwalters@0
|
436 % the window
|
tomwalters@0
|
437 maxtextlen=0;
|
tomwalters@0
|
438 maxeditwidth=0;
|
tomwalters@0
|
439 mineditwidth=stringedit_width;
|
tomwalters@0
|
440 otheroffset=0; % when an "other..." is in a panel, then make everything a bit wider
|
tomwalters@0
|
441 thirdpaneladd=0; % a third panel to the right
|
tomwalters@0
|
442 for iii=1:nr_params
|
tomwalters@0
|
443 param=entryparams{iii};
|
tomwalters@0
|
444 text_len=length(param.text);
|
tomwalters@0
|
445 if text_len>maxtextlen
|
tomwalters@0
|
446 maxtextlen=text_len;
|
tomwalters@0
|
447 end
|
tomwalters@0
|
448
|
tomwalters@0
|
449 if strcmp(param.type,'filename')
|
tomwalters@0
|
450 maxeditwidth=filenamelength+10;
|
tomwalters@0
|
451 end
|
tomwalters@0
|
452 if strcmp(param.type,'directoryname')
|
tomwalters@0
|
453 maxeditwidth=filenamelength+10;
|
tomwalters@0
|
454 end
|
tomwalters@0
|
455 if strcmp(param.type,'string')
|
tomwalters@0
|
456 maxeditwidth=max(maxeditwidth,param.width);
|
tomwalters@0
|
457 maxeditwidth=max(maxeditwidth,mineditwidth);
|
tomwalters@0
|
458 end
|
tomwalters@0
|
459 if strcmp(param.type,'float') || strcmp(param.type,'int')
|
tomwalters@0
|
460 maxeditwidth=max(maxeditwidth,25);
|
tomwalters@0
|
461 end
|
tomwalters@0
|
462 if strcmp(param.type,'pop-up menu')
|
tomwalters@0
|
463 maxeditwidth=max(maxeditwidth,20);
|
tomwalters@0
|
464 end
|
tomwalters@0
|
465 if strcmp(param.type,'slider')
|
tomwalters@0
|
466 thirdpaneladd=30;
|
tomwalters@0
|
467 maxeditwidth=max(maxeditwidth,45);
|
tomwalters@0
|
468 end
|
tomwalters@0
|
469 end
|
tomwalters@0
|
470
|
tomwalters@0
|
471 % the total size of the window is now:
|
tomwalters@0
|
472 maxwidth=max(maxeditwidth,edit_width);
|
tomwalters@0
|
473 window_width=maxtextlen+spacebetweentextandedit+maxwidth+3*leftoffset+rightoffset+thirdpaneladd;
|
tomwalters@0
|
474 window_height=(nr_params+1)*rowheight;
|
tomwalters@0
|
475 % get the size of the screen in chars
|
tomwalters@0
|
476 set(0,'units','char');
|
tomwalters@0
|
477 siz=get(0,'screensize');
|
tomwalters@0
|
478 screeen_height=siz(4);
|
tomwalters@0
|
479 screeen_width=siz(3);
|
tomwalters@0
|
480 set(0,'units','pixels'); % back to normal
|
tomwalters@0
|
481
|
tomwalters@0
|
482 % the figure
|
tomwalters@0
|
483 % windoff=1.3; % offset from the top right corner
|
tomwalters@0
|
484 windoff=0;
|
tomwalters@0
|
485 guihandle = figure(...
|
tomwalters@0
|
486 'Units','characters',...
|
tomwalters@0
|
487 'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
488 'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
|
tomwalters@0
|
489 'IntegerHandle','off',...
|
tomwalters@0
|
490 'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
|
tomwalters@0
|
491 'MenuBar','none',...
|
tomwalters@0
|
492 'Name',getname(params),...
|
tomwalters@0
|
493 'NumberTitle','off',...
|
tomwalters@0
|
494 'Position',[screeen_width-window_width+windoff screeen_height-window_height-windoff window_width window_height],...
|
tomwalters@0
|
495 'Renderer',get(0,'defaultfigureRenderer'),...
|
tomwalters@0
|
496 'RendererMode','manual',...
|
tomwalters@0
|
497 'Resize','off',...
|
tomwalters@0
|
498 'HandleVisibility','callback',...
|
tomwalters@0
|
499 'visible','off',...
|
tomwalters@0
|
500 'KeyPressFcn' ,@doFigureKeyPress , ...
|
tomwalters@0
|
501 'Tag','figure1');
|
tomwalters@0
|
502
|
tomwalters@0
|
503 pos=getposition(params);
|
tomwalters@0
|
504 movegui(guihandle,pos);
|
tomwalters@0
|
505
|
tomwalters@0
|
506 % make sure we are on screen
|
tomwalters@0
|
507 movegui(guihandle)
|
tomwalters@0
|
508
|
tomwalters@0
|
509 % error in V7... correct for small offset
|
tomwalters@0
|
510 if strcmp(pos,'northeast')
|
tomwalters@0
|
511 wp=get(guihandle,'pos');
|
tomwalters@0
|
512 wp(1)=wp(1)+5;
|
tomwalters@0
|
513 wp(2)=wp(2)+5;
|
tomwalters@0
|
514 set(guihandle,'pos',wp);
|
tomwalters@0
|
515 end
|
tomwalters@0
|
516 set(guihandle,'visible','on')
|
tomwalters@0
|
517
|
tomwalters@0
|
518 % application data
|
tomwalters@0
|
519 setappdata(guihandle, 'parameterguiDEOptions', struct(...
|
tomwalters@0
|
520 'active_h', 1.020033e+002, ...
|
tomwalters@0
|
521 'taginfo', struct(...
|
tomwalters@0
|
522 'figure', 2, ...
|
tomwalters@0
|
523 'pushbutton', 2), ...
|
tomwalters@0
|
524 'override', 0, ...
|
tomwalters@0
|
525 'release', 13, ...
|
tomwalters@0
|
526 'resize', 'simple', ...
|
tomwalters@0
|
527 'accessibility', 'callback', ...
|
tomwalters@0
|
528 'mfile', 1, ...
|
tomwalters@0
|
529 'callbacks', 1, ...
|
tomwalters@0
|
530 'singleton', 1, ...
|
tomwalters@0
|
531 'syscolorfig', 1, ...
|
tomwalters@0
|
532 'lastSavedFile', 'c:\bla bla bla'));
|
tomwalters@0
|
533
|
tomwalters@0
|
534 % generate a huge panel that resides in that figure
|
tomwalters@0
|
535
|
tomwalters@0
|
536 set(guihandle,'Units','characters');
|
tomwalters@0
|
537 winsize=get(guihandle,'position');
|
tomwalters@0
|
538 winsize(1)=0;
|
tomwalters@0
|
539 winsize(2)=0;
|
tomwalters@0
|
540 bigpanel=uipanel(...
|
tomwalters@0
|
541 'Parent',guihandle,...
|
tomwalters@0
|
542 'Units','characters',...
|
tomwalters@0
|
543 'Position',winsize,...
|
tomwalters@0
|
544 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
545 'Title','',...
|
tomwalters@0
|
546 'BorderType','none',...
|
tomwalters@0
|
547 'visible','on',...
|
tomwalters@0
|
548 'Tag','parameterpanel');
|
tomwalters@0
|
549
|
tomwalters@0
|
550
|
tomwalters@0
|
551
|
tomwalters@0
|
552
|
tomwalters@0
|
553 % first plot all panels so that they are in the background
|
tomwalters@0
|
554 linecount=1;
|
tomwalters@0
|
555 panelcount=1;
|
tomwalters@0
|
556 for iii=nr_params:-1:1
|
tomwalters@0
|
557 param=entryparams{iii};
|
tomwalters@0
|
558 type=param.type;
|
tomwalters@0
|
559 if strcmp(type,'panel') % draw a panel around the next ones
|
tomwalters@0
|
560 pos_x=leftoffset;
|
tomwalters@0
|
561 width=window_width-2*leftoffset+rightoffset/2;
|
tomwalters@0
|
562 height=(param.nr_elements+0.99)*rowheight;
|
tomwalters@0
|
563 pos_y=(linecount+0.82)*rowheight-height-all_y_offset;
|
tomwalters@0
|
564 % panelhand(panelcount) = uipanel(... % panel
|
tomwalters@0
|
565 callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))';
|
tomwalters@0
|
566 panelhand(panelcount) = uibuttongroup(... % panel
|
tomwalters@0
|
567 'Parent',bigpanel,...
|
tomwalters@0
|
568 'Units','characters',...
|
tomwalters@0
|
569 'Position',[pos_x pos_y width height],...
|
tomwalters@0
|
570 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
571 'TitlePosition','lefttop',...
|
tomwalters@0
|
572 'Title',param.text,...
|
tomwalters@0
|
573 'BorderType','etchedin',...
|
tomwalters@0
|
574 'FontWeight','bold',...
|
tomwalters@0
|
575 'Fontsize',11,...
|
tomwalters@0
|
576 'Tag',sprintf('panel%d',panelcount),...
|
tomwalters@0
|
577 'SelectionChangeFcn',callbackstr,...
|
tomwalters@0
|
578 'Userdata',param.text);
|
tomwalters@0
|
579 panelcount=panelcount+1;
|
tomwalters@0
|
580 params=sethandle(params,param.text,panelhand,param.panel); % save the handle
|
tomwalters@0
|
581 end
|
tomwalters@0
|
582 linecount=linecount+1;
|
tomwalters@0
|
583 param_y(iii)=linecount;
|
tomwalters@0
|
584 end
|
tomwalters@0
|
585 % then make a line for each parameter
|
tomwalters@0
|
586 linecount=ones(panelcount,1); % one linecounter for each panel
|
tomwalters@0
|
587 general_line_count=1;
|
tomwalters@0
|
588 for iii=nr_params:-1:1
|
tomwalters@0
|
589 param=entryparams{iii};
|
tomwalters@0
|
590 type=param.type;
|
tomwalters@0
|
591 callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))';
|
tomwalters@0
|
592 tooltiptext=param.tooltiptext;
|
tomwalters@0
|
593 % find out to which panel we belong and set the parent appropriate
|
tomwalters@0
|
594 parentpanel=bigpanel; % by default the ui is in the big panel without subp
|
tomwalters@0
|
595 current_panel_count=1; % by default in the big panel
|
tomwalters@0
|
596 for jjj=1:panelcount-1
|
tomwalters@0
|
597 if strcmp(param.panel,get(panelhand(jjj),'title'))
|
tomwalters@0
|
598 parentpanel=panelhand(jjj);
|
tomwalters@0
|
599 current_panel_count=jjj+1; % the current panel +1 to avoid confusion with the big one
|
tomwalters@0
|
600 end
|
tomwalters@0
|
601 end
|
tomwalters@0
|
602 if ~strcmp(type,'button') && ~strcmp(type,'panel')
|
tomwalters@0
|
603 text_len=length(param.text);
|
tomwalters@0
|
604 if current_panel_count==1
|
tomwalters@0
|
605 pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset;
|
tomwalters@0
|
606 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
607 else
|
tomwalters@0
|
608 pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset-2;
|
tomwalters@0
|
609 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
610 end
|
tomwalters@0
|
611 h2 = uicontrol(... % text
|
tomwalters@0
|
612 'Parent',parentpanel,...
|
tomwalters@0
|
613 'Units','characters',...
|
tomwalters@0
|
614 'Position',[pos_x pos_y-yoffset text_len+2*spacearoundtext elementhigth],...
|
tomwalters@0
|
615 'String',param.text,...
|
tomwalters@0
|
616 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
617 'HorizontalAlignment','right',...
|
tomwalters@0
|
618 'Tag',sprintf('text%d',general_line_count),...
|
tomwalters@0
|
619 'Style','text');
|
tomwalters@0
|
620 if strcmp(type,'text')
|
tomwalters@0
|
621 set(h2,'FontSize',12);
|
tomwalters@0
|
622 set(h2,'Fontweight','bold');
|
tomwalters@0
|
623 ext=get(h2,'extent');
|
tomwalters@0
|
624 pos=get(h2,'position');
|
tomwalters@0
|
625 pos(1)=buttonoffset;
|
tomwalters@0
|
626 pos(3)=ext(3);
|
tomwalters@0
|
627 pos(4)=ext(4);
|
tomwalters@0
|
628 set(h2,'position',pos);
|
tomwalters@0
|
629 end
|
tomwalters@0
|
630 end
|
tomwalters@0
|
631 switch param.enable
|
tomwalters@0
|
632 case 0
|
tomwalters@0
|
633 enableval='off';
|
tomwalters@0
|
634 case 1
|
tomwalters@0
|
635 enableval='on';
|
tomwalters@0
|
636 end
|
tomwalters@0
|
637
|
tomwalters@0
|
638 switch type
|
tomwalters@0
|
639 case {'int'}
|
tomwalters@0
|
640 if current_panel_count==1
|
tomwalters@0
|
641 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
642 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
643 else
|
tomwalters@0
|
644 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
645 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
646 end
|
tomwalters@0
|
647 val=getraw(params,param.text);
|
tomwalters@0
|
648 hand = uicontrol(... % float edit box
|
tomwalters@0
|
649 'Parent',parentpanel,...
|
tomwalters@0
|
650 'Units','characters',...
|
tomwalters@0
|
651 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
652 'Position',[pos_x pos_y edit_width elementhigth],...
|
tomwalters@0
|
653 'Callback',callbackstr,...
|
tomwalters@0
|
654 'String',val,...
|
tomwalters@0
|
655 'enable',enableval,...
|
tomwalters@0
|
656 'Style','edit',...
|
tomwalters@0
|
657 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
658 'Userdata',param.text);
|
tomwalters@0
|
659 set(hand,'HorizontalAlignment','right');
|
tomwalters@0
|
660 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
661 case {'float'}
|
tomwalters@0
|
662 if current_panel_count==1
|
tomwalters@0
|
663 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
664 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
665 else
|
tomwalters@0
|
666 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
667 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
668 end
|
tomwalters@0
|
669 % val=getas(params,param.text,param.orgunit);
|
tomwalters@0
|
670 strval=param.stringvalue;
|
tomwalters@0
|
671 hand = uicontrol(... % float edit box
|
tomwalters@0
|
672 'Parent',parentpanel,...
|
tomwalters@0
|
673 'Units','characters',...
|
tomwalters@0
|
674 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
675 'Position',[pos_x pos_y edit_width elementhigth],...
|
tomwalters@0
|
676 'Callback',callbackstr,...
|
tomwalters@0
|
677 'String',strval,...
|
tomwalters@0
|
678 'Style','edit',...
|
tomwalters@0
|
679 'enable',enableval,...
|
tomwalters@0
|
680 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
681 'Userdata',param.text);
|
tomwalters@0
|
682
|
tomwalters@0
|
683 set(hand,'HorizontalAlignment','left');
|
tomwalters@0
|
684 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
685
|
tomwalters@0
|
686 % make the unit poupbox
|
tomwalters@0
|
687 unit=param.unittype;
|
tomwalters@0
|
688 % make a tooltip for it
|
tomwalters@0
|
689 unittype=getname(unit);
|
tomwalters@0
|
690 if ~isa(unit,'unit_none')
|
tomwalters@0
|
691 pos_x=pos_x+edit_width+2;
|
tomwalters@0
|
692 possible_units=getunitstrings(unit);
|
tomwalters@0
|
693 possible_units_full=getunitfullstrings(unit);
|
tomwalters@0
|
694 select_nr=findunit(unit,param.orgunit);
|
tomwalters@0
|
695 unitname=possible_units{select_nr};
|
tomwalters@0
|
696 fullunitname=possible_units_full{select_nr};
|
tomwalters@0
|
697 tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname);
|
tomwalters@0
|
698 hand2 = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
699 'Parent',parentpanel,...
|
tomwalters@0
|
700 'Units','characters',...
|
tomwalters@0
|
701 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
702 'Position',[pos_x pos_y unit_width elementhigth],...
|
tomwalters@0
|
703 'string',possible_units,...
|
tomwalters@0
|
704 'enable',enableval,...
|
tomwalters@0
|
705 'value',select_nr,...
|
tomwalters@0
|
706 'Style','popupmenu',...
|
tomwalters@0
|
707 'Callback',callbackstr,...
|
tomwalters@0
|
708 'tooltip',tooltips,...
|
tomwalters@0
|
709 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
710 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
|
tomwalters@0
|
711 params=sethandle(params,param.text,hand2,param.panel,2);
|
tomwalters@0
|
712 end
|
tomwalters@0
|
713 case {'slider'}
|
tomwalters@0
|
714 if current_panel_count==1
|
tomwalters@0
|
715 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
716 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
717 else
|
tomwalters@0
|
718 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
719 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
720 end
|
tomwalters@0
|
721 % val=getas(params,param.text,param.orgunit);
|
tomwalters@0
|
722 strval=param.stringvalue;
|
tomwalters@0
|
723 hand = uicontrol(... % float edit box
|
tomwalters@0
|
724 'Parent',parentpanel,...
|
tomwalters@0
|
725 'Units','characters',...
|
tomwalters@0
|
726 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
727 'Position',[pos_x pos_y edit_width elementhigth],...
|
tomwalters@0
|
728 'Callback',callbackstr,...
|
tomwalters@0
|
729 'String',strval,...
|
tomwalters@0
|
730 'Style','edit',...
|
tomwalters@0
|
731 'enable',enableval,...
|
tomwalters@0
|
732 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
733 'Userdata',param.text);
|
tomwalters@0
|
734
|
tomwalters@0
|
735 set(hand,'HorizontalAlignment','left');
|
tomwalters@0
|
736 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
737
|
tomwalters@0
|
738 % make the unit poupbox
|
tomwalters@0
|
739 unit=param.unittype;
|
tomwalters@0
|
740 % make a tooltip for it
|
tomwalters@0
|
741 unittype=getname(unit);
|
tomwalters@0
|
742 if ~isa(unit,'unit_none')
|
tomwalters@0
|
743 pos_x=pos_x+edit_width+2;
|
tomwalters@0
|
744 possible_units=getunitstrings(unit);
|
tomwalters@0
|
745 possible_units_full=getunitfullstrings(unit);
|
tomwalters@0
|
746 select_nr=findunit(unit,param.orgunit);
|
tomwalters@0
|
747 unitname=possible_units{select_nr};
|
tomwalters@0
|
748 fullunitname=possible_units_full{select_nr};
|
tomwalters@0
|
749 tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname);
|
tomwalters@0
|
750 hand2 = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
751 'Parent',parentpanel,...
|
tomwalters@0
|
752 'Units','characters',...
|
tomwalters@0
|
753 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
754 'Position',[pos_x pos_y unit_width elementhigth],...
|
tomwalters@0
|
755 'string',possible_units,...
|
tomwalters@0
|
756 'enable',enableval,...
|
tomwalters@0
|
757 'value',select_nr,...
|
tomwalters@0
|
758 'Style','popupmenu',...
|
tomwalters@0
|
759 'Callback',callbackstr,...
|
tomwalters@0
|
760 'tooltip',tooltips,...
|
tomwalters@0
|
761 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
762 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
|
tomwalters@0
|
763 params=sethandle(params,param.text,hand2,param.panel,2);
|
tomwalters@0
|
764 else
|
tomwalters@0
|
765 pos_x=pos_x+edit_width+2;
|
tomwalters@0
|
766 params=sethandle(params,param.text,0,param.panel,2);
|
tomwalters@0
|
767 end
|
tomwalters@0
|
768
|
tomwalters@0
|
769 % make the slider
|
tomwalters@0
|
770 pos_x=pos_x+unit_width+2;
|
tomwalters@0
|
771 hand3 = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
772 'Parent',parentpanel,...
|
tomwalters@0
|
773 'Units','characters',...
|
tomwalters@0
|
774 'Position',[pos_x pos_y thirdpaneladd+15 elementhigth],...
|
tomwalters@0
|
775 'enable',enableval,...
|
tomwalters@0
|
776 'value',1,...
|
tomwalters@0
|
777 'Style','slider',...
|
tomwalters@0
|
778 'Callback',callbackstr,...
|
tomwalters@0
|
779 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
780 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
|
tomwalters@0
|
781 params=sethandle(params,param.text,hand3,param.panel,3);
|
tomwalters@0
|
782
|
tomwalters@0
|
783 % set up the slidereditcontrol
|
tomwalters@0
|
784 secombi=slidereditcontrol_setup(hand3,hand,param.minvalue,param.maxvalue,param.rawvalue,param.islog,param.editscaler,param.nreditdigits);
|
tomwalters@0
|
785 secombi=slidereditcontrol_set_value(secombi,param.rawvalue);
|
tomwalters@0
|
786 params=setslidereditcontrol(params,param.text,secombi,param.panel);
|
tomwalters@0
|
787
|
tomwalters@0
|
788 case 'string'
|
tomwalters@0
|
789 if current_panel_count==1
|
tomwalters@0
|
790 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
791 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
792 else
|
tomwalters@0
|
793 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
794 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
795 end
|
tomwalters@0
|
796 width=max(stringedit_width,param.width)-2;
|
tomwalters@0
|
797 hand = uicontrol(... % string edit box
|
tomwalters@0
|
798 'Parent',parentpanel,...
|
tomwalters@0
|
799 'Units','characters',...
|
tomwalters@0
|
800 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
801 'enable',enableval,...
|
tomwalters@0
|
802 'Position',[pos_x pos_y width elementhigth],...
|
tomwalters@0
|
803 'Callback',callbackstr,...
|
tomwalters@0
|
804 'String',param.value,...
|
tomwalters@0
|
805 'Style','edit',...
|
tomwalters@0
|
806 'HorizontalAlignment','left',...
|
tomwalters@0
|
807 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
808 'Userdata',param.text);
|
tomwalters@0
|
809 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
810 case 'bool'
|
tomwalters@0
|
811 if current_panel_count==1
|
tomwalters@0
|
812 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
813 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
814 else
|
tomwalters@0
|
815 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
816 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
817 end
|
tomwalters@0
|
818 hand = uicontrol(... % bool: checkbox
|
tomwalters@0
|
819 'Parent',parentpanel,...
|
tomwalters@0
|
820 'Units','characters',...
|
tomwalters@0
|
821 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
822 'Position',[pos_x pos_y edit_width elementhigth],...
|
tomwalters@0
|
823 'enable',enableval,...
|
tomwalters@0
|
824 'value',param.value,...
|
tomwalters@0
|
825 'Style','checkbox',...
|
tomwalters@0
|
826 'Callback',callbackstr,...
|
tomwalters@0
|
827 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
828 'Userdata',param.text);
|
tomwalters@0
|
829 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
830 case 'radiobutton'
|
tomwalters@0
|
831 if current_panel_count==1
|
tomwalters@0
|
832 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
833 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
834 else
|
tomwalters@0
|
835 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
836 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
837 end
|
tomwalters@0
|
838 hand = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
839 'Parent',parentpanel,...
|
tomwalters@0
|
840 'TooltipString',tooltiptext,...
|
tomwalters@0
|
841 'Units','characters',...
|
tomwalters@0
|
842 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],...
|
tomwalters@0
|
843 'Position',[pos_x pos_y 3 elementhigth],...
|
tomwalters@0
|
844 'value',param.value,...
|
tomwalters@0
|
845 'Style','radiobutton',...
|
tomwalters@0
|
846 'enable',enableval,...
|
tomwalters@0
|
847 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
848 'Userdata',param.text);
|
tomwalters@0
|
849 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
850 if strcmp(param.text,'other...')
|
tomwalters@0
|
851 pos_x=pos_x+4;
|
tomwalters@0
|
852 % width=max(window_width-pos_x-5,10);
|
tomwalters@0
|
853 width=maxeditwidth-1;
|
tomwalters@0
|
854 if isfield(param,'userdata')
|
tomwalters@0
|
855 userstr=param.userdata;
|
tomwalters@0
|
856 else
|
tomwalters@0
|
857 userstr='';
|
tomwalters@0
|
858 end
|
tomwalters@0
|
859 hand2 = uicontrol(... % string edit box
|
tomwalters@0
|
860 'Parent',parentpanel,...
|
tomwalters@0
|
861 'Units','characters',...
|
tomwalters@0
|
862 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
863 'Position',[pos_x pos_y width elementhigth],...
|
tomwalters@0
|
864 'Callback',callbackstr,...
|
tomwalters@0
|
865 'String',userstr,...
|
tomwalters@0
|
866 'Style','edit',...
|
tomwalters@0
|
867 'enable',enableval,...
|
tomwalters@0
|
868 'HorizontalAlignment','left',...
|
tomwalters@0
|
869 'Tag',sprintf('other_entry%d',general_line_count),...
|
tomwalters@0
|
870 'Userdata',param.text);
|
tomwalters@0
|
871 params=sethandle(params,param.text,hand2,param.panel,2);
|
tomwalters@0
|
872 % params=sethandle(params,param.text,param.panel,hand2,2);
|
tomwalters@0
|
873 end
|
tomwalters@0
|
874 case {'filename','directoryname'}
|
tomwalters@0
|
875 if current_panel_count==1
|
tomwalters@0
|
876 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
877 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
878 else
|
tomwalters@0
|
879 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
880 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
881 end
|
tomwalters@0
|
882
|
tomwalters@0
|
883 hand = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
884 'Parent',parentpanel,...
|
tomwalters@0
|
885 'Units','characters',...
|
tomwalters@0
|
886 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
887 'Position',[pos_x pos_y filenamelength elementhigth],...
|
tomwalters@0
|
888 'enable',enableval,...
|
tomwalters@0
|
889 'string',param.value,...
|
tomwalters@0
|
890 'Style','edit',...
|
tomwalters@0
|
891 'Callback',callbackstr,...
|
tomwalters@0
|
892 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
893 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
|
tomwalters@0
|
894 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
895 % and a button
|
tomwalters@0
|
896 pos_x=pos_x+filenamelength+2;
|
tomwalters@0
|
897 str=' select...';
|
tomwalters@0
|
898 width=length(str);
|
tomwalters@0
|
899 hand2 = uicontrol(... % string edit box
|
tomwalters@0
|
900 'Parent',parentpanel,...
|
tomwalters@0
|
901 'Units','characters',...
|
tomwalters@0
|
902 'Position',[pos_x pos_y width elementhigth+0.2],...
|
tomwalters@0
|
903 'Callback',callbackstr,...
|
tomwalters@0
|
904 'String',str,...
|
tomwalters@0
|
905 'Style','pushbutton',...
|
tomwalters@0
|
906 'HorizontalAlignment','left',...
|
tomwalters@0
|
907 'enable',enableval,...
|
tomwalters@0
|
908 'Tag',sprintf('other_entry%d',general_line_count),...
|
tomwalters@0
|
909 'Userdata',param.text);
|
tomwalters@0
|
910 params=sethandle(params,param.text,hand2,param.panel,2);
|
tomwalters@0
|
911 % params=sethandle(params,param.text,param.panel,hand2,2);
|
tomwalters@0
|
912
|
tomwalters@0
|
913 case 'button'
|
tomwalters@0
|
914 textlen=length(param.text)+4;
|
tomwalters@0
|
915 buttonwidth=2*spacearoundtext+textlen;
|
tomwalters@0
|
916 if current_panel_count==1
|
tomwalters@0
|
917 buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown+0.5;
|
tomwalters@0
|
918 else
|
tomwalters@0
|
919 buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown-3+0.5;
|
tomwalters@0
|
920 end
|
tomwalters@0
|
921
|
tomwalters@0
|
922 hand = uicontrol(... % button
|
tomwalters@0
|
923 'Parent',parentpanel,...
|
tomwalters@0
|
924 'Units','characters',...
|
tomwalters@0
|
925 'Callback',callbackstr,...
|
tomwalters@0
|
926 'Position',[buttonoffset+2*leftoffset buttonposy+0.1 buttonwidth 1.8],...
|
tomwalters@0
|
927 'String',param.text,...
|
tomwalters@0
|
928 'Style','pushbutton',...
|
tomwalters@0
|
929 'enable',enableval,...
|
tomwalters@0
|
930 'KeyPressFcn',@doFigureKeyPress , ...
|
tomwalters@0
|
931 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
932 'Userdata',param.text);
|
tomwalters@0
|
933 % 'backgroundcolor',[0.5 1 1],...
|
tomwalters@0
|
934 % 'foregroundcolor',[0.5 1 1],...
|
tomwalters@0
|
935 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
936
|
tomwalters@0
|
937 if param.isdefaultbutton==1
|
tomwalters@0
|
938 setappdata(guihandle, 'DefaultValid', true);
|
tomwalters@0
|
939 h = uicontrol(...
|
tomwalters@0
|
940 'Units','characters',...
|
tomwalters@0
|
941 'BackgroundColor', 'k', ...
|
tomwalters@0
|
942 'Style','frame',...
|
tomwalters@0
|
943 'Position',[buttonoffset+2*leftoffset-0.5 buttonposy-0.05 buttonwidth+0.9 1.9],...
|
tomwalters@0
|
944 'Parent',parentpanel...
|
tomwalters@0
|
945 );
|
tomwalters@0
|
946 uistack(h,'bottom')
|
tomwalters@0
|
947 end
|
tomwalters@0
|
948
|
tomwalters@0
|
949 case 'pop-up menu'
|
tomwalters@0
|
950 if current_panel_count==1
|
tomwalters@0
|
951 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset;
|
tomwalters@0
|
952 pos_y=general_line_count*rowheight-all_y_offset;
|
tomwalters@0
|
953 else
|
tomwalters@0
|
954 pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3;
|
tomwalters@0
|
955 pos_y=linecount(current_panel_count)*rowheight-all_y_offset;
|
tomwalters@0
|
956 end
|
tomwalters@0
|
957
|
tomwalters@0
|
958 hand = uicontrol(... % bool: radiobutton
|
tomwalters@0
|
959 'Parent',parentpanel,...
|
tomwalters@0
|
960 'Units','characters',...
|
tomwalters@0
|
961 'BackgroundColor',[1 1 1],...
|
tomwalters@0
|
962 'Position',[pos_x pos_y filenamelength elementhigth],...
|
tomwalters@0
|
963 'string',param.possible_values,...
|
tomwalters@0
|
964 'Style','popupmenu',...
|
tomwalters@0
|
965 'enable',enableval,...
|
tomwalters@0
|
966 'Callback',callbackstr,...
|
tomwalters@0
|
967 'Tag',sprintf('entry%d',general_line_count),...
|
tomwalters@0
|
968 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear
|
tomwalters@0
|
969 params=sethandle(params,param.text,hand,param.panel);
|
tomwalters@0
|
970 end
|
tomwalters@0
|
971
|
tomwalters@0
|
972 linecount(current_panel_count)=linecount(current_panel_count)+1;
|
tomwalters@0
|
973 general_line_count=general_line_count+1;
|
tomwalters@0
|
974 end
|
tomwalters@0
|
975
|
tomwalters@0
|
976 hsingleton = guihandle;
|
tomwalters@0
|
977
|
tomwalters@0
|
978
|
tomwalters@0
|
979 % --- Handles default parameterguiDE parametergui creation and callback dispatch
|
tomwalters@0
|
980 function varargout = parametergui_mainfcn(parametergui_State, varargin)
|
tomwalters@0
|
981
|
tomwalters@0
|
982 parametergui_StateFields = {'parametergui_Name'
|
tomwalters@0
|
983 'parametergui_Singleton'
|
tomwalters@0
|
984 'parametergui_OpeningFcn'
|
tomwalters@0
|
985 'parametergui_OutputFcn'
|
tomwalters@0
|
986 'parametergui_LayoutFcn'
|
tomwalters@0
|
987 'parametergui_Callback'};
|
tomwalters@0
|
988 parametergui_Mfile = '';
|
tomwalters@0
|
989 for i=1:length(parametergui_StateFields)
|
tomwalters@0
|
990 if ~isfield(parametergui_State, parametergui_StateFields{i})
|
tomwalters@0
|
991 error('Could not find field %s in the parametergui_State struct in parametergui M-file %s', parametergui_StateFields{i}, parametergui_Mfile);
|
tomwalters@0
|
992 elseif isequal(parametergui_StateFields{i}, 'parametergui_Name')
|
tomwalters@0
|
993 parametergui_Mfile = [getfield(parametergui_State, parametergui_StateFields{i}), '.m'];
|
tomwalters@0
|
994 end
|
tomwalters@0
|
995 end
|
tomwalters@0
|
996
|
tomwalters@0
|
997 numargin = length(varargin);
|
tomwalters@0
|
998
|
tomwalters@0
|
999 if numargin == 0
|
tomwalters@0
|
1000 % parametergui
|
tomwalters@0
|
1001 % create the parametergui
|
tomwalters@0
|
1002 parametergui_Create = 1;
|
tomwalters@0
|
1003 elseif numargin > 3 && ischar(varargin{1}) && ishandle(varargin{2})
|
tomwalters@0
|
1004 % parametergui('CALLBACK',hObject,eventData,handles,...)
|
tomwalters@0
|
1005 parametergui_Create = 0;
|
tomwalters@0
|
1006 else
|
tomwalters@0
|
1007 % parametergui(...)
|
tomwalters@0
|
1008 % create the parametergui and hand varargin to the openingfcn
|
tomwalters@0
|
1009 parametergui_Create = 1;
|
tomwalters@0
|
1010 end
|
tomwalters@0
|
1011
|
tomwalters@0
|
1012 %SB: return values
|
tomwalters@0
|
1013 global params
|
tomwalters@0
|
1014
|
tomwalters@0
|
1015 if parametergui_Create == 0
|
tomwalters@0
|
1016 varargin{1} = parametergui_State.parametergui_Callback;
|
tomwalters@0
|
1017 if nargout
|
tomwalters@0
|
1018 [varargout{1:nargout}] = feval(varargin{:});
|
tomwalters@0
|
1019 else
|
tomwalters@0
|
1020 feval(varargin{:});
|
tomwalters@0
|
1021 end
|
tomwalters@0
|
1022 else
|
tomwalters@0
|
1023 if parametergui_State.parametergui_Singleton
|
tomwalters@0
|
1024 parametergui_SingletonOpt = 'reuse';
|
tomwalters@0
|
1025 else
|
tomwalters@0
|
1026 parametergui_SingletonOpt = 'new';
|
tomwalters@0
|
1027 end
|
tomwalters@0
|
1028
|
tomwalters@0
|
1029 % Open fig file with stored settings. Note: This executes all component
|
tomwalters@0
|
1030 % specific CreateFunctions with an empty HANDLES structure.
|
tomwalters@0
|
1031 % make params global, so that I can access them in the generation
|
tomwalters@0
|
1032 % function
|
tomwalters@0
|
1033 params=varargin{1};
|
tomwalters@0
|
1034
|
tomwalters@0
|
1035 % Do feval on layout code in m-file if it exists
|
tomwalters@0
|
1036 if ~isempty(parametergui_State.parametergui_LayoutFcn)
|
tomwalters@0
|
1037 gui_hFigure = feval(parametergui_State.parametergui_LayoutFcn, parametergui_SingletonOpt);
|
tomwalters@0
|
1038 % SB: the original one finds the wrong one, possible because it just looks
|
tomwalters@0
|
1039 % for the first one with the m-file. We can do better:
|
tomwalters@0
|
1040
|
tomwalters@0
|
1041 all_childs=get(0,'children');
|
tomwalters@0
|
1042 this_name=getname(params);
|
tomwalters@0
|
1043 for i=1:length(all_childs)
|
tomwalters@0
|
1044 name=get(all_childs(i),'name');
|
tomwalters@0
|
1045 if strcmp(name,this_name)
|
tomwalters@0
|
1046 gui_hFigure=all_childs(i);
|
tomwalters@0
|
1047 break
|
tomwalters@0
|
1048 end
|
tomwalters@0
|
1049 end
|
tomwalters@0
|
1050
|
tomwalters@0
|
1051 else
|
tomwalters@0
|
1052 gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt);
|
tomwalters@0
|
1053 % If the figure has InparameterguiInitialization it was not completely created
|
tomwalters@0
|
1054 % on the last pass. Delete this handle and try again.
|
tomwalters@0
|
1055 if isappdata(gui_hFigure, 'InparameterguiInitialization')
|
tomwalters@0
|
1056 delete(gui_hFigure);
|
tomwalters@0
|
1057 gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt);
|
tomwalters@0
|
1058 end
|
tomwalters@0
|
1059 end
|
tomwalters@0
|
1060
|
tomwalters@0
|
1061 % Set flag to indicate starting parametergui initialization
|
tomwalters@0
|
1062 setappdata(gui_hFigure,'InparameterguiInitialization',1);
|
tomwalters@0
|
1063
|
tomwalters@0
|
1064 % Fetch parameterguiDE Application params
|
tomwalters@0
|
1065 parametergui_Options = getappdata(gui_hFigure,'parameterguiDEOptions');
|
tomwalters@0
|
1066
|
tomwalters@0
|
1067 if ~isappdata(gui_hFigure,'parameterguiOnScreen')
|
tomwalters@0
|
1068 % Adjust background color
|
tomwalters@0
|
1069 if parametergui_Options.syscolorfig
|
tomwalters@0
|
1070 set(gui_hFigure,'Color', [0.831372549019608 0.815686274509804 0.784313725490196]);
|
tomwalters@0
|
1071 end
|
tomwalters@0
|
1072
|
tomwalters@0
|
1073 % Generate HANDLES structure and store with guidata
|
tomwalters@0
|
1074 guidata(gui_hFigure, guihandles(gui_hFigure));
|
tomwalters@0
|
1075 end
|
tomwalters@0
|
1076
|
tomwalters@0
|
1077
|
tomwalters@0
|
1078
|
tomwalters@0
|
1079 % If user specified 'Visible','off' in p/v pairs, don't make the figure
|
tomwalters@0
|
1080 % visible.
|
tomwalters@0
|
1081 parametergui_MakeVisible = 1;
|
tomwalters@0
|
1082 for ind=1:2:length(varargin)
|
tomwalters@0
|
1083 if length(varargin) == ind
|
tomwalters@0
|
1084 break;
|
tomwalters@0
|
1085 end
|
tomwalters@0
|
1086 len1 = min(length('visible'),length(varargin{ind}));
|
tomwalters@0
|
1087 len2 = min(length('off'),length(varargin{ind+1}));
|
tomwalters@0
|
1088 if ischar(varargin{ind}) && ischar(varargin{ind+1}) && ...
|
tomwalters@0
|
1089 strncmpi(varargin{ind},'visible',len1) && len2 > 1
|
tomwalters@0
|
1090 if strncmpi(varargin{ind+1},'off',len2)
|
tomwalters@0
|
1091 parametergui_MakeVisible = 0;
|
tomwalters@0
|
1092 elseif strncmpi(varargin{ind+1},'on',len2)
|
tomwalters@0
|
1093 parametergui_MakeVisible = 1;
|
tomwalters@0
|
1094 end
|
tomwalters@0
|
1095 end
|
tomwalters@0
|
1096 end
|
tomwalters@0
|
1097
|
tomwalters@0
|
1098 % Check for figure param value pairs
|
tomwalters@0
|
1099 for index=1:2:length(varargin)
|
tomwalters@0
|
1100 if length(varargin) == index
|
tomwalters@0
|
1101 break;
|
tomwalters@0
|
1102 end
|
tomwalters@0
|
1103 try
|
tomwalters@0
|
1104 set(gui_hFigure, varargin{index},vargin{index+1});
|
tomwalters@0
|
1105 catch
|
tomwalters@0
|
1106 break
|
tomwalters@0
|
1107 end
|
tomwalters@0
|
1108 end
|
tomwalters@0
|
1109
|
tomwalters@0
|
1110 % If handle visibility is set to 'callback', turn it on until finished
|
tomwalters@0
|
1111 % with OpeningFcn
|
tomwalters@0
|
1112 parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
|
tomwalters@0
|
1113 if strcmp(parametergui_HandleVisibility, 'callback')
|
tomwalters@0
|
1114 set(gui_hFigure,'HandleVisibility', 'on');
|
tomwalters@0
|
1115 end
|
tomwalters@0
|
1116
|
tomwalters@0
|
1117 % SB: save the user structure to the handle struct
|
tomwalters@0
|
1118 handles=guidata(gui_hFigure);
|
tomwalters@0
|
1119 handles.params=params;
|
tomwalters@0
|
1120 guidata(gui_hFigure, handles);
|
tomwalters@0
|
1121 feval(parametergui_State.parametergui_OpeningFcn, gui_hFigure, [], handles, varargin{:});
|
tomwalters@0
|
1122
|
tomwalters@0
|
1123
|
tomwalters@0
|
1124
|
tomwalters@0
|
1125
|
tomwalters@0
|
1126 if ishandle(gui_hFigure)
|
tomwalters@0
|
1127 % Update handle visibility
|
tomwalters@0
|
1128 set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility);
|
tomwalters@0
|
1129
|
tomwalters@0
|
1130 % Make figure visible
|
tomwalters@0
|
1131 if parametergui_MakeVisible
|
tomwalters@0
|
1132 set(gui_hFigure, 'Visible', 'on')
|
tomwalters@0
|
1133 if parametergui_Options.singleton
|
tomwalters@0
|
1134 setappdata(gui_hFigure,'parameterguiOnScreen', 1);
|
tomwalters@0
|
1135 end
|
tomwalters@0
|
1136 end
|
tomwalters@0
|
1137
|
tomwalters@0
|
1138 % Done with parametergui initialization
|
tomwalters@0
|
1139 rmappdata(gui_hFigure,'InparameterguiInitialization');
|
tomwalters@0
|
1140 end
|
tomwalters@0
|
1141
|
tomwalters@0
|
1142 % If handle visibility is set to 'callback', turn it on until finished with
|
tomwalters@0
|
1143 % OutputFcn
|
tomwalters@0
|
1144 if ishandle(gui_hFigure)
|
tomwalters@0
|
1145 parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
|
tomwalters@0
|
1146 if strcmp(parametergui_HandleVisibility, 'callback')
|
tomwalters@0
|
1147 set(gui_hFigure,'HandleVisibility', 'on');
|
tomwalters@0
|
1148 end
|
tomwalters@0
|
1149 parametergui_Handles = guidata(gui_hFigure);
|
tomwalters@0
|
1150 else
|
tomwalters@0
|
1151 parametergui_Handles = [];
|
tomwalters@0
|
1152 end
|
tomwalters@0
|
1153
|
tomwalters@0
|
1154
|
tomwalters@0
|
1155 % SB: if the window was reused then update the handles in the params, so
|
tomwalters@0
|
1156 % that they can be recalculated.
|
tomwalters@0
|
1157 % this only works when the number and type of variables have not
|
tomwalters@0
|
1158 % changed in between
|
tomwalters@0
|
1159 if strcmp(parametergui_SingletonOpt,'reuse')
|
tomwalters@0
|
1160 dsnew=get(handles.params); % the new parameter without handles
|
tomwalters@0
|
1161 nr_ds=length(dsnew);
|
tomwalters@0
|
1162 fields=fieldnames(handles);
|
tomwalters@0
|
1163 for i=1:nr_ds % we have to find the uicontrol with these two features:
|
tomwalters@0
|
1164 searchtext=dsnew{i}.text;
|
tomwalters@0
|
1165 searchpanel=dsnew{i}.panel;
|
tomwalters@0
|
1166 searchtype=dsnew{i}.type;
|
tomwalters@0
|
1167 nr_h=length(fields);
|
tomwalters@0
|
1168 for j=1:nr_h % search through all
|
tomwalters@0
|
1169 fh=getfield(handles,fields{j});
|
tomwalters@0
|
1170 if ishandle(fh)
|
tomwalters@0
|
1171 type=get(fh,'type');
|
tomwalters@0
|
1172 [nr_enty,len]=size(type);
|
tomwalters@0
|
1173 if nr_enty>1
|
tomwalters@0
|
1174 type=type(1);
|
tomwalters@0
|
1175 secondh=fh(1);
|
tomwalters@0
|
1176 fh=fh(2);
|
tomwalters@0
|
1177 end
|
tomwalters@0
|
1178 if strcmp(type,'uipanel') && strcmp(searchtype,'panel')
|
tomwalters@0
|
1179 panelname=get(fh,'title');
|
tomwalters@0
|
1180 if strcmp(searchpanel,panelname)
|
tomwalters@0
|
1181 params=sethandle(params,searchtext,fh,searchpanel); % set the handle
|
tomwalters@0
|
1182 break
|
tomwalters@0
|
1183 end
|
tomwalters@0
|
1184 end
|
tomwalters@0
|
1185 % if its not a panel then its an uicontrol
|
tomwalters@0
|
1186 if strcmp(type,'uicontrol')
|
tomwalters@0
|
1187 parent=get(fh,'parent');
|
tomwalters@0
|
1188 panelname=get(parent,'title'); % this is the panel
|
tomwalters@0
|
1189 if strcmp(panelname,'')
|
tomwalters@0
|
1190 panelname='all';
|
tomwalters@0
|
1191 end
|
tomwalters@0
|
1192 uiname=get(fh,'UserData');
|
tomwalters@0
|
1193
|
tomwalters@0
|
1194 if strcmp(searchpanel,panelname) && strcmp(searchtext,uiname)
|
tomwalters@0
|
1195 params=sethandle(params,searchtext,fh,searchpanel); % set the handle
|
tomwalters@0
|
1196 if nr_enty>1
|
tomwalters@0
|
1197 params=sethandle(params,searchtext,secondh,searchpanel,2); % set the handle
|
tomwalters@0
|
1198 end
|
tomwalters@0
|
1199 break
|
tomwalters@0
|
1200 end
|
tomwalters@0
|
1201
|
tomwalters@0
|
1202 % newstyle=get(fh,'style');
|
tomwalters@0
|
1203 % if strcmp(orgstyle,newstyle)
|
tomwalters@0
|
1204 % str2=get(fh,'UserData');
|
tomwalters@0
|
1205 % if strcmp(str1,str2)
|
tomwalters@0
|
1206 % params=sethandle(params,str1,fh); % set the handle
|
tomwalters@0
|
1207 % style=get(fh,'style');
|
tomwalters@0
|
1208 % switch style
|
tomwalters@0
|
1209 % case 'edit'
|
tomwalters@0
|
1210 % params=set(params,str1,get(fh,'string'));
|
tomwalters@0
|
1211 % case {'checkbox','radiobox','int','float'}
|
tomwalters@0
|
1212 % params=set(params,str1,get(fh,'value'));
|
tomwalters@0
|
1213 % params=set(params,str1,get(fh,'value'));
|
tomwalters@0
|
1214 % end
|
tomwalters@0
|
1215 % break
|
tomwalters@0
|
1216 % end
|
tomwalters@0
|
1217 % end
|
tomwalters@0
|
1218 end
|
tomwalters@0
|
1219 end
|
tomwalters@0
|
1220 % h=gethandle(params,searchtext,searchpanel);
|
tomwalters@0
|
1221 end
|
tomwalters@0
|
1222 end
|
tomwalters@0
|
1223 handles.params=params;
|
tomwalters@0
|
1224 guidata(gui_hFigure, handles);
|
tomwalters@0
|
1225 end
|
tomwalters@0
|
1226
|
tomwalters@0
|
1227
|
tomwalters@0
|
1228
|
tomwalters@0
|
1229 if nargout
|
tomwalters@0
|
1230 global result
|
tomwalters@0
|
1231 parametergui_Handles=result;
|
tomwalters@0
|
1232 if strcmp(getmode(handles.params),'nonmodal')
|
tomwalters@0
|
1233 result=params;
|
tomwalters@0
|
1234 end
|
tomwalters@0
|
1235 [varargout{1:nargout}] = feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles);
|
tomwalters@0
|
1236 else
|
tomwalters@0
|
1237 feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles);
|
tomwalters@0
|
1238 end
|
tomwalters@0
|
1239
|
tomwalters@0
|
1240 if ishandle(gui_hFigure)
|
tomwalters@0
|
1241 set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility);
|
tomwalters@0
|
1242 end
|
tomwalters@0
|
1243
|
tomwalters@0
|
1244
|
tomwalters@0
|
1245 end
|
tomwalters@0
|
1246
|
tomwalters@0
|
1247
|
tomwalters@0
|
1248 function gui_hFigure = local_openfig(name, singleton)
|
tomwalters@0
|
1249 if nargin('openfig') == 3
|
tomwalters@0
|
1250 gui_hFigure = openfig(name, singleton, 'auto');
|
tomwalters@0
|
1251 else
|
tomwalters@0
|
1252 % OPENFIG did not accept 3rd input argument until R13,
|
tomwalters@0
|
1253 % toggle default figure visible to prevent the figure
|
tomwalters@0
|
1254 % from showing up too soon.
|
tomwalters@0
|
1255 parametergui_OldDefaultVisible = get(0,'defaultFigureVisible');
|
tomwalters@0
|
1256 set(0,'defaultFigureVisible','off');
|
tomwalters@0
|
1257 gui_hFigure = openfig(name, singleton);
|
tomwalters@0
|
1258 set(0,'defaultFigureVisible',parametergui_OldDefaultVisible);
|
tomwalters@0
|
1259 end
|
tomwalters@0
|
1260
|
tomwalters@0
|
1261 function doFigureKeyPress(obj, evd)
|
tomwalters@0
|
1262 switch(evd.Key)
|
tomwalters@0
|
1263 case {'return','space'}
|
tomwalters@0
|
1264 if getappdata(gcbf,'DefaultValid')
|
tomwalters@0
|
1265 handles=guidata(gcbf);
|
tomwalters@0
|
1266 generic_Callback([],'default',handles)
|
tomwalters@0
|
1267 end
|
tomwalters@0
|
1268 case 'escape'
|
tomwalters@0
|
1269 close(gcbf)
|
tomwalters@0
|
1270 end
|