function GUI_model(action); % Modèle classique de GUI persistent sig figNumber hndlList; if nargin<1, action='initialize'; sig = []; elseif nargin==1 if ~ischar(action) x = action; sig = x; action = 'initialize'; end end % ========================================= % GUI are often function that callback themselves % with different actions % When calling for the first time the action is % often called 'initialize' % this one defines the interface, locates button and axes, ... % if strcmp(action,'initialize'), %==================================== % Information for all buttons labelColor=[0.9 0.9 0.9]; yInitPos=0.90; menutop=0.95; top=0.4; left=0.785; btnWid=0.175; btnHt=0.06; textHeight = 0.05; textWidth = 0.07; % Spacing between the button and the next command's label spacing=0.025; %================================== % Génération d'une figure figNumber=figure( ... 'Name','titre de la figure', ... 'NumberTitle','off', ... 'Backingstore','off', ... 'Visible','off'); %================================== % Pour rajouter un fond à la figure % axes() %================================== % Set up the axes axHndl1=axes( ... 'Units','normalized', ... 'Position',[0.10 0.60 0.60 0.32], ... 'Drawmode','fast', ... 'Visible','on'); axHndl2=axes( ... 'Units','normalized', ... 'Position',[0.10 0.2 0.60 0.32], ... 'Drawmode','fast', ... 'Visible','on'); %==================================== % The CONSOLE frame frmBorder=0.019; frmBottom=0.04; frmHeight = 0.92; frmWidth = btnWid; yPos=frmBottom-frmBorder; frmPos=[left-frmBorder yPos frmWidth+2*frmBorder frmHeight+2*frmBorder]; uicontrol( ... 'Style','frame', ... 'Units','normalized', ... 'Position',frmPos, ... 'BackgroundColor',[0.5 0.5 0.5]); %==================================== % Premier Bouton menuNumber=1; yPos=menutop-(menuNumber-1)*(btnHt+spacing); % Generic button information labelStr='Nom Bouton 1'; callbackStr='GUI_model(''actionbouton1'');'; btnPos=[left yPos-btnHt btnWid btnHt]; btn1Hndl=uicontrol( ... 'Style','push', ... 'Units','normalized', ... 'BackgroundColor',labelColor,... 'Position',btnPos, ... 'String',labelStr, ... 'Callback',callbackStr); %==================================== % Deuxieme Bouton menuNumber=2; yPos=menutop-(menuNumber-1)*(btnHt+spacing); % Generic button information btnPos=[left yPos-btnHt btnWid btnHt]; labelStr='Nom Bouton 2'; callbackStr='GUI_model(''actionbouton2'');'; btn2Hndl=uicontrol( ... 'Style','push', ... 'Units','normalized', ... 'BackgroundColor',labelColor,... 'Position',btnPos, ... 'String',labelStr, ... 'Callback',callbackStr); %======================================= % Boutons INFO et CLOSE, partent du bas %==================================== % The INFO button labelStr='Info'; callbackStr='GUI_model(''info'')'; helpHndl=uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'BackgroundColor',labelColor, ... 'Position',[left frmBottom+btnHt+spacing btnWid btnHt], ... 'String',labelStr, ... 'Callback',callbackStr); %==================================== % The CLOSE button labelStr='Close'; callbackStr='close(gcf)'; closeHndl=uicontrol( ... 'Style','pushbutton', ... 'Units','normalized', ... 'BackgroundColor',labelColor, ... 'Position',[left frmBottom btnWid btnHt], ... 'String',labelStr, ... 'Callback',callbackStr); % We create here a persistent (see beginning of the program) % vector that will contain all the handles you need % This vector is stored in the figure to a place called % 'UserData' hndlList=[ axHndl1 axHndl2 btn1Hndl btn2Hndl ]; set(figNumber, ... 'Visible','on', ... 'UserData',hndlList); %==================================== % Actions % The following part are called with the % callback property in each handle % these actually perform what you want %==================================== %========================= % ACTION PREMIER BOUTON elseif strcmp(action,'actionbouton1'), disp('Vous avez appuyé sur le bouton 1') disp('You''ve just push button 1') %========================= % ACTION 2EME BOUTON elseif strcmp(action,'actionbouton2'), disp('Vous avez appuyé sur le bouton 2') disp('You''ve just push button 2') % If you want to draw something in axe2 with button 2 % follow the code above % 1. Load the appropriate axis handle property hndlList = get(figNumber,'UserData'); axes(hndlList(2)); % 2. generate your signal (here you can use your functions) signal = sin(2*pi*(0:255)/256 + rand(1)*pi); % 3. plot it ! plot(signal) %========================= % AFFICHAGE AIDE elseif strcmp(action,'info'), ttlStr = 'Titre de l''aide'; hlpStr1 = str2mat(... ' This is just a simple GUI, ment to show you ',... ' different possibilities',... 'by changing these words you can add help for your GUI',... ' ',... ' Cette fonction est juste une architecture de',... ' démonstration ',... '',... ' tapez le texte de l''aide ligne par ligne'); hlpStr2 = str2mat(... ' 2ème page d''aide',... 'You can also make a multipage help',... ' C''est tout / that''s all folks '); helpfun(ttlStr,hlpStr1,hlpStr2); return end %==================================== % Autre fonctions %====================================