tomwalters@0: % tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function varargout = parametergui(varargin) tomwalters@0: % all action from a parametergui. tomwalters@0: % tomwalters@0: % parametergui_MAINFCN provides these command line APIs for dealing with parameterguis tomwalters@0: % tomwalters@0: % parametergui, by itself, creates a new parametergui or raises the existing tomwalters@0: % singleton*. tomwalters@0: % tomwalters@0: % H = parametergui returns the handle to a new parametergui or the handle to tomwalters@0: % the existing singleton*. tomwalters@0: % tomwalters@0: % parametergui(parameter_structure) creates a new window with the guis tomwalters@0: % for each parameter tomwalters@0: % tomwalters@0: % parametergui('CALLBACK',hObject,eventData,handles,...) calls the local tomwalters@0: % function named CALLBACK in parametergui.M with the given input arguments. tomwalters@0: % tomwalters@0: % parametergui('Property','Value',...) creates a new parametergui or raises the tomwalters@0: % existing singleton*. Starting from the left, property value pairs are tomwalters@0: % applied to the parametergui before untitled_OpeningFunction gets called. An tomwalters@0: % unrecognized property name or invalid value makes property application tomwalters@0: % stop. All inputs are passed to untitled_OpeningFcn via varargin. tomwalters@0: % tomwalters@0: % Copyright 1984-2002 The MathWorks, Inc. tomwalters@0: % $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ tomwalters@0: % tomwalters@0: % Copyright 2004 Stefan Bleeck tomwalters@0: % $Revision: 585 $ $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % find out, if we want a new window or the old one: tomwalters@0: if length(varargin)==1 && ~isempty(varargin{1}) tomwalters@0: parametergui_Singleton = 0; % normally we want a new window tomwalters@0: all_childs=get(0,'children'); tomwalters@0: this_name=getname(varargin{1}); tomwalters@0: for i=1:length(all_childs) tomwalters@0: name=get(all_childs(i),'name'); tomwalters@0: if strcmp(name,this_name) tomwalters@0: parametergui_Singleton = 1; % but if there is a copy already, take that window instead tomwalters@0: % and bring it to the front tomwalters@0: figure(all_childs(i)); tomwalters@0: break tomwalters@0: end tomwalters@0: end tomwalters@0: else tomwalters@0: parametergui_Singleton = 1; % but if there is a copy already, take that window instead tomwalters@0: end tomwalters@0: tomwalters@0: parametergui_State = struct('parametergui_Name', mfilename, ... tomwalters@0: 'parametergui_Singleton', parametergui_Singleton, ... tomwalters@0: 'parametergui_OpeningFcn', @parametergui_OpeningFcn, ... tomwalters@0: 'parametergui_OutputFcn', @parametergui_OutputFcn, ... tomwalters@0: 'parametergui_LayoutFcn', @parametergui_LayoutFcn, ... tomwalters@0: 'parametergui_Callback', []); tomwalters@0: if nargin && ischar(varargin{1}) tomwalters@0: parametergui_State.parametergui_Callback = str2func(varargin{1}); tomwalters@0: end tomwalters@0: tomwalters@0: if nargout tomwalters@0: [varargout{1:nargout}] = parametergui_mainfcn(parametergui_State, varargin{:}); tomwalters@0: else tomwalters@0: parametergui_mainfcn(parametergui_State, varargin{:}); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % --- Executes just before parametergui is made visible. tomwalters@0: function parametergui_OpeningFcn(hObject, eventdata, handles, varargin) %#ok tomwalters@0: % This function has no output args, see OutputFcn. tomwalters@0: % hObject handle to figure tomwalters@0: % eventdata reserved - to be defined in a future version of MATLAB tomwalters@0: % handles structure with handles and user data (see guidata) tomwalters@0: % varargin command line arguments to parametergui (see VARARGIN) tomwalters@0: tomwalters@0: % Choose default command line output for parametergui tomwalters@0: handles.output = hObject; tomwalters@0: tomwalters@0: tomwalters@0: % copy the params in place tomwalters@0: % params=varargin{1}; tomwalters@0: % handles.params=params; tomwalters@0: tomwalters@0: % Update handles structure tomwalters@0: guidata(hObject, handles); tomwalters@0: tomwalters@0: global result; tomwalters@0: % UIWAIT makes parametergui wait for user response (see UIRESUME) tomwalters@0: tomwalters@0: % result=getdefaultvalue(handles.params); tomwalters@0: tomwalters@0: tomwalters@0: if strcmp(getmode(handles.params),'modal') tomwalters@0: % set the first focus tomwalters@0: focus=getfirstfocus(handles.params); tomwalters@0: if ~isempty(focus) tomwalters@0: hand=gethandle(handles.params,focus); tomwalters@0: if ishandle(hand) tomwalters@0: uicontrol(hand); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: uiwait(handles.figure1); tomwalters@0: end tomwalters@0: tomwalters@0: % % set the userdata to the parameters so that they can be accessed from other programs tomwalters@0: % set(handles.figure1,'userdata',handles.params); tomwalters@0: % w=get(handles.figure1,'userdata'); tomwalters@0: %%%% that doesnt work because of an obvious bug in matlab. The set routine tomwalters@0: %%%% calls the params set not the windows set tomwalters@0: tomwalters@0: tomwalters@0: % --- Outputs from this function are returned to the command line. tomwalters@0: function varargout = parametergui_OutputFcn(hObject, eventdata, handles) %#ok tomwalters@0: % varargout cell array for returning output args (see VARARGOUT); tomwalters@0: % hObject handle to figure tomwalters@0: % eventdata reserved - to be defined in a future version of MATLAB tomwalters@0: % handles structure with handles and user data (see guidata) tomwalters@0: tomwalters@0: tomwalters@0: % Get default command line output from handles structure tomwalters@0: global result; tomwalters@0: % if isfield(result,'handles') tomwalters@0: % % matlab doesnt call the callback routine when closed, so update all values tomwalters@0: % % first: tomwalters@0: % generic_Callback([], 'onlyupdate', result.handles); tomwalters@0: % end tomwalters@0: tomwalters@0: tomwalters@0: varargout{1} = result; tomwalters@0: tomwalters@0: tomwalters@0: % --- Executes on button press in pushbutton1. tomwalters@0: function generic_Callback(hObject, eventdata, handles) tomwalters@0: global result; tomwalters@0: if ischar(eventdata) && strcmp(eventdata,'default') tomwalters@0: p=getdefaultbutton(handles.params); % its as if the button was pressed tomwalters@0: hObject=p.handle{1}; tomwalters@0: end tomwalters@0: if ischar(eventdata) && strcmp(eventdata,'onlyupdate') tomwalters@0: p=get(handles.params); tomwalters@0: hObject=p{1}.handle{1}; tomwalters@0: end tomwalters@0: centry=getentrybyhandle(handles.params,hObject); tomwalters@0: if isempty(centry) tomwalters@0: disp('clicked on something outside') tomwalters@0: return tomwalters@0: end tomwalters@0: tomwalters@0: params=handles.params; tomwalters@0: entryparams=get(params); tomwalters@0: data=getuserdata(params); tomwalters@0: callback=centry.callback; tomwalters@0: nr_params=length(entryparams); tomwalters@0: tomwalters@0: % second go through all fields and update the value. This is neccessary to tomwalters@0: % make sure to update the values in the params-structure when altered from tomwalters@0: % outside tomwalters@0: for iii=1:nr_params tomwalters@0: % param=entryparams{iii}; tomwalters@0: type=entryparams{iii}.type; tomwalters@0: handleb=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel); tomwalters@0: switch type tomwalters@0: case {'pop-up menu'} tomwalters@0: vals=get(handleb,'string'); tomwalters@0: nrval=get(handleb,'value'); tomwalters@0: value=vals{nrval}; tomwalters@0: params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel); % set the string value tomwalters@0: case {'bool','radiobutton'} tomwalters@0: value=get(handleb,'value'); tomwalters@0: params=set(params,entryparams{iii}.text,value,entryparams{iii}.panel); tomwalters@0: tomwalters@0: % bool items can enable or disable other items: tomwalters@0: for i=1:length(entryparams{iii}.enables) tomwalters@0: params=enable(params,entryparams{iii}.enables{i},value,entryparams{iii}.enables_inbox{i}); tomwalters@0: end tomwalters@0: for i=1:length(entryparams{iii}.disables) tomwalters@0: params=enable(params,entryparams{iii}.disables{i},1-value,entryparams{iii}.disables_inbox{i}); tomwalters@0: end tomwalters@0: case {'filename','string','directoryname'} tomwalters@0: stringvalue=get(handleb,'string'); tomwalters@0: params=set(params,entryparams{iii}.text,stringvalue,entryparams{iii}.panel); tomwalters@0: case {'slider'} tomwalters@0: % user could have clicked on the slider or on the edit tomwalters@0: secombi=entryparams{iii}.slidereditcombi; tomwalters@0: hand1=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,1); tomwalters@0: hand2=gethandle(params,entryparams{iii}.text,entryparams{iii}.panel,3); tomwalters@0: if hObject==hand1 tomwalters@0: strval=get(hand1,'string'); tomwalters@0: val=str2num(strval); tomwalters@0: secombi=slidereditcontrol_set_raweditvalue(secombi,val); tomwalters@0: else tomwalters@0: val=get(hand2,'value'); tomwalters@0: secombi=slidereditcontrol_set_rawslidervalue(secombi,val); tomwalters@0: end tomwalters@0: val=slidereditcontrol_get_value(secombi); tomwalters@0: selectedunit=getcurrentunit(params,entryparams{iii}.text); tomwalters@0: toval=val*secombi.editscaler; tomwalters@0: params=setas(params,entryparams{iii}.text,toval,selectedunit,entryparams{iii}.panel); % set the real value tomwalters@0: case {'float'} tomwalters@0: set(handleb,'backgroundcolor','w'); tomwalters@0: set(handleb,'foregroundcolor','k'); tomwalters@0: strvalue=get(handleb,'string'); % value is a string, lets see what we make of it tomwalters@0: if ~strcmp(strvalue,'auto') tomwalters@0: selectedunit=getcurrentunit(params,entryparams{iii}.text); tomwalters@0: units=entryparams{iii}.unittype; tomwalters@0: if isa(units,'unit_none') tomwalters@0: testvalue=str2num(strvalue); % its a float, it must have a value tomwalters@0: realvalue=testvalue; tomwalters@0: selectedunit=''; tomwalters@0: else tomwalters@0: params=setas(params,entryparams{iii}.text,strvalue,selectedunit,entryparams{iii}.panel); % set the real value tomwalters@0: testvalue=getas(params,entryparams{iii}.text,entryparams{iii}.orgunit); tomwalters@0: realvalue=str2num(strvalue); tomwalters@0: end tomwalters@0: if isempty(testvalue) tomwalters@0: set(handleb,'backgroundcolor','g'); tomwalters@0: set(handleb,'foregroundcolor','r'); tomwalters@0: uicontrol(handleb); tomwalters@0: errordlg(sprintf('no valid value for ''%s''',entryparams{iii}.text)); tomwalters@0: return tomwalters@0: end tomwalters@0: if min(testvalue)entryparams{iii}.maxvalue tomwalters@0: set(handleb,'backgroundcolor','g'); tomwalters@0: set(handleb,'foregroundcolor','r'); tomwalters@0: uicontrol(handleb); tomwalters@0: if testvalueentryparams{iii}.maxvalue tomwalters@0: set(handleb,'foregroundcolor','g'); tomwalters@0: set(handleb,'backgroundcolor','r'); tomwalters@0: uicontrol(handleb); tomwalters@0: if testvaluemaxtextlen tomwalters@0: maxtextlen=text_len; tomwalters@0: end tomwalters@0: tomwalters@0: if strcmp(param.type,'filename') tomwalters@0: maxeditwidth=filenamelength+10; tomwalters@0: end tomwalters@0: if strcmp(param.type,'directoryname') tomwalters@0: maxeditwidth=filenamelength+10; tomwalters@0: end tomwalters@0: if strcmp(param.type,'string') tomwalters@0: maxeditwidth=max(maxeditwidth,param.width); tomwalters@0: maxeditwidth=max(maxeditwidth,mineditwidth); tomwalters@0: end tomwalters@0: if strcmp(param.type,'float') || strcmp(param.type,'int') tomwalters@0: maxeditwidth=max(maxeditwidth,25); tomwalters@0: end tomwalters@0: if strcmp(param.type,'pop-up menu') tomwalters@0: maxeditwidth=max(maxeditwidth,20); tomwalters@0: end tomwalters@0: if strcmp(param.type,'slider') tomwalters@0: thirdpaneladd=30; tomwalters@0: maxeditwidth=max(maxeditwidth,45); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % the total size of the window is now: tomwalters@0: maxwidth=max(maxeditwidth,edit_width); tomwalters@0: window_width=maxtextlen+spacebetweentextandedit+maxwidth+3*leftoffset+rightoffset+thirdpaneladd; tomwalters@0: window_height=(nr_params+1)*rowheight; tomwalters@0: % get the size of the screen in chars tomwalters@0: set(0,'units','char'); tomwalters@0: siz=get(0,'screensize'); tomwalters@0: screeen_height=siz(4); tomwalters@0: screeen_width=siz(3); tomwalters@0: set(0,'units','pixels'); % back to normal tomwalters@0: tomwalters@0: % the figure tomwalters@0: % windoff=1.3; % offset from the top right corner tomwalters@0: windoff=0; tomwalters@0: guihandle = figure(... tomwalters@0: 'Units','characters',... tomwalters@0: 'Color',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: '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: 'IntegerHandle','off',... tomwalters@0: 'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),... tomwalters@0: 'MenuBar','none',... tomwalters@0: 'Name',getname(params),... tomwalters@0: 'NumberTitle','off',... tomwalters@0: 'Position',[screeen_width-window_width+windoff screeen_height-window_height-windoff window_width window_height],... tomwalters@0: 'Renderer',get(0,'defaultfigureRenderer'),... tomwalters@0: 'RendererMode','manual',... tomwalters@0: 'Resize','off',... tomwalters@0: 'HandleVisibility','callback',... tomwalters@0: 'visible','off',... tomwalters@0: 'KeyPressFcn' ,@doFigureKeyPress , ... tomwalters@0: 'Tag','figure1'); tomwalters@0: tomwalters@0: pos=getposition(params); tomwalters@0: movegui(guihandle,pos); tomwalters@0: tomwalters@0: % make sure we are on screen tomwalters@0: movegui(guihandle) tomwalters@0: tomwalters@0: % error in V7... correct for small offset tomwalters@0: if strcmp(pos,'northeast') tomwalters@0: wp=get(guihandle,'pos'); tomwalters@0: wp(1)=wp(1)+5; tomwalters@0: wp(2)=wp(2)+5; tomwalters@0: set(guihandle,'pos',wp); tomwalters@0: end tomwalters@0: set(guihandle,'visible','on') tomwalters@0: tomwalters@0: % application data tomwalters@0: setappdata(guihandle, 'parameterguiDEOptions', struct(... tomwalters@0: 'active_h', 1.020033e+002, ... tomwalters@0: 'taginfo', struct(... tomwalters@0: 'figure', 2, ... tomwalters@0: 'pushbutton', 2), ... tomwalters@0: 'override', 0, ... tomwalters@0: 'release', 13, ... tomwalters@0: 'resize', 'simple', ... tomwalters@0: 'accessibility', 'callback', ... tomwalters@0: 'mfile', 1, ... tomwalters@0: 'callbacks', 1, ... tomwalters@0: 'singleton', 1, ... tomwalters@0: 'syscolorfig', 1, ... tomwalters@0: 'lastSavedFile', 'c:\bla bla bla')); tomwalters@0: tomwalters@0: % generate a huge panel that resides in that figure tomwalters@0: tomwalters@0: set(guihandle,'Units','characters'); tomwalters@0: winsize=get(guihandle,'position'); tomwalters@0: winsize(1)=0; tomwalters@0: winsize(2)=0; tomwalters@0: bigpanel=uipanel(... tomwalters@0: 'Parent',guihandle,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Position',winsize,... tomwalters@0: 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: 'Title','',... tomwalters@0: 'BorderType','none',... tomwalters@0: 'visible','on',... tomwalters@0: 'Tag','parameterpanel'); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % first plot all panels so that they are in the background tomwalters@0: linecount=1; tomwalters@0: panelcount=1; tomwalters@0: for iii=nr_params:-1:1 tomwalters@0: param=entryparams{iii}; tomwalters@0: type=param.type; tomwalters@0: if strcmp(type,'panel') % draw a panel around the next ones tomwalters@0: pos_x=leftoffset; tomwalters@0: width=window_width-2*leftoffset+rightoffset/2; tomwalters@0: height=(param.nr_elements+0.99)*rowheight; tomwalters@0: pos_y=(linecount+0.82)*rowheight-height-all_y_offset; tomwalters@0: % panelhand(panelcount) = uipanel(... % panel tomwalters@0: callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))'; tomwalters@0: panelhand(panelcount) = uibuttongroup(... % panel tomwalters@0: 'Parent',bigpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Position',[pos_x pos_y width height],... tomwalters@0: 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: 'TitlePosition','lefttop',... tomwalters@0: 'Title',param.text,... tomwalters@0: 'BorderType','etchedin',... tomwalters@0: 'FontWeight','bold',... tomwalters@0: 'Fontsize',11,... tomwalters@0: 'Tag',sprintf('panel%d',panelcount),... tomwalters@0: 'SelectionChangeFcn',callbackstr,... tomwalters@0: 'Userdata',param.text); tomwalters@0: panelcount=panelcount+1; tomwalters@0: params=sethandle(params,param.text,panelhand,param.panel); % save the handle tomwalters@0: end tomwalters@0: linecount=linecount+1; tomwalters@0: param_y(iii)=linecount; tomwalters@0: end tomwalters@0: % then make a line for each parameter tomwalters@0: linecount=ones(panelcount,1); % one linecounter for each panel tomwalters@0: general_line_count=1; tomwalters@0: for iii=nr_params:-1:1 tomwalters@0: param=entryparams{iii}; tomwalters@0: type=param.type; tomwalters@0: callbackstr='parametergui(''generic_Callback'',gcbo,[],guidata(gcbo))'; tomwalters@0: tooltiptext=param.tooltiptext; tomwalters@0: % find out to which panel we belong and set the parent appropriate tomwalters@0: parentpanel=bigpanel; % by default the ui is in the big panel without subp tomwalters@0: current_panel_count=1; % by default in the big panel tomwalters@0: for jjj=1:panelcount-1 tomwalters@0: if strcmp(param.panel,get(panelhand(jjj),'title')) tomwalters@0: parentpanel=panelhand(jjj); tomwalters@0: current_panel_count=jjj+1; % the current panel +1 to avoid confusion with the big one tomwalters@0: end tomwalters@0: end tomwalters@0: if ~strcmp(type,'button') && ~strcmp(type,'panel') tomwalters@0: text_len=length(param.text); tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen-(text_len+2*spacearoundtext)+3*leftoffset-2; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: h2 = uicontrol(... % text tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Position',[pos_x pos_y-yoffset text_len+2*spacearoundtext elementhigth],... tomwalters@0: 'String',param.text,... tomwalters@0: 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: 'HorizontalAlignment','right',... tomwalters@0: 'Tag',sprintf('text%d',general_line_count),... tomwalters@0: 'Style','text'); tomwalters@0: if strcmp(type,'text') tomwalters@0: set(h2,'FontSize',12); tomwalters@0: set(h2,'Fontweight','bold'); tomwalters@0: ext=get(h2,'extent'); tomwalters@0: pos=get(h2,'position'); tomwalters@0: pos(1)=buttonoffset; tomwalters@0: pos(3)=ext(3); tomwalters@0: pos(4)=ext(4); tomwalters@0: set(h2,'position',pos); tomwalters@0: end tomwalters@0: end tomwalters@0: switch param.enable tomwalters@0: case 0 tomwalters@0: enableval='off'; tomwalters@0: case 1 tomwalters@0: enableval='on'; tomwalters@0: end tomwalters@0: tomwalters@0: switch type tomwalters@0: case {'int'} tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: val=getraw(params,param.text); tomwalters@0: hand = uicontrol(... % float edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y edit_width elementhigth],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',val,... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Style','edit',... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: set(hand,'HorizontalAlignment','right'); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: case {'float'} tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: % val=getas(params,param.text,param.orgunit); tomwalters@0: strval=param.stringvalue; tomwalters@0: hand = uicontrol(... % float edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y edit_width elementhigth],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',strval,... tomwalters@0: 'Style','edit',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: tomwalters@0: set(hand,'HorizontalAlignment','left'); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: tomwalters@0: % make the unit poupbox tomwalters@0: unit=param.unittype; tomwalters@0: % make a tooltip for it tomwalters@0: unittype=getname(unit); tomwalters@0: if ~isa(unit,'unit_none') tomwalters@0: pos_x=pos_x+edit_width+2; tomwalters@0: possible_units=getunitstrings(unit); tomwalters@0: possible_units_full=getunitfullstrings(unit); tomwalters@0: select_nr=findunit(unit,param.orgunit); tomwalters@0: unitname=possible_units{select_nr}; tomwalters@0: fullunitname=possible_units_full{select_nr}; tomwalters@0: tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname); tomwalters@0: hand2 = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y unit_width elementhigth],... tomwalters@0: 'string',possible_units,... tomwalters@0: 'enable',enableval,... tomwalters@0: 'value',select_nr,... tomwalters@0: 'Style','popupmenu',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'tooltip',tooltips,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear tomwalters@0: params=sethandle(params,param.text,hand2,param.panel,2); tomwalters@0: end tomwalters@0: case {'slider'} tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: % val=getas(params,param.text,param.orgunit); tomwalters@0: strval=param.stringvalue; tomwalters@0: hand = uicontrol(... % float edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y edit_width elementhigth],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',strval,... tomwalters@0: 'Style','edit',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: tomwalters@0: set(hand,'HorizontalAlignment','left'); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: tomwalters@0: % make the unit poupbox tomwalters@0: unit=param.unittype; tomwalters@0: % make a tooltip for it tomwalters@0: unittype=getname(unit); tomwalters@0: if ~isa(unit,'unit_none') tomwalters@0: pos_x=pos_x+edit_width+2; tomwalters@0: possible_units=getunitstrings(unit); tomwalters@0: possible_units_full=getunitfullstrings(unit); tomwalters@0: select_nr=findunit(unit,param.orgunit); tomwalters@0: unitname=possible_units{select_nr}; tomwalters@0: fullunitname=possible_units_full{select_nr}; tomwalters@0: tooltips=sprintf('%s measured in %s (%s)',unittype,unitname,fullunitname); tomwalters@0: hand2 = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y unit_width elementhigth],... tomwalters@0: 'string',possible_units,... tomwalters@0: 'enable',enableval,... tomwalters@0: 'value',select_nr,... tomwalters@0: 'Style','popupmenu',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'tooltip',tooltips,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear tomwalters@0: params=sethandle(params,param.text,hand2,param.panel,2); tomwalters@0: else tomwalters@0: pos_x=pos_x+edit_width+2; tomwalters@0: params=sethandle(params,param.text,0,param.panel,2); tomwalters@0: end tomwalters@0: tomwalters@0: % make the slider tomwalters@0: pos_x=pos_x+unit_width+2; tomwalters@0: hand3 = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Position',[pos_x pos_y thirdpaneladd+15 elementhigth],... tomwalters@0: 'enable',enableval,... tomwalters@0: 'value',1,... tomwalters@0: 'Style','slider',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear tomwalters@0: params=sethandle(params,param.text,hand3,param.panel,3); tomwalters@0: tomwalters@0: % set up the slidereditcontrol tomwalters@0: secombi=slidereditcontrol_setup(hand3,hand,param.minvalue,param.maxvalue,param.rawvalue,param.islog,param.editscaler,param.nreditdigits); tomwalters@0: secombi=slidereditcontrol_set_value(secombi,param.rawvalue); tomwalters@0: params=setslidereditcontrol(params,param.text,secombi,param.panel); tomwalters@0: tomwalters@0: case 'string' tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: width=max(stringedit_width,param.width)-2; tomwalters@0: hand = uicontrol(... % string edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Position',[pos_x pos_y width elementhigth],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',param.value,... tomwalters@0: 'Style','edit',... tomwalters@0: 'HorizontalAlignment','left',... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: case 'bool' tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: hand = uicontrol(... % bool: checkbox tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: 'Position',[pos_x pos_y edit_width elementhigth],... tomwalters@0: 'enable',enableval,... tomwalters@0: 'value',param.value,... tomwalters@0: 'Style','checkbox',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: case 'radiobutton' tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: hand = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'TooltipString',tooltiptext,... tomwalters@0: 'Units','characters',... tomwalters@0: 'backgroundColor',[0.831372549019608 0.815686274509804 0.784313725490196],... tomwalters@0: 'Position',[pos_x pos_y 3 elementhigth],... tomwalters@0: 'value',param.value,... tomwalters@0: 'Style','radiobutton',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: if strcmp(param.text,'other...') tomwalters@0: pos_x=pos_x+4; tomwalters@0: % width=max(window_width-pos_x-5,10); tomwalters@0: width=maxeditwidth-1; tomwalters@0: if isfield(param,'userdata') tomwalters@0: userstr=param.userdata; tomwalters@0: else tomwalters@0: userstr=''; tomwalters@0: end tomwalters@0: hand2 = uicontrol(... % string edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y width elementhigth],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',userstr,... tomwalters@0: 'Style','edit',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'HorizontalAlignment','left',... tomwalters@0: 'Tag',sprintf('other_entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: params=sethandle(params,param.text,hand2,param.panel,2); tomwalters@0: % params=sethandle(params,param.text,param.panel,hand2,2); tomwalters@0: end tomwalters@0: case {'filename','directoryname'} tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: tomwalters@0: hand = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y filenamelength elementhigth],... tomwalters@0: 'enable',enableval,... tomwalters@0: 'string',param.value,... tomwalters@0: 'Style','edit',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: % and a button tomwalters@0: pos_x=pos_x+filenamelength+2; tomwalters@0: str=' select...'; tomwalters@0: width=length(str); tomwalters@0: hand2 = uicontrol(... % string edit box tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Position',[pos_x pos_y width elementhigth+0.2],... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'String',str,... tomwalters@0: 'Style','pushbutton',... tomwalters@0: 'HorizontalAlignment','left',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Tag',sprintf('other_entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: params=sethandle(params,param.text,hand2,param.panel,2); tomwalters@0: % params=sethandle(params,param.text,param.panel,hand2,2); tomwalters@0: tomwalters@0: case 'button' tomwalters@0: textlen=length(param.text)+4; tomwalters@0: buttonwidth=2*spacearoundtext+textlen; tomwalters@0: if current_panel_count==1 tomwalters@0: buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown+0.5; tomwalters@0: else tomwalters@0: buttonposy=rowheight*linecount(current_panel_count)-yoffset-all_y_offset-extrabuttondown-3+0.5; tomwalters@0: end tomwalters@0: tomwalters@0: hand = uicontrol(... % button tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'Position',[buttonoffset+2*leftoffset buttonposy+0.1 buttonwidth 1.8],... tomwalters@0: 'String',param.text,... tomwalters@0: 'Style','pushbutton',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'KeyPressFcn',@doFigureKeyPress , ... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.text); tomwalters@0: % 'backgroundcolor',[0.5 1 1],... tomwalters@0: % 'foregroundcolor',[0.5 1 1],... tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: tomwalters@0: if param.isdefaultbutton==1 tomwalters@0: setappdata(guihandle, 'DefaultValid', true); tomwalters@0: h = uicontrol(... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor', 'k', ... tomwalters@0: 'Style','frame',... tomwalters@0: 'Position',[buttonoffset+2*leftoffset-0.5 buttonposy-0.05 buttonwidth+0.9 1.9],... tomwalters@0: 'Parent',parentpanel... tomwalters@0: ); tomwalters@0: uistack(h,'bottom') tomwalters@0: end tomwalters@0: tomwalters@0: case 'pop-up menu' tomwalters@0: if current_panel_count==1 tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset; tomwalters@0: pos_y=general_line_count*rowheight-all_y_offset; tomwalters@0: else tomwalters@0: pos_x=maxtextlen+spacebetweentextandedit+2*leftoffset-3; tomwalters@0: pos_y=linecount(current_panel_count)*rowheight-all_y_offset; tomwalters@0: end tomwalters@0: tomwalters@0: hand = uicontrol(... % bool: radiobutton tomwalters@0: 'Parent',parentpanel,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'Position',[pos_x pos_y filenamelength elementhigth],... tomwalters@0: 'string',param.possible_values,... tomwalters@0: 'Style','popupmenu',... tomwalters@0: 'enable',enableval,... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'Tag',sprintf('entry%d',general_line_count),... tomwalters@0: 'Userdata',param.panel); % for radiobuttons it is important to know in which context they appear tomwalters@0: params=sethandle(params,param.text,hand,param.panel); tomwalters@0: end tomwalters@0: tomwalters@0: linecount(current_panel_count)=linecount(current_panel_count)+1; tomwalters@0: general_line_count=general_line_count+1; tomwalters@0: end tomwalters@0: tomwalters@0: hsingleton = guihandle; tomwalters@0: tomwalters@0: tomwalters@0: % --- Handles default parameterguiDE parametergui creation and callback dispatch tomwalters@0: function varargout = parametergui_mainfcn(parametergui_State, varargin) tomwalters@0: tomwalters@0: parametergui_StateFields = {'parametergui_Name' tomwalters@0: 'parametergui_Singleton' tomwalters@0: 'parametergui_OpeningFcn' tomwalters@0: 'parametergui_OutputFcn' tomwalters@0: 'parametergui_LayoutFcn' tomwalters@0: 'parametergui_Callback'}; tomwalters@0: parametergui_Mfile = ''; tomwalters@0: for i=1:length(parametergui_StateFields) tomwalters@0: if ~isfield(parametergui_State, parametergui_StateFields{i}) tomwalters@0: error('Could not find field %s in the parametergui_State struct in parametergui M-file %s', parametergui_StateFields{i}, parametergui_Mfile); tomwalters@0: elseif isequal(parametergui_StateFields{i}, 'parametergui_Name') tomwalters@0: parametergui_Mfile = [getfield(parametergui_State, parametergui_StateFields{i}), '.m']; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: numargin = length(varargin); tomwalters@0: tomwalters@0: if numargin == 0 tomwalters@0: % parametergui tomwalters@0: % create the parametergui tomwalters@0: parametergui_Create = 1; tomwalters@0: elseif numargin > 3 && ischar(varargin{1}) && ishandle(varargin{2}) tomwalters@0: % parametergui('CALLBACK',hObject,eventData,handles,...) tomwalters@0: parametergui_Create = 0; tomwalters@0: else tomwalters@0: % parametergui(...) tomwalters@0: % create the parametergui and hand varargin to the openingfcn tomwalters@0: parametergui_Create = 1; tomwalters@0: end tomwalters@0: tomwalters@0: %SB: return values tomwalters@0: global params tomwalters@0: tomwalters@0: if parametergui_Create == 0 tomwalters@0: varargin{1} = parametergui_State.parametergui_Callback; tomwalters@0: if nargout tomwalters@0: [varargout{1:nargout}] = feval(varargin{:}); tomwalters@0: else tomwalters@0: feval(varargin{:}); tomwalters@0: end tomwalters@0: else tomwalters@0: if parametergui_State.parametergui_Singleton tomwalters@0: parametergui_SingletonOpt = 'reuse'; tomwalters@0: else tomwalters@0: parametergui_SingletonOpt = 'new'; tomwalters@0: end tomwalters@0: tomwalters@0: % Open fig file with stored settings. Note: This executes all component tomwalters@0: % specific CreateFunctions with an empty HANDLES structure. tomwalters@0: % make params global, so that I can access them in the generation tomwalters@0: % function tomwalters@0: params=varargin{1}; tomwalters@0: tomwalters@0: % Do feval on layout code in m-file if it exists tomwalters@0: if ~isempty(parametergui_State.parametergui_LayoutFcn) tomwalters@0: gui_hFigure = feval(parametergui_State.parametergui_LayoutFcn, parametergui_SingletonOpt); tomwalters@0: % SB: the original one finds the wrong one, possible because it just looks tomwalters@0: % for the first one with the m-file. We can do better: tomwalters@0: tomwalters@0: all_childs=get(0,'children'); tomwalters@0: this_name=getname(params); tomwalters@0: for i=1:length(all_childs) tomwalters@0: name=get(all_childs(i),'name'); tomwalters@0: if strcmp(name,this_name) tomwalters@0: gui_hFigure=all_childs(i); tomwalters@0: break tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: else tomwalters@0: gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt); tomwalters@0: % If the figure has InparameterguiInitialization it was not completely created tomwalters@0: % on the last pass. Delete this handle and try again. tomwalters@0: if isappdata(gui_hFigure, 'InparameterguiInitialization') tomwalters@0: delete(gui_hFigure); tomwalters@0: gui_hFigure = local_openfig(parametergui_State.parametergui_Name, parametergui_SingletonOpt); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % Set flag to indicate starting parametergui initialization tomwalters@0: setappdata(gui_hFigure,'InparameterguiInitialization',1); tomwalters@0: tomwalters@0: % Fetch parameterguiDE Application params tomwalters@0: parametergui_Options = getappdata(gui_hFigure,'parameterguiDEOptions'); tomwalters@0: tomwalters@0: if ~isappdata(gui_hFigure,'parameterguiOnScreen') tomwalters@0: % Adjust background color tomwalters@0: if parametergui_Options.syscolorfig tomwalters@0: set(gui_hFigure,'Color', [0.831372549019608 0.815686274509804 0.784313725490196]); tomwalters@0: end tomwalters@0: tomwalters@0: % Generate HANDLES structure and store with guidata tomwalters@0: guidata(gui_hFigure, guihandles(gui_hFigure)); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % If user specified 'Visible','off' in p/v pairs, don't make the figure tomwalters@0: % visible. tomwalters@0: parametergui_MakeVisible = 1; tomwalters@0: for ind=1:2:length(varargin) tomwalters@0: if length(varargin) == ind tomwalters@0: break; tomwalters@0: end tomwalters@0: len1 = min(length('visible'),length(varargin{ind})); tomwalters@0: len2 = min(length('off'),length(varargin{ind+1})); tomwalters@0: if ischar(varargin{ind}) && ischar(varargin{ind+1}) && ... tomwalters@0: strncmpi(varargin{ind},'visible',len1) && len2 > 1 tomwalters@0: if strncmpi(varargin{ind+1},'off',len2) tomwalters@0: parametergui_MakeVisible = 0; tomwalters@0: elseif strncmpi(varargin{ind+1},'on',len2) tomwalters@0: parametergui_MakeVisible = 1; tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % Check for figure param value pairs tomwalters@0: for index=1:2:length(varargin) tomwalters@0: if length(varargin) == index tomwalters@0: break; tomwalters@0: end tomwalters@0: try tomwalters@0: set(gui_hFigure, varargin{index},vargin{index+1}); tomwalters@0: catch tomwalters@0: break tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % If handle visibility is set to 'callback', turn it on until finished tomwalters@0: % with OpeningFcn tomwalters@0: parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility'); tomwalters@0: if strcmp(parametergui_HandleVisibility, 'callback') tomwalters@0: set(gui_hFigure,'HandleVisibility', 'on'); tomwalters@0: end tomwalters@0: tomwalters@0: % SB: save the user structure to the handle struct tomwalters@0: handles=guidata(gui_hFigure); tomwalters@0: handles.params=params; tomwalters@0: guidata(gui_hFigure, handles); tomwalters@0: feval(parametergui_State.parametergui_OpeningFcn, gui_hFigure, [], handles, varargin{:}); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: if ishandle(gui_hFigure) tomwalters@0: % Update handle visibility tomwalters@0: set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility); tomwalters@0: tomwalters@0: % Make figure visible tomwalters@0: if parametergui_MakeVisible tomwalters@0: set(gui_hFigure, 'Visible', 'on') tomwalters@0: if parametergui_Options.singleton tomwalters@0: setappdata(gui_hFigure,'parameterguiOnScreen', 1); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % Done with parametergui initialization tomwalters@0: rmappdata(gui_hFigure,'InparameterguiInitialization'); tomwalters@0: end tomwalters@0: tomwalters@0: % If handle visibility is set to 'callback', turn it on until finished with tomwalters@0: % OutputFcn tomwalters@0: if ishandle(gui_hFigure) tomwalters@0: parametergui_HandleVisibility = get(gui_hFigure,'HandleVisibility'); tomwalters@0: if strcmp(parametergui_HandleVisibility, 'callback') tomwalters@0: set(gui_hFigure,'HandleVisibility', 'on'); tomwalters@0: end tomwalters@0: parametergui_Handles = guidata(gui_hFigure); tomwalters@0: else tomwalters@0: parametergui_Handles = []; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % SB: if the window was reused then update the handles in the params, so tomwalters@0: % that they can be recalculated. tomwalters@0: % this only works when the number and type of variables have not tomwalters@0: % changed in between tomwalters@0: if strcmp(parametergui_SingletonOpt,'reuse') tomwalters@0: dsnew=get(handles.params); % the new parameter without handles tomwalters@0: nr_ds=length(dsnew); tomwalters@0: fields=fieldnames(handles); tomwalters@0: for i=1:nr_ds % we have to find the uicontrol with these two features: tomwalters@0: searchtext=dsnew{i}.text; tomwalters@0: searchpanel=dsnew{i}.panel; tomwalters@0: searchtype=dsnew{i}.type; tomwalters@0: nr_h=length(fields); tomwalters@0: for j=1:nr_h % search through all tomwalters@0: fh=getfield(handles,fields{j}); tomwalters@0: if ishandle(fh) tomwalters@0: type=get(fh,'type'); tomwalters@0: [nr_enty,len]=size(type); tomwalters@0: if nr_enty>1 tomwalters@0: type=type(1); tomwalters@0: secondh=fh(1); tomwalters@0: fh=fh(2); tomwalters@0: end tomwalters@0: if strcmp(type,'uipanel') && strcmp(searchtype,'panel') tomwalters@0: panelname=get(fh,'title'); tomwalters@0: if strcmp(searchpanel,panelname) tomwalters@0: params=sethandle(params,searchtext,fh,searchpanel); % set the handle tomwalters@0: break tomwalters@0: end tomwalters@0: end tomwalters@0: % if its not a panel then its an uicontrol tomwalters@0: if strcmp(type,'uicontrol') tomwalters@0: parent=get(fh,'parent'); tomwalters@0: panelname=get(parent,'title'); % this is the panel tomwalters@0: if strcmp(panelname,'') tomwalters@0: panelname='all'; tomwalters@0: end tomwalters@0: uiname=get(fh,'UserData'); tomwalters@0: tomwalters@0: if strcmp(searchpanel,panelname) && strcmp(searchtext,uiname) tomwalters@0: params=sethandle(params,searchtext,fh,searchpanel); % set the handle tomwalters@0: if nr_enty>1 tomwalters@0: params=sethandle(params,searchtext,secondh,searchpanel,2); % set the handle tomwalters@0: end tomwalters@0: break tomwalters@0: end tomwalters@0: tomwalters@0: % newstyle=get(fh,'style'); tomwalters@0: % if strcmp(orgstyle,newstyle) tomwalters@0: % str2=get(fh,'UserData'); tomwalters@0: % if strcmp(str1,str2) tomwalters@0: % params=sethandle(params,str1,fh); % set the handle tomwalters@0: % style=get(fh,'style'); tomwalters@0: % switch style tomwalters@0: % case 'edit' tomwalters@0: % params=set(params,str1,get(fh,'string')); tomwalters@0: % case {'checkbox','radiobox','int','float'} tomwalters@0: % params=set(params,str1,get(fh,'value')); tomwalters@0: % params=set(params,str1,get(fh,'value')); tomwalters@0: % end tomwalters@0: % break tomwalters@0: % end tomwalters@0: % end tomwalters@0: end tomwalters@0: end tomwalters@0: % h=gethandle(params,searchtext,searchpanel); tomwalters@0: end tomwalters@0: end tomwalters@0: handles.params=params; tomwalters@0: guidata(gui_hFigure, handles); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: if nargout tomwalters@0: global result tomwalters@0: parametergui_Handles=result; tomwalters@0: if strcmp(getmode(handles.params),'nonmodal') tomwalters@0: result=params; tomwalters@0: end tomwalters@0: [varargout{1:nargout}] = feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles); tomwalters@0: else tomwalters@0: feval(parametergui_State.parametergui_OutputFcn, gui_hFigure, [], parametergui_Handles); tomwalters@0: end tomwalters@0: tomwalters@0: if ishandle(gui_hFigure) tomwalters@0: set(gui_hFigure,'HandleVisibility', parametergui_HandleVisibility); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: function gui_hFigure = local_openfig(name, singleton) tomwalters@0: if nargin('openfig') == 3 tomwalters@0: gui_hFigure = openfig(name, singleton, 'auto'); tomwalters@0: else tomwalters@0: % OPENFIG did not accept 3rd input argument until R13, tomwalters@0: % toggle default figure visible to prevent the figure tomwalters@0: % from showing up too soon. tomwalters@0: parametergui_OldDefaultVisible = get(0,'defaultFigureVisible'); tomwalters@0: set(0,'defaultFigureVisible','off'); tomwalters@0: gui_hFigure = openfig(name, singleton); tomwalters@0: set(0,'defaultFigureVisible',parametergui_OldDefaultVisible); tomwalters@0: end tomwalters@0: tomwalters@0: function doFigureKeyPress(obj, evd) tomwalters@0: switch(evd.Key) tomwalters@0: case {'return','space'} tomwalters@0: if getappdata(gcbf,'DefaultValid') tomwalters@0: handles=guidata(gcbf); tomwalters@0: generic_Callback([],'default',handles) tomwalters@0: end tomwalters@0: case 'escape' tomwalters@0: close(gcbf) tomwalters@0: end