tomwalters@0: % support file for 'aim-mat' tomwalters@0: % 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 = data_gui(varargin) tomwalters@0: % allow some nice action with a gui. tomwalters@0: % Example: try: tomwalters@0: % function plot_psth(data,options) tomwalters@0: % options.startms=0; tomwalters@0: % options.duration=data.expparams.spike_window_end_ms; tomwalters@0: % options.binwidth=1; tomwalters@0: % options.info.buttontext={'plot psth','save as ascii'}; tomwalters@0: % options.info.data=data; tomwalters@0: % options.info.title='psth parameter'; tomwalters@0: % options.info.callback={'plot_psth(data,options,''plot'')','plot_psth(data,options,''save_as_ascii'')'}; tomwalters@0: % out.handle=data_gui(options); tomwalters@0: % tomwalters@0: tomwalters@0: % Begin initialization code - DO NOT EDIT tomwalters@0: tomwalters@0: % find out, if we want a new window or the old one: tomwalters@0: if length(varargin)==1 tomwalters@0: gui_Singleton = 0; % normally we want a new window tomwalters@0: all_childs=get(0,'children'); tomwalters@0: this_name=varargin{1}.info.title; 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_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: end tomwalters@0: end tomwalters@0: else tomwalters@0: gui_Singleton = 1; % but if there is a copy already, take that window instead tomwalters@0: end tomwalters@0: tomwalters@0: gui_State = struct('gui_Name', mfilename, ... tomwalters@0: 'gui_Singleton', gui_Singleton, ... tomwalters@0: 'gui_OpeningFcn', @data_gui_OpeningFcn, ... tomwalters@0: 'gui_OutputFcn', @data_gui_OutputFcn, ... tomwalters@0: 'gui_LayoutFcn', @data_gui_LayoutFcn, ... tomwalters@0: 'gui_Callback', []); tomwalters@0: if nargin & isstr(varargin{1}) tomwalters@0: gui_State.gui_Callback = str2func(varargin{1}); tomwalters@0: end tomwalters@0: tomwalters@0: if nargout tomwalters@0: [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); tomwalters@0: else tomwalters@0: gui_mainfcn(gui_State, varargin{:}); tomwalters@0: end tomwalters@0: % End initialization code - DO NOT EDIT tomwalters@0: tomwalters@0: tomwalters@0: % --- Executes just before data_gui is made visible. tomwalters@0: function data_gui_OpeningFcn(hObject, eventdata, handles, varargin) 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 data_gui (see VARARGIN) tomwalters@0: tomwalters@0: % Choose default command line output for data_gui tomwalters@0: handles.output = hObject; tomwalters@0: tomwalters@0: tomwalters@0: % copy the options in place tomwalters@0: options=varargin{1}; tomwalters@0: handles.options=options; tomwalters@0: tomwalters@0: % Update handles structure tomwalters@0: guidata(hObject, handles); tomwalters@0: tomwalters@0: global result; tomwalters@0: % UIWAIT makes data_gui wait for user response (see UIRESUME) tomwalters@0: tomwalters@0: if ~isfield(options.info,'default_value') tomwalters@0: result=''; % not determined yet tomwalters@0: else tomwalters@0: result=options.info.default_value; tomwalters@0: end tomwalters@0: tomwalters@0: if isfield(options.info,'mode') && strcmp(options.info.mode,'modal') tomwalters@0: uiwait(handles.figure1); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % --- Outputs from this function are returned to the command line. tomwalters@0: function varargout = data_gui_OutputFcn(hObject, eventdata, handles) 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: % Get default command line output from handles structure tomwalters@0: global result; tomwalters@0: varargout{1} = result; tomwalters@0: tomwalters@0: tomwalters@0: % --- Executes on button press in pushbutton1. tomwalters@0: function pushbuttons_Callback(hObject, eventdata, handles) tomwalters@0: % hObject handle to pushbutton1 (see GCBO) 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: options=handles.options; tomwalters@0: tomwalters@0: tomwalters@0: if iscell(handles.options.info.buttontext) tomwalters@0: nr_buttons=length(handles.options.info.buttontext); tomwalters@0: else tomwalters@0: nr_buttons=1; tomwalters@0: end tomwalters@0: for ii=1:nr_buttons tomwalters@0: pushtag=sprintf('pushbutton%d',ii); tomwalters@0: handstr=sprintf('hand=handles.%s;',pushtag); tomwalters@0: eval(handstr); tomwalters@0: if hObject==hand; tomwalters@0: buttonnumber=ii; tomwalters@0: break; tomwalters@0: end tomwalters@0: end tomwalters@0: % dispatch all data values to the options structure tomwalters@0: tomwalters@0: options=handles.options; tomwalters@0: % radiobuttons=options.toggleradiobuttons; tomwalters@0: % nr_but=length(radiobuttons); tomwalters@0: nr_hands=length(fields(handles)); tomwalters@0: all_fields=fields(handles); tomwalters@0: % set all to 0 tomwalters@0: linecount=1; tomwalters@0: params=fields(options); tomwalters@0: nr_params=length(params); tomwalters@0: tomwalters@0: params=fields(options); tomwalters@0: nr_params=length(params); tomwalters@0: linecount=1; tomwalters@0: tomwalters@0: for i=1:nr_params % look through all parameter and find the assoziated handle for it tomwalters@0: if ~strcmp(params(i),'info') tomwalters@0: for j=1:nr_hands % go through all handles. One must be it tomwalters@0: curhand=getfield(handles,all_fields{j}); tomwalters@0: if ishandle(curhand) tomwalters@0: fieldname=all_fields{j}; tomwalters@0: allfi=get(curhand); tomwalters@0: if isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'edit') tomwalters@0: fieldvalue=get(curhand,'String'); tomwalters@0: val=str2num(fieldvalue{1}); tomwalters@0: stuctname=get(curhand,'userdata'); tomwalters@0: if isnumeric(val) && ~isempty(val) tomwalters@0: options=setfield(options,stuctname,val); tomwalters@0: else tomwalters@0: options=setfield(options,stuctname,fieldvalue{1}); tomwalters@0: end tomwalters@0: linecount=linecount+1; tomwalters@0: elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'radiobutton') tomwalters@0: val=get(curhand,'value'); tomwalters@0: nr=get(curhand,'Userdata'); tomwalters@0: options.toggleradiobuttons{nr}.value=val; tomwalters@0: elseif isfield(allfi,'Style') && strcmp(get(curhand,'Style'),'checkbox') tomwalters@0: val=get(curhand,'value'); tomwalters@0: nr=get(curhand,'Userdata'); tomwalters@0: options.checkboxes{nr}.value=val; tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: data=options.info.data; tomwalters@0: if nr_buttons==1 tomwalters@0: callline=sprintf('%s;',options.info.callback); tomwalters@0: else tomwalters@0: callline=sprintf('%s;',options.info.callback{buttonnumber}); tomwalters@0: end tomwalters@0: eval(callline); tomwalters@0: tomwalters@0: % does the function give back a value? tomwalters@0: gleichwo=strfind(callline,'='); tomwalters@0: if ~isempty(gleichwo) tomwalters@0: retvar=callline(1:gleichwo-1); tomwalters@0: global result; tomwalters@0: resstr=sprintf('result=%s;',retvar); tomwalters@0: eval(resstr); tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: function togglebuttons_Callback(hObject, eventdata, handles) tomwalters@0: if get(hObject,'value')==0 tomwalters@0: return tomwalters@0: end tomwalters@0: options=handles.options; tomwalters@0: radiobuttons=options.toggleradiobuttons; tomwalters@0: nr_but=length(radiobuttons); tomwalters@0: nr_hands=length(fields(handles)); tomwalters@0: all_fields=fields(handles); tomwalters@0: % set all to 0 tomwalters@0: for i=1:nr_hands tomwalters@0: curhand=getfield(handles,all_fields{i}); tomwalters@0: if ishandle(curhand) tomwalters@0: name1=get(curhand,'tag'); tomwalters@0: for j=1:nr_but tomwalters@0: name2=sprintf('togglebutton%d',j); tomwalters@0: if strcmp(name1,name2) && hObject~=curhand tomwalters@0: set(curhand,'value',0); tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % --- Creates and returns a handle to the GUI figure. tomwalters@0: function h1 = data_gui_LayoutFcn(policy) tomwalters@0: % policy - create a new figure or use a singleton. 'new' or 'reuse'. tomwalters@0: tomwalters@0: persistent hsingleton; tomwalters@0: if strcmpi(policy, 'reuse') & ishandle(hsingleton) tomwalters@0: h1 = hsingleton; tomwalters@0: return; tomwalters@0: end tomwalters@0: % collect my own options to generate parmeters on the fly tomwalters@0: global options tomwalters@0: tomwalters@0: % now build from bottom to top a line of text and an edit box for each tomwalters@0: % parameter tomwalters@0: params=fields(options); tomwalters@0: nr_params=length(params); tomwalters@0: linecount=1; tomwalters@0: % first find out, what the longest name is tomwalters@0: maxxlen=0; % the longest text in width tomwalters@0: maxylen=0; % essentially the number of lines tomwalters@0: rowheight=2; % how high every row is tomwalters@0: elementhigth=1.5; % how high every element is tomwalters@0: edit_width=20; % how wide an edit box is tomwalters@0: spacebetweentextandedit=5; % space between text and edit box tomwalters@0: leftoffset=2; % offset of text to the left boundary (and right as well) tomwalters@0: tomwalters@0: for i=1:nr_params tomwalters@0: if ~strcmp(params(i),'info') tomwalters@0: string_text=params{i}; tomwalters@0: textlen=length(string_text)+3; tomwalters@0: maxxlen=max(maxxlen,textlen); tomwalters@0: maxylen=maxylen+rowheight; % the distance between lines tomwalters@0: end tomwalters@0: if strcmp(params(i),'toggleradiobuttons') tomwalters@0: radiobuttons=options.toggleradiobuttons; tomwalters@0: nr_but=length(radiobuttons); tomwalters@0: maxylen=maxylen+nr_but*rowheight; % the distance between lines tomwalters@0: end tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: % the total size of the window is now: tomwalters@0: window_width=maxxlen+spacebetweentextandedit+edit_width+2*leftoffset; tomwalters@0: window_height=maxylen+3*leftoffset; 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=2; % offset from the top right corner tomwalters@0: h1 = figure(... tomwalters@0: 'Units','characters',... tomwalters@0: 'PaperUnits',get(0,'defaultfigurePaperUnits'),... 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',options.info.title,... tomwalters@0: 'NumberTitle','off',... tomwalters@0: 'PaperPosition',get(0,'defaultfigurePaperPosition'),... tomwalters@0: 'PaperSize',[20.98404194812 29.67743169791],... tomwalters@0: 'PaperType',get(0,'defaultfigurePaperType'),... 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','on',... tomwalters@0: 'HandleVisibility','callback',... tomwalters@0: 'Tag','figure1',... tomwalters@0: 'UserData',zeros(1,0)); tomwalters@0: tomwalters@0: % application data tomwalters@0: setappdata(h1, 'GUIDEOptions', 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: % buttons tomwalters@0: if iscell(options.info.buttontext) tomwalters@0: nr_buttons=length(options.info.buttontext); tomwalters@0: else tomwalters@0: nr_buttons=1; tomwalters@0: end tomwalters@0: gesbtextlen=0; tomwalters@0: boffset=2; tomwalters@0: % for ii=1:nr_buttons tomwalters@0: % if nr_buttons==1 tomwalters@0: % btext=options.info.buttontext; tomwalters@0: % textlen=length(btext)+4; tomwalters@0: % textx=(window_width-textlen)/2; tomwalters@0: % fbtext{1}=btext; tomwalters@0: % buttonposx(1)=textx-textlen/2; tomwalters@0: % buttonwidth(1)=textlen+boffset; tomwalters@0: % else tomwalters@0: % btext=options.info.buttontext{ii}; tomwalters@0: % fbtext{ii}=btext; tomwalters@0: % textlen=length(btext)+4; tomwalters@0: % tomwalters@0: % buttonposx(ii)=gesbtextlen+boffset; tomwalters@0: % gesbtextlen=gesbtextlen+textlen+boffset; tomwalters@0: % tomwalters@0: % buttonwidth(ii)=textlen; tomwalters@0: % tomwalters@0: % end tomwalters@0: % end tomwalters@0: % tomwalters@0: % for ii=1:nr_buttons tomwalters@0: % callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))'; tomwalters@0: % pushtag=sprintf('pushbutton%d',ii); tomwalters@0: % h2 = uicontrol(... tomwalters@0: % 'Parent',h1,... tomwalters@0: % 'Units','characters',... tomwalters@0: % 'Callback',callbackstr,... tomwalters@0: % 'ListboxTop',0,... tomwalters@0: % 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],... tomwalters@0: % 'String',fbtext{ii},... tomwalters@0: % 'Tag',pushtag); tomwalters@0: % options.buttonhandles(ii)=h2; tomwalters@0: % end tomwalters@0: tomwalters@0: for ii=1:nr_buttons tomwalters@0: if nr_buttons==1 tomwalters@0: btext=options.info.buttontext; tomwalters@0: textlen=length(btext)+4; tomwalters@0: textx=(window_width-textlen)/2; tomwalters@0: fbtext{1}=btext; tomwalters@0: buttonposx(1)=textx-textlen/2; tomwalters@0: buttonwidth(1)=textlen+boffset; tomwalters@0: else tomwalters@0: btext=options.info.buttontext{ii}; tomwalters@0: fbtext{ii}=btext; tomwalters@0: textlen=length(btext)+4; tomwalters@0: tomwalters@0: buttonposx(ii)=gesbtextlen+boffset; tomwalters@0: gesbtextlen=gesbtextlen+textlen+boffset; tomwalters@0: tomwalters@0: buttonwidth(ii)=textlen; tomwalters@0: tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: for ii=1:nr_buttons tomwalters@0: callbackstr='data_gui(''pushbuttons_Callback'',gcbo,[],guidata(gcbo))'; tomwalters@0: pushtag=sprintf('pushbutton%d',ii); tomwalters@0: h2 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'Callback',callbackstr,... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[buttonposx(ii) 1 buttonwidth(ii) 1.5],... tomwalters@0: 'String',fbtext{ii},... tomwalters@0: 'Tag',pushtag); tomwalters@0: options.buttonhandles(ii)=h2; tomwalters@0: end tomwalters@0: tomwalters@0: % make the window wider if necessary tomwalters@0: tomwalters@0: % the total size of the window is now: tomwalters@0: new_window_width=window_width; tomwalters@0: if buttonposx(end)+buttonwidth(end)+boffset >new_window_width tomwalters@0: new_window_width=buttonposx(end)+buttonwidth(end)+boffset; tomwalters@0: end tomwalters@0: tomwalters@0: set(h1,'Position',[screeen_width-new_window_width-windoff screeen_height-window_height-windoff new_window_width window_height]); tomwalters@0: tomwalters@0: tomwalters@0: % now put a text and an edit field on every line tomwalters@0: % tagcount=1; tomwalters@0: togglecount=1; tomwalters@0: checkcount=1; tomwalters@0: for i=nr_params:-1:1 tomwalters@0: if ~strcmp(params(i),'info') && ~strcmp(params(i),'toggleradiobuttons') && ~strcmp(params(i),'checkboxes') tomwalters@0: string_text=params{i}; tomwalters@0: plot_text=[string_text ' ']; tomwalters@0: % plot_text=string_text; tomwalters@0: tag=sprintf('text%d',linecount); tomwalters@0: text_len=length(string_text); tomwalters@0: pos_x=maxxlen-text_len+leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: h2 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x pos_y text_len+5 elementhigth],... tomwalters@0: 'String',plot_text,... tomwalters@0: 'Style','text',... tomwalters@0: 'Tag',tag); tomwalters@0: tomwalters@0: edittag=sprintf('edit%d',linecount); tomwalters@0: pos_x=window_width-edit_width-leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: value=getfield(options,string_text); tomwalters@0: if isnumeric(value) tomwalters@0: valuestr=num2str(value); tomwalters@0: if length(value)>1 % a field instead a single number tomwalters@0: valuestr='['; tomwalters@0: for j=1:length(value) tomwalters@0: valuestr=[valuestr ' ' num2str(value(j))]; tomwalters@0: end tomwalters@0: valuestr=[valuestr ']']; tomwalters@0: end tomwalters@0: else % a string tomwalters@0: valuestr=value; tomwalters@0: end tomwalters@0: h3 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x pos_y edit_width elementhigth],... tomwalters@0: 'String',{ valuestr },... tomwalters@0: 'userdata',plot_text,... tomwalters@0: 'Style','edit',... tomwalters@0: 'Tag',edittag); tomwalters@0: % 'Callback','data_gui(''edit1_Callback'',gcbo,[],guidata(gcbo))',... tomwalters@0: tomwalters@0: linecount=linecount+1; tomwalters@0: elseif strcmp(params(i),'toggleradiobuttons') tomwalters@0: radiobuttons=options.toggleradiobuttons; tomwalters@0: nr_but=length(radiobuttons); tomwalters@0: for jj=1:nr_but tomwalters@0: string_text=radiobuttons{jj}.name; tomwalters@0: plot_text=[string_text ' ']; tomwalters@0: % plot_text=string_text; tomwalters@0: tag=sprintf('text%d',linecount); tomwalters@0: text_len=length(string_text); tomwalters@0: pos_x=maxxlen-text_len+leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: h2 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x pos_y text_len+5 elementhigth],... tomwalters@0: 'String',plot_text,... tomwalters@0: 'Style','text',... tomwalters@0: 'Tag',tag); tomwalters@0: tomwalters@0: toggletag=sprintf('togglebutton%d',togglecount); tomwalters@0: togglecount=togglecount+1; tomwalters@0: pos_x=window_width-edit_width-leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: value=radiobuttons{jj}.value; tomwalters@0: h3 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x+2 pos_y 4 elementhigth],... tomwalters@0: 'Value',value,... tomwalters@0: 'Style','radiobutton',... tomwalters@0: 'backgroundcolor',[0.925 0.914 0.847],... tomwalters@0: 'userdata',jj,... tomwalters@0: 'Callback','data_gui(''togglebuttons_Callback'',gcbo,[],guidata(gcbo))',... tomwalters@0: 'Tag',toggletag); tomwalters@0: tomwalters@0: linecount=linecount+1; tomwalters@0: end tomwalters@0: elseif strcmp(params(i),'checkboxes') tomwalters@0: checkboxes=options.checkboxes; tomwalters@0: nr_but=length(checkboxes); tomwalters@0: for jj=1:nr_but tomwalters@0: string_text=checkboxes{jj}.name; tomwalters@0: plot_text=[string_text ' ']; tomwalters@0: % plot_text=string_text; tomwalters@0: tag=sprintf('text%d',linecount); tomwalters@0: text_len=length(string_text); tomwalters@0: pos_x=maxxlen-text_len+leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: h2 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x pos_y text_len+5 elementhigth],... tomwalters@0: 'String',plot_text,... tomwalters@0: 'Style','text',... tomwalters@0: 'Tag',tag); tomwalters@0: tomwalters@0: checktag=sprintf('checkbox%d',checkcount); tomwalters@0: checkcount=checkcount+1; tomwalters@0: pos_x=window_width-edit_width-leftoffset; tomwalters@0: pos_y=(linecount+1)*rowheight; tomwalters@0: value=checkboxes{jj}.value; tomwalters@0: h3 = uicontrol(... tomwalters@0: 'Parent',h1,... tomwalters@0: 'Units','characters',... tomwalters@0: 'BackgroundColor',[1 1 1],... tomwalters@0: 'ListboxTop',0,... tomwalters@0: 'Position',[pos_x+2 pos_y 4 elementhigth],... tomwalters@0: 'Value',value,... tomwalters@0: 'Style','checkbox',... tomwalters@0: 'backgroundcolor',[0.925 0.914 0.847],... tomwalters@0: 'userdata',jj,... tomwalters@0: 'Tag',checktag); tomwalters@0: tomwalters@0: linecount=linecount+1; tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: hsingleton = h1; tomwalters@0: tomwalters@0: tomwalters@0: % --- Handles default GUIDE GUI creation and callback dispatch tomwalters@0: function varargout = gui_mainfcn(gui_State, varargin) tomwalters@0: tomwalters@0: tomwalters@0: % GUI_MAINFCN provides these command line APIs for dealing with GUIs tomwalters@0: % tomwalters@0: % data_gui, by itself, creates a new data_gui or raises the existing tomwalters@0: % singleton*. tomwalters@0: % tomwalters@0: % H = data_gui returns the handle to a new data_gui or the handle to tomwalters@0: % the existing singleton*. tomwalters@0: % tomwalters@0: % data_gui('CALLBACK',hObject,eventData,handles,...) calls the local tomwalters@0: % function named CALLBACK in data_gui.M with the given input arguments. tomwalters@0: % tomwalters@0: % data_gui('Property','Value',...) creates a new data_gui or raises the tomwalters@0: % existing singleton*. Starting from the left, property value pairs are tomwalters@0: % applied to the GUI 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: % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one tomwalters@0: % instance to run (singleton)". 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: gui_StateFields = {'gui_Name' tomwalters@0: 'gui_Singleton' tomwalters@0: 'gui_OpeningFcn' tomwalters@0: 'gui_OutputFcn' tomwalters@0: 'gui_LayoutFcn' tomwalters@0: 'gui_Callback'}; tomwalters@0: gui_Mfile = ''; tomwalters@0: for i=1:length(gui_StateFields) tomwalters@0: if ~isfield(gui_State, gui_StateFields{i}) tomwalters@0: error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile); tomwalters@0: elseif isequal(gui_StateFields{i}, 'gui_Name') tomwalters@0: gui_Mfile = [getfield(gui_State, gui_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: % data_gui tomwalters@0: % create the GUI tomwalters@0: gui_Create = 1; tomwalters@0: elseif numargin > 3 & ischar(varargin{1}) & ishandle(varargin{2}) tomwalters@0: % data_gui('CALLBACK',hObject,eventData,handles,...) tomwalters@0: gui_Create = 0; tomwalters@0: else tomwalters@0: % data_gui(...) tomwalters@0: % create the GUI and hand varargin to the openingfcn tomwalters@0: gui_Create = 1; tomwalters@0: end tomwalters@0: tomwalters@0: if gui_Create == 0 tomwalters@0: varargin{1} = gui_State.gui_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 gui_State.gui_Singleton tomwalters@0: gui_SingletonOpt = 'reuse'; tomwalters@0: else tomwalters@0: gui_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 options global, so that I can access them in the generation tomwalters@0: % function tomwalters@0: global options tomwalters@0: options=varargin{1}; tomwalters@0: tomwalters@0: % Do feval on layout code in m-file if it exists tomwalters@0: if ~isempty(gui_State.gui_LayoutFcn) tomwalters@0: gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt); tomwalters@0: % SB: this 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=options.info.title; 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: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: else tomwalters@0: gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt); tomwalters@0: % If the figure has InGUIInitialization it was not completely created tomwalters@0: % on the last pass. Delete this handle and try again. tomwalters@0: if isappdata(gui_hFigure, 'InGUIInitialization') tomwalters@0: delete(gui_hFigure); tomwalters@0: gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % Set flag to indicate starting GUI initialization tomwalters@0: setappdata(gui_hFigure,'InGUIInitialization',1); tomwalters@0: tomwalters@0: % Fetch GUIDE Application options tomwalters@0: gui_Options = getappdata(gui_hFigure,'GUIDEOptions'); tomwalters@0: tomwalters@0: if ~isappdata(gui_hFigure,'GUIOnScreen') tomwalters@0: % Adjust background color tomwalters@0: if gui_Options.syscolorfig tomwalters@0: set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor')); 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: % If user specified 'Visible','off' in p/v pairs, don't make the figure tomwalters@0: % visible. tomwalters@0: gui_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: gui_MakeVisible = 0; tomwalters@0: elseif strncmpi(varargin{ind+1},'on',len2) tomwalters@0: gui_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, set(gui_hFigure, varargin{index}, varargin{index+1}), catch, break, 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: gui_HandleVisibility = get(gui_hFigure,'HandleVisibility'); tomwalters@0: if strcmp(gui_HandleVisibility, 'callback') tomwalters@0: set(gui_hFigure,'HandleVisibility', 'on'); tomwalters@0: end tomwalters@0: tomwalters@0: feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:}); tomwalters@0: tomwalters@0: if ishandle(gui_hFigure) tomwalters@0: % Update handle visibility tomwalters@0: set(gui_hFigure,'HandleVisibility', gui_HandleVisibility); tomwalters@0: tomwalters@0: % Make figure visible tomwalters@0: if gui_MakeVisible tomwalters@0: set(gui_hFigure, 'Visible', 'on') tomwalters@0: if gui_Options.singleton tomwalters@0: setappdata(gui_hFigure,'GUIOnScreen', 1); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % Done with GUI initialization tomwalters@0: rmappdata(gui_hFigure,'InGUIInitialization'); 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: gui_HandleVisibility = get(gui_hFigure,'HandleVisibility'); tomwalters@0: if strcmp(gui_HandleVisibility, 'callback') tomwalters@0: set(gui_hFigure,'HandleVisibility', 'on'); tomwalters@0: end tomwalters@0: gui_Handles = guidata(gui_hFigure); tomwalters@0: else tomwalters@0: gui_Handles = []; tomwalters@0: end tomwalters@0: tomwalters@0: if nargout tomwalters@0: [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles); tomwalters@0: else tomwalters@0: feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles); tomwalters@0: end tomwalters@0: tomwalters@0: if ishandle(gui_hFigure) tomwalters@0: set(gui_hFigure,'HandleVisibility', gui_HandleVisibility); tomwalters@0: end 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: gui_OldDefaultVisible = get(0,'defaultFigureVisible'); tomwalters@0: set(0,'defaultFigureVisible','off'); tomwalters@0: gui_hFigure = openfig(name, singleton); tomwalters@0: set(0,'defaultFigureVisible',gui_OldDefaultVisible); tomwalters@0: end tomwalters@0: