Upload
vonguyet
View
235
Download
0
Embed Size (px)
Citation preview
1
Instituto Superior Técnico,Dep. de Engenharia Mecânica - ACCAII
Construção de Interfaces Gráficas Programa/Utilizador
• Componentes das GUIs no MATLAB
• Estrutura da m-file para uma GUI
• Elementos de estilo
• Casos de Estudo
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
2222• Disponível na pasta do MATLAB, subdirectoria "..\help\techdoc\creating_guis\examples"
• Abrir pela linha de comandos utilizando: guide controlsuite
2
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
3333
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
4444
3
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Editor de GUIs: guide
5555
• GUI do guide
Componentes
de GUIs
Toolbar
do guide
Editor de Toolbars de GUIs
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componentes disponíveis no guide
6666
4
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Push Button
7777
Component Icon Description
Push Button
• Push buttons generate an action
when clicked.
• For example, an OK button might
apply settings and close a dialog box.
• When you click a push button, it
appears depressed; when you release
the mouse button, the push button
appears raised.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Slider
8888
Component Icon Description
Slider
• Sliders accept numeric input within a
specified range by enabling the user
to move a sliding bar, which is called a
slider or thumb.
• Users move the slider by clicking the
slider and dragging it, by clicking in the
trough, or by clicking an arrow.
• The location of the slider indicates
the relative location within the
specified range.
5
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Radio Button
9999
Component Icon Description
Radio Button
• Radio buttons are similar to check
boxes, but radio buttons are typically
mutually exclusive within a group of
related radio buttons. That is, when you
select one button the previously
selected button is deselected.
• To activate a radio button, click the
mouse button on the object. The display
indicates the state of the button.
•Use a button group to manage mutually
exclusive radio buttons.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Check Box
10101010
Component Icon Description
Check Box
• Check boxes can generate an action
when checked and indicate their state
as checked or not checked.
•Check boxes are useful when
providing the user with a number of
independent choices, for example,
displaying a toolbar.
6
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Edit Text
11111111
Component Icon Description
Edit Text
• Edit text components are fields that
enable users to enter or modify text
strings.
• Use edit text when you want text as
input.
• Users can enter numbers but you
must convert them to their numeric
equivalents.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Static Text
12121212
Component Icon Description
Static Text
• Static text controls display lines of
text.
• Static text is typically used to label
other controls, provide directions to
the user, or indicate values associated
with a slider.
• Users cannot change static text
interactively.
7
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Pop-Up Menu
13131313
Component Icon Description
Pop-Up Menu
• Pop-up menus open to display a list
of choices when users click the arrow.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: List Box
14141414
Component Icon Description
List Box• List boxes display a list of items and
enable users to select one or more
items.
8
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Toggle Button
15151515
Component Icon Description
ToggleButton
• Toggle buttons generate an action and
indicate whether they are turned on or off.
• When you click a toggle button, it appears
depressed, showing that it is on.
• When you release the mouse button, the
toggle button remains depressed until you
click it a second time. When you do so, the
button returns to the raised state, showing
that it is off.
• Use a button group to manage mutually
exclusive toggle buttons.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Table
16161616
Component Icon Description
Table
• Use the table button to create a
table component. (Refer to the uitable
function for more information on using
this component.)
9
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Axes
17171717
Component Icon Description
Axes
• Axes enable your GUI to display
graphics such as graphs and images.
• Like all graphics objects, axes have
properties that you can set to control
many aspects of its behavior and
appearance (See “Axes Properties” in
the MATLAB Graphics documentation)
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Panel
18181818
Component Icon Description
Panel
• Panels arrange GUI components into
groups.
• By visually grouping related controls, panels
can make the user interface easier to
understand. A panel can have a title and
various borders. Panel children can be user
interface controls and axes as well as button
groups and other panels.
•The position of each component within a
panel is interpreted relative to the panel. If
you move the panel, its children move with it
and maintain their positions on the panel.
10
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Button Group
19191919
Component Icon Description
Button Group
• Button groups are like panels but are
used to manage exclusive selection
behavior for radio buttons and toggle
buttons.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Componente: Toolbar
20202020
Component Icon Description
ToolbarGUIDE Toolbar Editor
• You can create toolbars containing
push buttons and toggle buttons.
•Use the GUIDE Toolbar Editor to
create toolbar buttons.
• Choose between predefined buttons,
such as Save and Print, and buttons
which you customize with your own
icons and callbacks.
11
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Estrutura de uma GUI no MATLAB
21212121
Figure: simple_gui.fig M-file: simple_gui.m+
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Estrutura padrão da m-file de uma GUI
22222222
12
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
23232323
• Comments
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
24242424
• Initialization
13
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
25252525
• Opening Function
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
26262626
• Output Function
14
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
27272727
• Component and figure callbacks (sample)
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
28282828
• Utility / helper functions
Não se aplica à GUI controlsuite
15
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Template de uma callback (push button)
29292929
Declaração da função de callback para a componente que disparou a chamada
Argumentos de entrada. A sequência indicada é fixa.
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
• OBJECT HANDLE (hObject): estrutura com atributos e
propriedades (os mesmos visualizáveis no Property
Inspector) da componente que disparou a callback.
• EVENT DATA (eventdata): estrutura com o histórico
da sequência de evento até ao disparo da callback (não
é utilizado por todas as componentes).
• HANDLES STRUCTURE (handles): apontador para uma
estrutura com atributos e propriedades (os mesmos
visualizáveis no Property Inspector) de todas as
componentes existentes na GUI, bem como dados
específicos da aplicação
Estrutura de dados dos argumentos
30303030
16
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
31313131
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Exemplo: GUI controlsuite
32323232
• Push Button
• Toggle Button
• Ver os callbacks dos restantes componentes no ficheiro.
17
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Elementos de Estilo
33333333
• “Effective interfaces are visually apparent and forgiving,
instilling in their users a sense of control. Users quickly
see the breadth of their options, grasp how to achieve
their goals, and do their work.”
• “Efficient interfaces do not concern the user with the
inner workings of the system.”
• “Effective applications and services perform a maximum
of work, while requiring a minimum of information from
users.”http://www.asktog.com/basics/firstPrinciples.html
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Elementos de Estilo
34343434
"Less is more"Mies van der Rohe
(while citing a poem by Robert Browning)
18
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Casos de Estudo
35353535
• Desenvolver uma GUI que implementa uma máquina de
somar.
• Analisar as seguintes GUIs (abrir pela linha de comandos)
• “Simple GUI” (>> guide simple_gui)
• “controlsuite” (>> guide controlsuite)
Disponiveis na pasta do MATLAB, subdirectoria "..\help\techdoc\creating_guis\examples"
José Borges José Borges -- Miguel Miguel Pedro Pedro SilvaSilva Computação e Programação 2009 / Computação e Programação 2009 / 20102010
Referências
36363636
• Mathworks:
• “Creating Graphical User Interfaces” (buildgui.pdf)
http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/buildgui.pdf
• Elementos de estilo:
• http://www.asktog.com/basics/firstPrinciples.html
• http://www.fast-consulting.com/desktop.htm
• http://www.usabilitynet.org/management/b_design.htm