Développer une IHM sous Matlab

Transcription

Développer une IHM sous Matlab
Vincent Gigot
Centre des Sciences du Goût et de l’Alimentation
9E bd. Jeanne d’Arc
21000 Dijon
http://www2.dijon.inra.fr/csga/
 L’environnement de développement : le GUIDE, Graphical User
Interface Development Environment.
 Les objets graphiques : hiérarchie, propriétés, identifiants
 Génération de code automatique : fichier .fig, .m, fonctions
callback et createfcn
 Deux exemples simple d’IHM en électrophysiologie :
1- calcul de la Current Source Density sur des
enregistrements expérimentaux de potentiels de
champs.
2- Détection et classification de spikes
14/06/2011
2
GUIDE
GUIDE
Outil graphique pour le
design d’IHM
14/06/2011
3
 L’environnement de développement : le GUIDE, Graphical User
Interface Development Environment.
 Les objets graphiques : hiérarchie, propriétés, identifiants
 Génération de code automatique : fichier .fig, .m, fonctions
callback et createfcn
 Deux exemples simple d’IHM en électrophysiologie :
1- calcul de la Current Source Density sur des
enregistrements expérimentaux de potentiels de
champs.
2- Détection et classification de spikes
14/06/2011
4
Les objets graphiques
une hiérarchie pyramidale parent-enfant
Ecran
Standard toolbar
14/06/2011
Figure
14/06/2011
6
Graphes (1)
14/06/2011
7
Graphes (2)
14/06/2011
8
Propriétés des objets graphiques
Double clic sur les axes
Les Listes des propriétés sont spécifiques :
- de l’objet ROOT
- de l’objet Figure
- des objets Axes
- des objets UIcontrol
14/06/2011
9
Identifiants des objets graphiques
• Les fonctions GET et SET permettent d’accéder et de
modifier les propriétés de tous les objets graphiques, via
leurs « handle »
Fonction « calcul »
Fonction de l’IHM (.m)
FINDOBJ
Structure HANDLES
slider_hndl=findobj(gcf,'tag‘ , ‘slider1');
set(handles.edit1, ’string ’, ‘BONJOUR’)
var=get(slider_hndl, ‘value’ );
14/06/2011
10
 L’environnement de développement : le GUIDE, Graphical User
Interface Development Environment.
 Les objets graphiques : hiérarchie, propriétés, identifiants
 Génération de code automatique : fichier .fig, .m et fonctions
callback et createfcn
 Deux exemples simple d’IHM en électrophysiologie :
1- calcul de la Current Source Density sur des
enregistrements expérimentaux de potentiels de
champs.
2- Détection et classification de spikes
14/06/2011
11
Code automatique
• A la sauvegarde de l’IHM (GUI sous Matlab), deux
types de scripts sont générés automatiquement :
– Un fichier avec extension .fig : crypté
– Un fichier avec extension .m : code matlab pour le
développement
14/06/2011
12
Objet graphique : slider
•
% --- Executes on slider movement.
•
•
function sliderup_Callback(hObject, eventdata, handles)
• function sliderup_CreateFcn(hObject, eventdata, handles)
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
% hObject handle to sliderup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
•
•
•
•
•
•
•
•
•
•
•
•
% Hints: get(hObject,'Value') returns position of slider
%
get(hObject,'Min') and get(hObject,'Max') to determine range of slider
----------------------------------------------------------------------------------------------------global SIGNAL
thresholdup_hndl=findobj(gcf,...
'tag','thresholdup');
sliderdown_hndl=findobj(gcf,...
'tag','sliderdown');
spikeslength_hndl=findobj(gcf,...
'tag','length');
•
•
•
•
•
•
•
•
% --- Executes during object creation, after setting all properties.
% hObject handle to sliderup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
Propriétés
set(thresholdup_hndl,'value',get(hObject,'Value'),'string',num2str(get(hObje
ct,'Value')))
T=SIGNAL.Source(:,1);
Y=SIGNAL.Source(:,2);
spikeslength=str2double(get(spikeslength_hndl,'string'));
minph=get(sliderdown_hndl,'value'); %min peak height
maxph=get(hObject,'value'); %min peak height
[spikes,interspikes,tpks,pks]=SPIKES_peaks(T,Y,spikeslength,minph,maxph,1)
;
SIGNAL.Spikes=spikes; % (tspikes,spikes) pairs
SIGNAL.Interspikes=interspikes; % interspikes time
SIGNAL.Peaks=[tpks,pks];
update_axes1(2)
------------------------------------------------------------------------------------------------------
14/06/2011
13
GUIDE ou « à la main »
14/06/2011
14
à la main
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
function simple_gui
% SIMPLE_GUI Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
% Create and hide the GUI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450,285]);
% Construct the components.
hsurf = uicontrol('Style','pushbutton','String','Surf',...
'Position',[315,220,70,25]);
hmesh = uicontrol('Style','pushbutton','String','Mesh',...
'Position',[315,180,70,25]);
hcontour = uicontrol('Style','pushbutton',...
'String','Countour',...
'Position',[315,135,70,25]);
htext = uicontrol('Style','text','String','Select Data',...
'Position',[325,90,60,15]);
hpopup = uicontrol('Style','popupmenu',...
'String',{'Peaks','Membrane','Sinc'},...
'Position',[300,50,100,25]);
ha = axes('Units','Pixels','Position',[50,60,200,185]);
align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None');
%Make the GUI visible.
set(f,'Visible','on')
avec GUIDE
function varargout = simple_gui(varargin)
% SIMPLE_GUI M-file for simple_gui.fig
% SIMPLE_GUI, by itself, creates a new SIMPLE_GUI or raises the existing
% singleton*.
%
% H = SIMPLE_GUI returns the handle to a new SIMPLE_GUI or the handle to
% the existing singleton*.
%
% SIMPLE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIMPLE_GUI.M with the given input arguments.
%
% SIMPLE_GUI('Property','Value',...) creates a new SIMPLE_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before simple_gui_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to simple_gui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help simple_gui
% Copyright 2001-2003 The MathWorks, Inc.
% Last Modified by GUIDE v2.5 06-Jun-2011 11:28:28
14/06/2011
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @simple_gui_OpeningFcn, ...
'gui_OutputFcn', @simple_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
15
à la main
avec GUIDE
Avantages
- Code pour la création des objets
relativement simple et accessible
-Evolution aisée en fonction des versions
Matlab utilisées
Avantages
- Environnement graphique convivial et
intuitif, pour le design comme pour les
nombreuses propriétés des objets
- Une seule structure « handles » pour accéder
à tous les objets graphiques
-Actions des objets faciles à programmer grâce
aux fonctions callback et createfcn
-Debugging et modification facile
Inconvénients
- Changement de design à éviter absolument
- Partie actions des objets graphiques plus
délicates à programmer
- Accessibilité aux multiples propriétés des
objets fastidieuses
Inconvénients
- Code de l’initialisation de l’IHM difficile à
comprendre
- Attention au passage aux nouvelles versions
Matlab
- code partie purement graphique crypté (.fig)
14/06/2011
16
 L’environnement de développement : le GUIDE, Graphical User
Interface Development Environment.
 Les objets graphiques : hiérarchie, propriétés, identifiants
 Génération de code automatique : fichier .fig, .m et fonctions
callback et createfcn
 Deux exemples simple d’IHM en électrophysiologie :
1- calcul de la Current Source Density sur des
enregistrements expérimentaux de potentiels de
champs.
2- Détection et classification de spikes
14/06/2011
17
Merci pour votre attention
14/06/2011
18

Documents pareils