annotate aim-mat/tools/data_gui.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % support file for 'aim-mat'
tomwalters@0 2 %
bleeck@3 3 % (c) 2011, University of Southampton
bleeck@3 4 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 5 % download of current version is on the soundsoftware site:
bleeck@3 6 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 7 % documentation and everything is on http://www.acousticscale.org
bleeck@3 8
tomwalters@0 9
tomwalters@0 10 function varargout = data_gui(varargin)
tomwalters@0 11 % allow some nice action with a gui.
tomwalters@0 12 % Example: try:
tomwalters@0 13 % function plot_psth(data,options)
tomwalters@0 14 % options.startms=0;
tomwalters@0 15 % options.duration=data.expparams.spike_window_end_ms;
tomwalters@0 16 % options.binwidth=1;
tomwalters@0 17 % options.info.buttontext={'plot psth','save as ascii'};
tomwalters@0 18 % options.info.data=data;
tomwalters@0 19 % options.info.title='psth parameter';
tomwalters@0 20 % options.info.callback={'plot_psth(data,options,''plot'')','plot_psth(data,options,''save_as_ascii'')'};
tomwalters@0 21 % out.handle=data_gui(options);
tomwalters@0 22 %
tomwalters@0 23
tomwalters@0 24 % Begin initialization code - DO NOT EDIT
tomwalters@0 25
tomwalters@0 26 % find out, if we want a new window or the old one:
tomwalters@0 27 if length(varargin)==1
tomwalters@0 28 gui_Singleton = 0; % normally we want a new window
tomwalters@0 29 all_childs=get(0,'children');
tomwalters@0 30 this_name=varargin{1}.info.title;
tomwalters@0 31 for i=1:length(all_childs)
tomwalters@0 32 name=get(all_childs(i),'name');
tomwalters@0 33 if strcmp(name,this_name)
tomwalters@0 34 gui_Singleton = 1; % but if there is a copy already, take that window instead
tomwalters@0 35 % and bring it to the front
tomwalters@0 36 figure(all_childs(i));
tomwalters@0 37 end
tomwalters@0 38 end
tomwalters@0 39 else
tomwalters@0 40 gui_Singleton = 1; % but if there is a copy already, take that window instead
tomwalters@0 41 end
tomwalters@0 42
tomwalters@0 43 gui_State = struct('gui_Name', mfilename, ...
tomwalters@0 44 'gui_Singleton', gui_Singleton, ...
tomwalters@0 45 'gui_OpeningFcn', @data_gui_OpeningFcn, ...
tomwalters@0 46 'gui_OutputFcn', @data_gui_OutputFcn, ...
tomwalters@0 47 'gui_LayoutFcn', @data_gui_LayoutFcn, ...
tomwalters@0 48 'gui_Callback', []);
tomwalters@0 49 if nargin & isstr(varargin{1})
tomwalters@0 50 gui_State.gui_Callback = str2func(varargin{1});
tomwalters@0 51 end
tomwalters@0 52
tomwalters@0 53 if nargout
tomwalters@0 54 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
tomwalters@0 55 else
tomwalters@0 56 gui_mainfcn(gui_State, varargin{:});
tomwalters@0 57 end
tomwalters@0 58 % End initialization code - DO NOT EDIT
tomwalters@0 59
tomwalters@0 60
tomwalters@0 61 % --- Executes just before data_gui is made visible.
tomwalters@0 62 function data_gui_OpeningFcn(hObject, eventdata, handles, varargin)
tomwalters@0 63 % This function has no output args, see OutputFcn.
tomwalters@0 64 % hObject handle to figure
tomwalters@0 65 % eventdata reserved - to be defined in a future version of MATLAB
tomwalters@0 66 % handles structure with handles and user data (see GUIDATA)
tomwalters@0 67 % varargin command line arguments to data_gui (see VARARGIN)
tomwalters@0 68
tomwalters@0 69 % Choose default command line output for data_gui
tomwalters@0 70 handles.output = hObject;
tomwalters@0 71
tomwalters@0 72
tomwalters@0 73 % copy the options in place
tomwalters@0 74 options=varargin{1};
tomwalters@0 75 handles.options=options;
tomwalters@0 76
tomwalters@0 77 % Update handles structure
tomwalters@0 78 guidata(hObject, handles);
tomwalters@0 79
tomwalters@0 80 global result;
tomwalters@0 81 % UIWAIT makes data_gui wait for user response (see UIRESUME)
tomwalters@0 82
tomwalters@0 83 if ~isfield(options.info,'default_value')
tomwalters@0 84 result=''; % not determined yet
tomwalters@0 85 else
tomwalters@0 86 result=options.info.default_value;
tomwalters@0 87 end
tomwalters@0 88
tomwalters@0 89 if isfield(options.info,'mode') && strcmp(options.info.mode,'modal')
tomwalters@0 90 uiwait(handles.figure1);
tomwalters@0 91 end
tomwalters@0 92
tomwalters@0 93
tomwalters@0 94
tomwalters@0 95
tomwalters@0 96 % --- Outputs from this function are returned to the command line.
tomwalters@0 97 function varargout = data_gui_OutputFcn(hObject, eventdata, handles)
tomwalters@0 98 % varargout cell array for returning output args (see VARARGOUT);
tomwalters@0 99 % hObject handle to figure
tomwalters@0 100 % eventdata reserved - to be defined in a future version of MATLAB
tomwalters@0 101 % handles structure with handles and user data (see GUIDATA)
tomwalters@0 102
tomwalters@0 103 % Get default command line output from handles structure
tomwalters@0 104 global result;
tomwalters@0 105 varargout{1} = result;
tomwalters@0 106
tomwalters@0 107
tomwalters@0 108 % --- Executes on button press in pushbutton1.
tomwalters@0 109 function pushbuttons_Callback(hObject, eventdata, handles)
tomwalters@0 110 % hObject handle to pushbutton1 (see GCBO)
tomwalters@0 111 % eventdata reserved - to be defined in a future version of MATLAB
tomwalters@0 112 % handles structure with handles and user data (see GUIDATA)
tomwalters@0 113 options=handles.options;
tomwalters@0 114
tomwalters@0 115
tomwalters@0 116 if iscell(handles.options.info.buttontext)
tomwalters@0 117 nr_buttons=length(handles.options.info.buttontext);
tomwalters@0 118 else
tomwalters@0 119 nr_buttons=1;
tomwalters@0 120 end
tomwalters@0 121 for ii=1:nr_buttons
tomwalters@0 122 pushtag=sprintf('pushbutton%d',ii);
tomwalters@0 123 handstr=sprintf('hand=handles.%s;',pushtag);
tomwalters@0 124 eval(handstr);
tomwalters@0 125 if hObject==hand;
tomwalters@0 126 buttonnumber=ii;
tomwalters@0 127 break;
tomwalters@0 128 end
tomwalters@0 129 end
tomwalters@0 130 % dispatch all data values to the options structure
tomwalters@0 131
tomwalters@0 132 options=handles.options;
tomwalters@0 133 % radiobuttons=options.toggleradiobuttons;
tomwalters@0 134 % nr_but=length(radiobuttons);
tomwalters@0 135 nr_hands=length(fields(handles));
tomwalters@0 136 all_fields=fields(handles);
tomwalters@0 137 % set all to 0
tomwalters@0 138 linecount=1;
tomwalters@0 139 params=fields(options);
tomwalters@0 140 nr_params=length(params);
tomwalters@0 141
tomwalters@0 142 params=fields(options);
tomwalters@0 143 nr_params=length(params);
tomwalters@0 144 linecount=1;
tomwalters@0 145
tomwalters@0 146 for i=1:nr_params % look through all parameter and find the assoziated handle for it
tomwalters@0 147 if ~strcmp(params(i),'info')
tomwalters@0 148 for j=1:nr_hands % go through all handles. One must be it
tomwalters@0 149 curhand=getfield(handles,all_fields{j});
tomwalters@0 150 if ishandle(curhand)
tomwalters@0 151 fieldname=all_fields{j};
tomwalters@0 152 allfi=get(curhand);
tomwalters@0 153 if isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'edit')
tomwalters@0 154 fieldvalue=get(curhand,'String');
tomwalters@0 155 val=str2num(fieldvalue{1});
tomwalters@0 156 stuctname=get(curhand,'userdata');
tomwalters@0 157 if isnumeric(val) && ~isempty(val)
tomwalters@0 158 options=setfield(options,stuctname,val);
tomwalters@0 159 else
tomwalters@0 160 options=setfield(options,stuctname,fieldvalue{1});
tomwalters@0 161 end
tomwalters@0 162 linecount=linecount+1;
tomwalters@0 163 elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'radiobutton')
tomwalters@0 164 val=get(curhand,'value');
tomwalters@0 165 nr=get(curhand,'Userdata');
tomwalters@0 166 options.toggleradiobuttons{nr}.value=val;
tomwalters@0 167 elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'checkbox')
tomwalters@0 168 val=get(curhand,'value');
tomwalters@0 169 nr=get(curhand,'Userdata');
tomwalters@0 170 options.checkboxes{nr}.value=val;
tomwalters@0 171 end
tomwalters@0 172 end
tomwalters@0 173 end
tomwalters@0 174 end
tomwalters@0 175 end
tomwalters@0 176
tomwalters@0 177
tomwalters@0 178 data=options.info.data;
tomwalters@0 179 if nr_buttons==1
tomwalters@0 180 callline=sprintf('%s;',options.info.callback);
tomwalters@0 181 else
tomwalters@0 182 callline=sprintf('%s;',options.info.callback{buttonnumber});
tomwalters@0 183 end
tomwalters@0 184 eval(callline);
tomwalters@0 185
tomwalters@0 186 % does the function give back a value?
tomwalters@0 187 gleichwo=strfind(callline,'=');
tomwalters@0 188 if ~isempty(gleichwo)
tomwalters@0 189 retvar=callline(1:gleichwo-1);
tomwalters@0 190 global result;
tomwalters@0 191 resstr=sprintf('result=%s;',retvar);
tomwalters@0 192 eval(resstr);
tomwalters@0 193 end
tomwalters@0 194
tomwalters@0 195
tomwalters@0 196 function togglebuttons_Callback(hObject, eventdata, handles)
tomwalters@0 197 if get(hObject,'value')==0
tomwalters@0 198 return
tomwalters@0 199 end
tomwalters@0 200 options=handles.options;
tomwalters@0 201 radiobuttons=options.toggleradiobuttons;
tomwalters@0 202 nr_but=length(radiobuttons);
tomwalters@0 203 nr_hands=length(fields(handles));
tomwalters@0 204 all_fields=fields(handles);
tomwalters@0 205 % set all to 0
tomwalters@0 206 for i=1:nr_hands
tomwalters@0 207 curhand=getfield(handles,all_fields{i});
tomwalters@0 208 if ishandle(curhand)
tomwalters@0 209 name1=get(curhand,'tag');
tomwalters@0 210 for j=1:nr_but
tomwalters@0 211 name2=sprintf('togglebutton%d',j);
tomwalters@0 212 if strcmp(name1,name2) && hObject~=curhand
tomwalters@0 213 set(curhand,'value',0);
tomwalters@0 214 end
tomwalters@0 215 end
tomwalters@0 216 end
tomwalters@0 217 end
tomwalters@0 218
tomwalters@0 219 % --- Creates and returns a handle to the GUI figure.
tomwalters@0 220 function h1 = data_gui_LayoutFcn(policy)
tomwalters@0 221 % policy - create a new figure or use a singleton. 'new' or 'reuse'.
tomwalters@0 222
tomwalters@0 223 persistent hsingleton;
tomwalters@0 224 if strcmpi(policy, 'reuse') & ishandle(hsingleton)
tomwalters@0 225 h1 = hsingleton;
tomwalters@0 226 return;
tomwalters@0 227 end
tomwalters@0 228 % collect my own options to generate parmeters on the fly
tomwalters@0 229 global options
tomwalters@0 230
tomwalters@0 231 % now build from bottom to top a line of text and an edit box for each
tomwalters@0 232 % parameter
tomwalters@0 233 params=fields(options);
tomwalters@0 234 nr_params=length(params);
tomwalters@0 235 linecount=1;
tomwalters@0 236 % first find out, what the longest name is
tomwalters@0 237 maxxlen=0; % the longest text in width
tomwalters@0 238 maxylen=0; % essentially the number of lines
tomwalters@0 239 rowheight=2; % how high every row is
tomwalters@0 240 elementhigth=1.5; % how high every element is
tomwalters@0 241 edit_width=20; % how wide an edit box is
tomwalters@0 242 spacebetweentextandedit=5; % space between text and edit box
tomwalters@0 243 leftoffset=2; % offset of text to the left boundary (and right as well)
tomwalters@0 244
tomwalters@0 245 for i=1:nr_params
tomwalters@0 246 if ~strcmp(params(i),'info')
tomwalters@0 247 string_text=params{i};
tomwalters@0 248 textlen=length(string_text)+3;
tomwalters@0 249 maxxlen=max(maxxlen,textlen);
tomwalters@0 250 maxylen=maxylen+rowheight; % the distance between lines
tomwalters@0 251 end
tomwalters@0 252 if strcmp(params(i),'toggleradiobuttons')
tomwalters@0 253 radiobuttons=options.toggleradiobuttons;
tomwalters@0 254 nr_but=length(radiobuttons);
tomwalters@0 255 maxylen=maxylen+nr_but*rowheight; % the distance between lines
tomwalters@0 256 end
tomwalters@0 257
tomwalters@0 258 end
tomwalters@0 259
tomwalters@0 260 % the total size of the window is now:
tomwalters@0 261 window_width=maxxlen+spacebetweentextandedit+edit_width+2*leftoffset;
tomwalters@0 262 window_height=maxylen+3*leftoffset;
tomwalters@0 263 % get the size of the screen in chars
tomwalters@0 264 set(0,'units','char');
tomwalters@0 265 siz=get(0,'screensize');
tomwalters@0 266 screeen_height=siz(4);
tomwalters@0 267 screeen_width=siz(3);
tomwalters@0 268 set(0,'units','pixels'); % back to normal
tomwalters@0 269
tomwalters@0 270 % the figure
tomwalters@0 271 windoff=2; % offset from the top right corner
tomwalters@0 272 h1 = figure(...
tomwalters@0 273 'Units','characters',...
tomwalters@0 274 'PaperUnits',get(0,'defaultfigurePaperUnits'),...
tomwalters@0 275 'Color',[0.831372549019608 0.815686274509804 0.784313725490196],...
tomwalters@0 276 '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 277 'IntegerHandle','off',...
tomwalters@0 278 'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
tomwalters@0 279 'MenuBar','none',...
tomwalters@0 280 'Name',options.info.title,...
tomwalters@0 281 'NumberTitle','off',...
tomwalters@0 282 'PaperPosition',get(0,'defaultfigurePaperPosition'),...
tomwalters@0 283 'PaperSize',[20.98404194812 29.67743169791],...
tomwalters@0 284 'PaperType',get(0,'defaultfigurePaperType'),...
tomwalters@0 285 'Position',[screeen_width-window_width-windoff screeen_height-window_height-windoff window_width window_height],...
tomwalters@0 286 'Renderer',get(0,'defaultfigureRenderer'),...
tomwalters@0 287 'RendererMode','manual',...
tomwalters@0 288 'Resize','on',...
tomwalters@0 289 'HandleVisibility','callback',...
tomwalters@0 290 'Tag','figure1',...
tomwalters@0 291 'UserData',zeros(1,0));
tomwalters@0 292
tomwalters@0 293 % application data
tomwalters@0 294 setappdata(h1, 'GUIDEOptions', struct(...
tomwalters@0 295 'active_h', 1.020033e+002, ...
tomwalters@0 296 'taginfo', struct(...
tomwalters@0 297 'figure', 2, ...
tomwalters@0 298 'pushbutton', 2), ...
tomwalters@0 299 'override', 0, ...
tomwalters@0 300 'release', 13, ...
tomwalters@0 301 'resize', 'simple', ...
tomwalters@0 302 'accessibility', 'callback', ...
tomwalters@0 303 'mfile', 1, ...
tomwalters@0 304 'callbacks', 1, ...
tomwalters@0 305 'singleton', 1, ...
tomwalters@0 306 'syscolorfig', 1, ...
tomwalters@0 307 'lastSavedFile', 'c:\bla bla bla'));
tomwalters@0 308
tomwalters@0 309 % buttons
tomwalters@0 310 if iscell(options.info.buttontext)
tomwalters@0 311 nr_buttons=length(options.info.buttontext);
tomwalters@0 312 else
tomwalters@0 313 nr_buttons=1;
tomwalters@0 314 end
tomwalters@0 315 gesbtextlen=0;
tomwalters@0 316 boffset=2;
tomwalters@0 317 % for ii=1:nr_buttons
tomwalters@0 318 % if nr_buttons==1
tomwalters@0 319 % btext=options.info.buttontext;
tomwalters@0 320 % textlen=length(btext)+4;
tomwalters@0 321 % textx=(window_width-textlen)/2;
tomwalters@0 322 % fbtext{1}=btext;
tomwalters@0 323 % buttonposx(1)=textx-textlen/2;
tomwalters@0 324 % buttonwidth(1)=textlen+boffset;
tomwalters@0 325 % else
tomwalters@0 326 % btext=options.info.buttontext{ii};
tomwalters@0 327 % fbtext{ii}=btext;
tomwalters@0 328 % textlen=length(btext)+4;
tomwalters@0 329 %
tomwalters@0 330 % buttonposx(ii)=gesbtextlen+boffset;
tomwalters@0 331 % gesbtextlen=gesbtextlen+textlen+boffset;
tomwalters@0 332 %
tomwalters@0 333 % buttonwidth(ii)=textlen;
tomwalters@0 334 %
tomwalters@0 335 % end
tomwalters@0 336 % end
tomwalters@0 337 %
tomwalters@0 338 % for ii=1:nr_buttons
tomwalters@0 339 % callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))';
tomwalters@0 340 % pushtag=sprintf('pushbutton%d',ii);
tomwalters@0 341 % h2 = uicontrol(...
tomwalters@0 342 % 'Parent',h1,...
tomwalters@0 343 % 'Units','characters',...
tomwalters@0 344 % 'Callback',callbackstr,...
tomwalters@0 345 % 'ListboxTop',0,...
tomwalters@0 346 % 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],...
tomwalters@0 347 % 'String',fbtext{ii},...
tomwalters@0 348 % 'Tag',pushtag);
tomwalters@0 349 % options.buttonhandles(ii)=h2;
tomwalters@0 350 % end
tomwalters@0 351
tomwalters@0 352 for ii=1:nr_buttons
tomwalters@0 353 if nr_buttons==1
tomwalters@0 354 btext=options.info.buttontext;
tomwalters@0 355 textlen=length(btext)+4;
tomwalters@0 356 textx=(window_width-textlen)/2;
tomwalters@0 357 fbtext{1}=btext;
tomwalters@0 358 buttonposx(1)=textx-textlen/2;
tomwalters@0 359 buttonwidth(1)=textlen+boffset;
tomwalters@0 360 else
tomwalters@0 361 btext=options.info.buttontext{ii};
tomwalters@0 362 fbtext{ii}=btext;
tomwalters@0 363 textlen=length(btext)+4;
tomwalters@0 364
tomwalters@0 365 buttonposx(ii)=gesbtextlen+boffset;
tomwalters@0 366 gesbtextlen=gesbtextlen+textlen+boffset;
tomwalters@0 367
tomwalters@0 368 buttonwidth(ii)=textlen;
tomwalters@0 369
tomwalters@0 370 end
tomwalters@0 371 end
tomwalters@0 372
tomwalters@0 373 for ii=1:nr_buttons
tomwalters@0 374 callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))';
tomwalters@0 375 pushtag=sprintf('pushbutton%d',ii);
tomwalters@0 376 h2 = uicontrol(...
tomwalters@0 377 'Parent',h1,...
tomwalters@0 378 'Units','characters',...
tomwalters@0 379 'Callback',callbackstr,...
tomwalters@0 380 'ListboxTop',0,...
tomwalters@0 381 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],...
tomwalters@0 382 'String',fbtext{ii},...
tomwalters@0 383 'Tag',pushtag);
tomwalters@0 384 options.buttonhandles(ii)=h2;
tomwalters@0 385 end
tomwalters@0 386
tomwalters@0 387 % make the window wider if necessary
tomwalters@0 388
tomwalters@0 389 % the total size of the window is now:
tomwalters@0 390 new_window_width=window_width;
tomwalters@0 391 if buttonposx(end)+buttonwidth(end)+boffset >new_window_width
tomwalters@0 392 new_window_width=buttonposx(end)+buttonwidth(end)+boffset;
tomwalters@0 393 end
tomwalters@0 394
tomwalters@0 395 set(h1,'Position',[screeen_width-new_window_width-windoff screeen_height-window_height-windoff new_window_width window_height]);
tomwalters@0 396
tomwalters@0 397
tomwalters@0 398 % now put a text and an edit field on every line
tomwalters@0 399 % tagcount=1;
tomwalters@0 400 togglecount=1;
tomwalters@0 401 checkcount=1;
tomwalters@0 402 for i=nr_params:-1:1
tomwalters@0 403 if ~strcmp(params(i),'info') && ~strcmp(params(i),'toggleradiobuttons') && ~strcmp(params(i),'checkboxes')
tomwalters@0 404 string_text=params{i};
tomwalters@0 405 plot_text=[string_text ' '];
tomwalters@0 406 % plot_text=string_text;
tomwalters@0 407 tag=sprintf('text%d',linecount);
tomwalters@0 408 text_len=length(string_text);
tomwalters@0 409 pos_x=maxxlen-text_len+leftoffset;
tomwalters@0 410 pos_y=(linecount+1)*rowheight;
tomwalters@0 411 h2 = uicontrol(...
tomwalters@0 412 'Parent',h1,...
tomwalters@0 413 'Units','characters',...
tomwalters@0 414 'ListboxTop',0,...
tomwalters@0 415 'Position',[pos_x pos_y text_len+5 elementhigth],...
tomwalters@0 416 'String',plot_text,...
tomwalters@0 417 'Style','text',...
tomwalters@0 418 'Tag',tag);
tomwalters@0 419
tomwalters@0 420 edittag=sprintf('edit%d',linecount);
tomwalters@0 421 pos_x=window_width-edit_width-leftoffset;
tomwalters@0 422 pos_y=(linecount+1)*rowheight;
tomwalters@0 423 value=getfield(options,string_text);
tomwalters@0 424 if isnumeric(value)
tomwalters@0 425 valuestr=num2str(value);
tomwalters@0 426 if length(value)>1 % a field instead a single number
tomwalters@0 427 valuestr='[';
tomwalters@0 428 for j=1:length(value)
tomwalters@0 429 valuestr=[valuestr ' ' num2str(value(j))];
tomwalters@0 430 end
tomwalters@0 431 valuestr=[valuestr ']'];
tomwalters@0 432 end
tomwalters@0 433 else % a string
tomwalters@0 434 valuestr=value;
tomwalters@0 435 end
tomwalters@0 436 h3 = uicontrol(...
tomwalters@0 437 'Parent',h1,...
tomwalters@0 438 'Units','characters',...
tomwalters@0 439 'BackgroundColor',[1 1 1],...
tomwalters@0 440 'ListboxTop',0,...
tomwalters@0 441 'Position',[pos_x pos_y edit_width elementhigth],...
tomwalters@0 442 'String',{ valuestr },...
tomwalters@0 443 'userdata',plot_text,...
tomwalters@0 444 'Style','edit',...
tomwalters@0 445 'Tag',edittag);
tomwalters@0 446 % 'Callback','data_gui(''edit1_Callback'',gcbo,[],guidata(gcbo))',...
tomwalters@0 447
tomwalters@0 448 linecount=linecount+1;
tomwalters@0 449 elseif strcmp(params(i),'toggleradiobuttons')
tomwalters@0 450 radiobuttons=options.toggleradiobuttons;
tomwalters@0 451 nr_but=length(radiobuttons);
tomwalters@0 452 for jj=1:nr_but
tomwalters@0 453 string_text=radiobuttons{jj}.name;
tomwalters@0 454 plot_text=[string_text ' '];
tomwalters@0 455 % plot_text=string_text;
tomwalters@0 456 tag=sprintf('text%d',linecount);
tomwalters@0 457 text_len=length(string_text);
tomwalters@0 458 pos_x=maxxlen-text_len+leftoffset;
tomwalters@0 459 pos_y=(linecount+1)*rowheight;
tomwalters@0 460 h2 = uicontrol(...
tomwalters@0 461 'Parent',h1,...
tomwalters@0 462 'Units','characters',...
tomwalters@0 463 'ListboxTop',0,...
tomwalters@0 464 'Position',[pos_x pos_y text_len+5 elementhigth],...
tomwalters@0 465 'String',plot_text,...
tomwalters@0 466 'Style','text',...
tomwalters@0 467 'Tag',tag);
tomwalters@0 468
tomwalters@0 469 toggletag=sprintf('togglebutton%d',togglecount);
tomwalters@0 470 togglecount=togglecount+1;
tomwalters@0 471 pos_x=window_width-edit_width-leftoffset;
tomwalters@0 472 pos_y=(linecount+1)*rowheight;
tomwalters@0 473 value=radiobuttons{jj}.value;
tomwalters@0 474 h3 = uicontrol(...
tomwalters@0 475 'Parent',h1,...
tomwalters@0 476 'Units','characters',...
tomwalters@0 477 'BackgroundColor',[1 1 1],...
tomwalters@0 478 'ListboxTop',0,...
tomwalters@0 479 'Position',[pos_x+2 pos_y 4 elementhigth],...
tomwalters@0 480 'Value',value,...
tomwalters@0 481 'Style','radiobutton',...
tomwalters@0 482 'backgroundcolor',[0.925 0.914 0.847],...
tomwalters@0 483 'userdata',jj,...
tomwalters@0 484 'Callback','data_gui(''togglebuttons_Callback'',gcbo,[],guidata(gcbo))',...
tomwalters@0 485 'Tag',toggletag);
tomwalters@0 486
tomwalters@0 487 linecount=linecount+1;
tomwalters@0 488 end
tomwalters@0 489 elseif strcmp(params(i),'checkboxes')
tomwalters@0 490 checkboxes=options.checkboxes;
tomwalters@0 491 nr_but=length(checkboxes);
tomwalters@0 492 for jj=1:nr_but
tomwalters@0 493 string_text=checkboxes{jj}.name;
tomwalters@0 494 plot_text=[string_text ' '];
tomwalters@0 495 % plot_text=string_text;
tomwalters@0 496 tag=sprintf('text%d',linecount);
tomwalters@0 497 text_len=length(string_text);
tomwalters@0 498 pos_x=maxxlen-text_len+leftoffset;
tomwalters@0 499 pos_y=(linecount+1)*rowheight;
tomwalters@0 500 h2 = uicontrol(...
tomwalters@0 501 'Parent',h1,...
tomwalters@0 502 'Units','characters',...
tomwalters@0 503 'ListboxTop',0,...
tomwalters@0 504 'Position',[pos_x pos_y text_len+5 elementhigth],...
tomwalters@0 505 'String',plot_text,...
tomwalters@0 506 'Style','text',...
tomwalters@0 507 'Tag',tag);
tomwalters@0 508
tomwalters@0 509 checktag=sprintf('checkbox%d',checkcount);
tomwalters@0 510 checkcount=checkcount+1;
tomwalters@0 511 pos_x=window_width-edit_width-leftoffset;
tomwalters@0 512 pos_y=(linecount+1)*rowheight;
tomwalters@0 513 value=checkboxes{jj}.value;
tomwalters@0 514 h3 = uicontrol(...
tomwalters@0 515 'Parent',h1,...
tomwalters@0 516 'Units','characters',...
tomwalters@0 517 'BackgroundColor',[1 1 1],...
tomwalters@0 518 'ListboxTop',0,...
tomwalters@0 519 'Position',[pos_x+2 pos_y 4 elementhigth],...
tomwalters@0 520 'Value',value,...
tomwalters@0 521 'Style','checkbox',...
tomwalters@0 522 'backgroundcolor',[0.925 0.914 0.847],...
tomwalters@0 523 'userdata',jj,...
tomwalters@0 524 'Tag',checktag);
tomwalters@0 525
tomwalters@0 526 linecount=linecount+1;
tomwalters@0 527 end
tomwalters@0 528 end
tomwalters@0 529 end
tomwalters@0 530
tomwalters@0 531
tomwalters@0 532 hsingleton = h1;
tomwalters@0 533
tomwalters@0 534
tomwalters@0 535 % --- Handles default GUIDE GUI creation and callback dispatch
tomwalters@0 536 function varargout = gui_mainfcn(gui_State, varargin)
tomwalters@0 537
tomwalters@0 538
tomwalters@0 539 % GUI_MAINFCN provides these command line APIs for dealing with GUIs
tomwalters@0 540 %
tomwalters@0 541 % data_gui, by itself, creates a new data_gui or raises the existing
tomwalters@0 542 % singleton*.
tomwalters@0 543 %
tomwalters@0 544 % H = data_gui returns the handle to a new data_gui or the handle to
tomwalters@0 545 % the existing singleton*.
tomwalters@0 546 %
tomwalters@0 547 % data_gui('CALLBACK',hObject,eventData,handles,...) calls the local
tomwalters@0 548 % function named CALLBACK in data_gui.M with the given input arguments.
tomwalters@0 549 %
tomwalters@0 550 % data_gui('Property','Value',...) creates a new data_gui or raises the
tomwalters@0 551 % existing singleton*. Starting from the left, property value pairs are
tomwalters@0 552 % applied to the GUI before untitled_OpeningFunction gets called. An
tomwalters@0 553 % unrecognized property name or invalid value makes property application
tomwalters@0 554 % stop. All inputs are passed to untitled_OpeningFcn via varargin.
tomwalters@0 555 %
tomwalters@0 556 % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
tomwalters@0 557 % instance to run (singleton)".
tomwalters@0 558
tomwalters@0 559 % Copyright 1984-2002 The MathWorks, Inc.
tomwalters@0 560 % $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
tomwalters@0 561
tomwalters@0 562 gui_StateFields = {'gui_Name'
tomwalters@0 563 'gui_Singleton'
tomwalters@0 564 'gui_OpeningFcn'
tomwalters@0 565 'gui_OutputFcn'
tomwalters@0 566 'gui_LayoutFcn'
tomwalters@0 567 'gui_Callback'};
tomwalters@0 568 gui_Mfile = '';
tomwalters@0 569 for i=1:length(gui_StateFields)
tomwalters@0 570 if ~isfield(gui_State, gui_StateFields{i})
tomwalters@0 571 error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);
tomwalters@0 572 elseif isequal(gui_StateFields{i}, 'gui_Name')
tomwalters@0 573 gui_Mfile = [getfield(gui_State, gui_StateFields{i}), '.m'];
tomwalters@0 574 end
tomwalters@0 575 end
tomwalters@0 576
tomwalters@0 577 numargin = length(varargin);
tomwalters@0 578
tomwalters@0 579 if numargin == 0
tomwalters@0 580 % data_gui
tomwalters@0 581 % create the GUI
tomwalters@0 582 gui_Create = 1;
tomwalters@0 583 elseif numargin > 3 & ischar(varargin{1}) & ishandle(varargin{2})
tomwalters@0 584 % data_gui('CALLBACK',hObject,eventData,handles,...)
tomwalters@0 585 gui_Create = 0;
tomwalters@0 586 else
tomwalters@0 587 % data_gui(...)
tomwalters@0 588 % create the GUI and hand varargin to the openingfcn
tomwalters@0 589 gui_Create = 1;
tomwalters@0 590 end
tomwalters@0 591
tomwalters@0 592 if gui_Create == 0
tomwalters@0 593 varargin{1} = gui_State.gui_Callback;
tomwalters@0 594 if nargout
tomwalters@0 595 [varargout{1:nargout}] = feval(varargin{:});
tomwalters@0 596 else
tomwalters@0 597 feval(varargin{:});
tomwalters@0 598 end
tomwalters@0 599 else
tomwalters@0 600 if gui_State.gui_Singleton
tomwalters@0 601 gui_SingletonOpt = 'reuse';
tomwalters@0 602 else
tomwalters@0 603 gui_SingletonOpt = 'new';
tomwalters@0 604 end
tomwalters@0 605
tomwalters@0 606 % Open fig file with stored settings. Note: This executes all component
tomwalters@0 607 % specific CreateFunctions with an empty HANDLES structure.
tomwalters@0 608 % make options global, so that I can access them in the generation
tomwalters@0 609 % function
tomwalters@0 610 global options
tomwalters@0 611 options=varargin{1};
tomwalters@0 612
tomwalters@0 613 % Do feval on layout code in m-file if it exists
tomwalters@0 614 if ~isempty(gui_State.gui_LayoutFcn)
tomwalters@0 615 gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
tomwalters@0 616 % SB: this one finds the wrong one, possible because it just looks
tomwalters@0 617 % for the first one with the m-file. We can do better:
tomwalters@0 618
tomwalters@0 619 all_childs=get(0,'children');
tomwalters@0 620 this_name=options.info.title;
tomwalters@0 621 for i=1:length(all_childs)
tomwalters@0 622 name=get(all_childs(i),'name');
tomwalters@0 623 if strcmp(name,this_name)
tomwalters@0 624 gui_hFigure=all_childs(i);
tomwalters@0 625 end
tomwalters@0 626 end
tomwalters@0 627
tomwalters@0 628
tomwalters@0 629 else
tomwalters@0 630 gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);
tomwalters@0 631 % If the figure has InGUIInitialization it was not completely created
tomwalters@0 632 % on the last pass. Delete this handle and try again.
tomwalters@0 633 if isappdata(gui_hFigure, 'InGUIInitialization')
tomwalters@0 634 delete(gui_hFigure);
tomwalters@0 635 gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);
tomwalters@0 636 end
tomwalters@0 637 end
tomwalters@0 638
tomwalters@0 639 % Set flag to indicate starting GUI initialization
tomwalters@0 640 setappdata(gui_hFigure,'InGUIInitialization',1);
tomwalters@0 641
tomwalters@0 642 % Fetch GUIDE Application options
tomwalters@0 643 gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
tomwalters@0 644
tomwalters@0 645 if ~isappdata(gui_hFigure,'GUIOnScreen')
tomwalters@0 646 % Adjust background color
tomwalters@0 647 if gui_Options.syscolorfig
tomwalters@0 648 set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
tomwalters@0 649 end
tomwalters@0 650
tomwalters@0 651 % Generate HANDLES structure and store with GUIDATA
tomwalters@0 652 guidata(gui_hFigure, guihandles(gui_hFigure));
tomwalters@0 653 end
tomwalters@0 654
tomwalters@0 655 % If user specified 'Visible','off' in p/v pairs, don't make the figure
tomwalters@0 656 % visible.
tomwalters@0 657 gui_MakeVisible = 1;
tomwalters@0 658 for ind=1:2:length(varargin)
tomwalters@0 659 if length(varargin) == ind
tomwalters@0 660 break;
tomwalters@0 661 end
tomwalters@0 662 len1 = min(length('visible'),length(varargin{ind}));
tomwalters@0 663 len2 = min(length('off'),length(varargin{ind+1}));
tomwalters@0 664 if ischar(varargin{ind}) & ischar(varargin{ind+1}) & ...
tomwalters@0 665 strncmpi(varargin{ind},'visible',len1) & len2 > 1
tomwalters@0 666 if strncmpi(varargin{ind+1},'off',len2)
tomwalters@0 667 gui_MakeVisible = 0;
tomwalters@0 668 elseif strncmpi(varargin{ind+1},'on',len2)
tomwalters@0 669 gui_MakeVisible = 1;
tomwalters@0 670 end
tomwalters@0 671 end
tomwalters@0 672 end
tomwalters@0 673
tomwalters@0 674 % Check for figure param value pairs
tomwalters@0 675 for index=1:2:length(varargin)
tomwalters@0 676 if length(varargin) == index
tomwalters@0 677 break;
tomwalters@0 678 end
tomwalters@0 679 try, set(gui_hFigure, varargin{index}, varargin{index+1}), catch, break, end
tomwalters@0 680 end
tomwalters@0 681
tomwalters@0 682 % If handle visibility is set to 'callback', turn it on until finished
tomwalters@0 683 % with OpeningFcn
tomwalters@0 684 gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
tomwalters@0 685 if strcmp(gui_HandleVisibility, 'callback')
tomwalters@0 686 set(gui_hFigure,'HandleVisibility', 'on');
tomwalters@0 687 end
tomwalters@0 688
tomwalters@0 689 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
tomwalters@0 690
tomwalters@0 691 if ishandle(gui_hFigure)
tomwalters@0 692 % Update handle visibility
tomwalters@0 693 set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
tomwalters@0 694
tomwalters@0 695 % Make figure visible
tomwalters@0 696 if gui_MakeVisible
tomwalters@0 697 set(gui_hFigure, 'Visible', 'on')
tomwalters@0 698 if gui_Options.singleton
tomwalters@0 699 setappdata(gui_hFigure,'GUIOnScreen', 1);
tomwalters@0 700 end
tomwalters@0 701 end
tomwalters@0 702
tomwalters@0 703 % Done with GUI initialization
tomwalters@0 704 rmappdata(gui_hFigure,'InGUIInitialization');
tomwalters@0 705 end
tomwalters@0 706
tomwalters@0 707 % If handle visibility is set to 'callback', turn it on until finished with
tomwalters@0 708 % OutputFcn
tomwalters@0 709 if ishandle(gui_hFigure)
tomwalters@0 710 gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
tomwalters@0 711 if strcmp(gui_HandleVisibility, 'callback')
tomwalters@0 712 set(gui_hFigure,'HandleVisibility', 'on');
tomwalters@0 713 end
tomwalters@0 714 gui_Handles = guidata(gui_hFigure);
tomwalters@0 715 else
tomwalters@0 716 gui_Handles = [];
tomwalters@0 717 end
tomwalters@0 718
tomwalters@0 719 if nargout
tomwalters@0 720 [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
tomwalters@0 721 else
tomwalters@0 722 feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
tomwalters@0 723 end
tomwalters@0 724
tomwalters@0 725 if ishandle(gui_hFigure)
tomwalters@0 726 set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
tomwalters@0 727 end
tomwalters@0 728 end
tomwalters@0 729
tomwalters@0 730
tomwalters@0 731 function gui_hFigure = local_openfig(name, singleton)
tomwalters@0 732 if nargin('openfig') == 3
tomwalters@0 733 gui_hFigure = openfig(name, singleton, 'auto');
tomwalters@0 734 else
tomwalters@0 735 % OPENFIG did not accept 3rd input argument until R13,
tomwalters@0 736 % toggle default figure visible to prevent the figure
tomwalters@0 737 % from showing up too soon.
tomwalters@0 738 gui_OldDefaultVisible = get(0,'defaultFigureVisible');
tomwalters@0 739 set(0,'defaultFigureVisible','off');
tomwalters@0 740 gui_hFigure = openfig(name, singleton);
tomwalters@0 741 set(0,'defaultFigureVisible',gui_OldDefaultVisible);
tomwalters@0 742 end
tomwalters@0 743