Docsity

Graphical User Interfaces - Lecture Slides | CSCI 0040, Exams of Computer Science

Toggle sidebar
bg1
CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16.0
Introduction to
Scientific Computing and
Problem Solving
Lecture #16
Graphical User Interfaces
(GUIs)
CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16.1
Announcements
• [Announcements of the day]
• By now you have completed the midterm exam
– Well done! Congratulations!
• What’s next: we switch to C after this lecture
– 4 weeks of classes
– 4 labs, 3 homeworks, 1 project, 1 final exam
• Final exam
– Not cumulative, covering only C material
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Graphical User Interfaces - Lecture Slides | CSCI 0040 and more Exams Computer Science in PDF only on Docsity!

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 0

Introduction to

Scientific Computing and

Problem Solving

Lecture # 16

Graphical User Interfaces

(GUIs)

Announcements

  • [Announcements of the day]
  • By now you have completed the midterm exam
    • Well done! Congratulations!
  • What’s next: we switch to C after this lecture
    • 4 weeks of classes
    • 4 labs, 3 homeworks, 1 project, 1 final exam
  • Final exam
    • Not cumulative, covering only C material

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 2

This lecture

  • Handle Graphics
  • GUIs
  • Examples - applications

Handle Graphics

  • Functions that control the characteristics of

graphics objects produced by MATLAB

  • Permits fine adjustments to appearance
    • X-axis grid only
    • Orange line color
  • Enables the creation of graphical user

interfaces (GUI)

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 6

Example 15-

Customizing a Plot

  • Plot the function from - 3!! x! 3! then
    • Make the background pink
    • Show the y-axis grid lines only
    • Change the line to orange and 2-points wide

sin

sinc

x

x

x

x

x

m-files: Ex 15 _ 1

User-Defined Data

  • Additional data can be defined and stored

with any object

setappdata(hndl, 'DataName', DataValue)

value = getappdata(hndl, 'DataName')

struct = getappdata(hndl)

hndl : object handle

DataName : name of the data

DataValue : value assigned to the name

value : value assigned to the name

struct : all user-defined names and values

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 8

Finding Objects

  • Best if you save the handle of the objects as they are

created, but…

  • Current object is the one last clicked on.

gcf handle of current figure

gca handle of current axes in current figure

gco handle of current object

h_fig = findobj('PropertyName', value,…)

h_fig : handles of objects matching properties/values

k = waitforbuttonpress;

0 : mouse click

1 : key press

Example 15-

Selecting Objects

  • Write a program that displays information

about selected objects in a plot until a key is

pressed

m-files: Ex 15 _ 2

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 12

Example 15-

Positioning Objects

  • The program creates two overlapping sets of

axes with a single figure

  • The first has a text comment attached to the

line itself

  • The second has a text comment in the lower

left corner

m-files: Ex 15 _ 3

Example 15-

Animating Plots

  • Fine control over plotting allows a form of

animation

m-files: Ex 15 _ 4

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 14

Graphical User Interfaces (GUI)

  • A familiar environment of pushbuttons, toggle

buttons, lists, menus, text boxes, etc.

  • Allows user to focus on the application and not

the mechanics of using it.

  • Simplifies user input
  • Avoids complicated command line syntax
  • Harder for the programmer because the

program must be prepared for mouse clicks

and other events at any time.

GUI Elements

  • Components
    • Pushbuttons, labels, boxes, menus, sliders, axes, etc.
    • Commands uicontrol, uimenu, uicontextmenu,

uitoolbar, axes

  • Containers
    • Hold components
    • Figure, panel, button group
    • Commands figure, uipanel, uibuttongroup
  • Callbacks
    • Code executed as a response to an event
    • Needed for every GUI component with a function

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 18

Gallery of GUI Components

  • Static text fields
  • Edit boxes
  • Pushbuttons
  • Toggle buttons
  • Checkboxes and radio buttons
  • Popup menus
  • List boxes
  • Sliders

m-files: editbox, togglebutton, checkbox, radiobutton, popupmenu, listbox

Example 16-

Temperature Conversion

  1. Layout 2 text fields, 2 edit boxes, and one slider
  2. Set Tag properties: Label1 , Label2 , Edit1 , Edit2 ,

and Slider

  1. Store String property values "Degrees F" and

Degrees C"

  1. Set slider maximum to 100
  2. Store initial values in String property for edit fields

and Value property for slider (32°F and 0°C)

  1. Set Name property of figure to 'Temperature

Conversion '

  1. Save as temp_conversion.fig

temp_conversion.fig

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 20

Example 16-

Temperature Conversion

  • Note the callback functions in the .m file
  • Write conversion functions to_c and to_f
  • Write callback functions for Edit 1 , Edit 2 ,

and Slider 1

  • Respond to both edit boxes and slider
  • Convert strings in edit boxes to numbers
  • Limit user entries to 0-100°C and 32-212°F

m-files: temp_conversion, to_c, to_f

Organizing Components

  • Panels
    • Container for other elements that move as a group
  • Button groups
    • Insure no more than one radio button or toggle is

selected at a time

  • Dialog boxes
    • Display information (e.g., warning) or get input

CSCI0040 - Introduction to Scientific Computing and Problem Solving 2009 - 16. 24

Example 16-3 (cont.)

Histogram GUI

  • Write code for histGUI_OpeningFcn to

initialize the background color and the number

of bins.

  • Write callbacks for File Open and Exit.
  • Write callback for number of bins edit box.
  • Write callback for edit box ( NBins )

m-files: histGUI.fig, histGUI.m

Almost Spring Break…

Have a nice and

safe Spring break :)

Things to remember… (or maybe not)