Mars Data Analysis Using IDL GG7101 Lecture 13 - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Mars Data Analysis Using IDL GG7101 Lecture 13

Description:

Checking Events in the Event Loop. Storing data about widgets ... Clickable button. widget_button. A container for other widgets. widget_base. Description ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 33
Provided by: fscotta
Category:

less

Transcript and Presenter's Notes

Title: Mars Data Analysis Using IDL GG7101 Lecture 13


1
Mars Data Analysis Using IDLGG710-1Lecture 13
  • F. Scott Anderson
  • Office POST 526B
  • Phone 956-6887
  • Email anderson_at_higp.hawaii.edu

2
Review of 11/17/04
  • Homework Review
  • FFT's
  • Frequencies that go with FFT's
  • Power Spectra

3
Today
  • Quiz Review Quiz
  • GUIs
  • Event Loop Concept
  • Widgets (bases, buttons, drawing)
  • Widget IDs
  • Event Structures
  • Controlling widgets
  • Checking Events in the Event Loop
  • Storing data about widgets
  • Destroying widgets
  • In class exercise
  • Class Evaluation

4
Questions from 11/17/04
  • Comments, Questions, Thoughts?

5
Quiz 8/9/10 HW4,4a Scores
6
Quiz 11
7
Quiz Answers
8
Quiz Answers
9
What is a GUI?
  • GUIGraphical User Interface
  • A windowed interface to your program
  • Download example and data from website
  • xdisp.pro
  • Mars Topo Grav
  • Try it
  • Disclaimer It is not claimed that this program
    represents good GUI programming style!

10
GUI versus Procedural Programs
  • All codes we have written are procedural
  • Read data, process, plot/write data
  • GUI programs driven by user interaction

11
GUI Design
  • Think out design ahead of time
  • Minimize total number of onscreen controls
  • Avoid excessive dead space
  • Align controls
  • Avoid under/over sized controls
  • Avoid non-standard names for controls
  • Think out design ahead of time!

12
Elements of a GUI Widgets
  • GUI's are made out of components called widgets

13
Widget Hierarchy
  • All widgets are hierarchically contained in bases
  • The top level base can have sub-bases
  • A sub-widget is known as a child
  • A widget containing a child widget is called the
    parent

Top Level Base Widget
Child Base Widget
Button Widget
Button Widget
Child Base Widget
Draw Widget
14
Making a widget base
  • Widget bases can hold widgets in rows or in
    columns
  • Top level widget bases can have menubars and a
    title at the top of the window
  • To make a top-level widget base
  • ID widget_base(titlestr, /row)
  • ID widget_base(titlestr, /col)
  • To make a child-base
  • ID widget_base(ID_parent, /row)
  • ID widget_base(ID_parent, /col)

15
Example Widget buttons
  • Widget buttons must be contained within a widget
    base
  • The words shown on the button is set with a
    parameter called value
  • To make a widget button
  • ID widget_button(ID_parent_base, value str)

16
Structure of Widget Program
  • Create widget bases
  • Fill with widgets
  • Show widgets on-screen (realize widgets)
  • Go to event-loop (manage widgets)
  • Control widgets as necessary
  • Resize, draw pictures, whatever
  • Destroy widgets
  • Achieved by destroying top-level widget
  • Let's do an example of steps 1-3

17
Show me a Widget! Steps 1-3
  • Create widget base to contain button
  • tp widget_base(/column)
  • Create button in top-level widget
  • but widget_button(tp, value'Rockin!')
  • Show me the money!
  • widget_control, tp, /realize
  • Note you can click it, but nothing happens
  • Can destroy it by closing

18
Widget ID
  • The value returned from a widget function allows
    you to manipulate that widget or widget hierarchy
    at a later time
  • Must keep track of widget ID's you intend to
    manipulate later
  • Can toss widget ID's that are never used again
  • In previous example
  • Toss "but" ID never reused
  • Keep "tp" used to realize widget hierarchy

19
widget_control
  • In addition to realizing widgets, widget_control
    can be used to
  • Get values from existing widgets
  • Set values for existing widgets
  • Check for events
  • Destroy widgets and widget hierarchies
  • Form
  • widget_control, widget_ID, get_valuevar
  • widget_control, widget_ID, set_valuevar
  • widget_control, widget_ID, /destroy

20
Widget Value/Uvalue
  • All widgets contain a field called value
  • Used to carry information controlling the use of
    the widget
  • Button widgets use value to hold string that will
    be shown on the button (e.g. "Rockin!")
  • Draw widgets use value to hold window ID for use
    with wset
  • All widgets also have a user definable field to
    carry information
  • This field can be a variable of any type
    typically struct
  • Can be accessed with
  • widget_control, widget_ID, set_uvaluevar
  • widget_control, widget_ID, get_uvaluevar

21
The Event Loop Step 4
  • The event loop is a subroutine to the main
    routine
  • The main routine draws widgets and destroys
    widgets on exiting the the event loop
  • All real action takes place in the event loop
  • IDL automatically checks for user interaction
    (events) and sends a structure of event data to a
    routine identified as the event loop
  • To identify the sub-routine to be used as the
    event loop, use the xmanager procedure
  • Has a default name of a string handed to xmanager
    "_event"

22
The Event Loop Step 4
  • All event structures include the ID of the widget
    involved in the event, and the top-level widget
  • For example, if the event structure variable is
    called ev
  • Why hand it the top ID or widget ID? Because
    many GUI programs can run simultaneously, so you
    may want to check the ID to see which GUI/widget
    is generating the event
  • Lets try implementing step 4 and manage an event
    loop

23
Expanding our Example
  • pro widex_event, evt
  • widget_control, evt.id, get_valueres
  • if (res eq 'Rockin!') then
  • print, "Someone touched the button!"
  • end
  • pro widex
  • top widget_base(/column)
  • but widget_button(top, value'Rockin!')
  • widget_control, top, /realize
  • xmanager, 'widex', top
  • end

Event Loop
widex.pro
Main Routine
24
Storing Widget Information
  • If we want to modify a widget in the event loop,
    we must know it's ID
  • However, all ID's defined in the main routine,
    and in our example, have not been handed to our
    event loop sub-routine
  • Typically, ID's from all widgets that will be
    modified are placed in a structure that is kept
    in the top-level base user value field (uvalue)
  • Other information relevant to the program can
    also be kept in this structure
  • Commonly used variables, etc.
  • Example Change the previous example so that when
    clicked, "Rockin!" changes to "Doh!" and back on
    2nd click

25
Rockin! 2 Doh!
  • pro widex_event, evt
  • widget_control, evt.id, get_valueres
  • widget_control, evt.top, get_uvalueuvl
  • if (res eq 'Rockin!') then
  • widget_control, uvl.but_id, set_value"Doh!"
  • else if (res eq 'Doh!') then
  • widget_control, uvl.but_id, set_value"Rockin!"
  • end
  • pro widex
  • top widget_base(/column)
  • but widget_button(top, value'Rockin!')
  • widget_control, top, set_uvaluebut_idbut,
    var0
  • widget_control, top, /realize
  • xmanager, 'widex', top
  • end

Event Loop
widex.pro
Main Routine
26
Step 5 Destroying Widgets
  • IDL will repeat the event loop ad infinitum until
  • The widget is destroyed using widget_control
  • The widget is destroyed by closing the window
  • When a widget is destroyed, program flow is
    resumed following xmanager
  • Now lets change our example so that
  • When we click once Rockin changes to Doh
  • On the second click, the widget is destroyed, and
    the program ends

27
Destroy a Widget Ha ha ha ha!
  • pro widex_event, evt
  • widget_control, evt.id, get_valueres
  • widget_control, evt.top, get_uvalueuvl
  • if (res eq 'Rockin!') then
  • widget_control, uvl.but_id, set_value"Doh!"
  • else if (res eq 'Doh!') then
  • widget_control, evt.top, /destroy
  • end
  • pro widex
  • top widget_base(/column)
  • but widget_button(top, value'Rockin!')
  • widget_control, top, set_uvaluebut_idbut,
    var0
  • widget_control, top, /realize
  • xmanager, 'widex', top
  • end

Event Loop
widex.pro
Main Routine
28
Draw Widgets
  • Draw widgets are used to hold plots and images,
    and is like the window command
  • The value of a draw widget is it's window ID
  • Draw widgets can have a window size a total
    image size
  • If the image size gt window size, then scroll bars
    are added
  • Form
  • IDwidget_draw(ID_parent, xsizex1, ysizey1,
  • x_scroll_sizex2, y_scroll_sizey2)

29
Draw Widgets
  • Example with scroll bars
  • IDwidget_draw(ID_parent, xsize500, ysize500,
  • x_scroll_size400, y_scroll_size400)
  • Note On some computers, parts of the image that
    are not currently displayed are lost.
  • Fix device, retain2
  • You can resize the plottable area of a draw
    widget using widget_control
  • widget_control, ID, draw_xsizex1a, draw_ysizey1a

x2
y2
y1a
x1a
30
In Class Exercise
  • Make a GUI to display a jpeg image
  • Have file "Open" "Quit" buttons
  • Make the image no display area 400x400
  • Assume an initial blank image of 500x500
  • Read an image when "Open" is clicked
  • Use scroll bars
  • Resize the draw widget size to match the image
    size
  • Leave the scroll bars so no more than 400x400
    area shown
  • Demonstrate on jpeg from website

31
In Class Exercise
  • Start by making an outline of steps!

32
End of Class Wahoo! Wahoo!
  • In two weeks
  • Class presentations
  • Science, IDL Code, Results
  • 15 minutes, 5 for questions (20 total)
  • In closing
  • It has been a blast working with all of you!
  • Think about all we have covered
  • Variables, procedures, graphics, math, GUIs!
  • Am very pleased with everyone's progress
  • For me class will be even better next time!
  • More HW, more exercises, some reorganization

You have the power of IDL! Use it for good - not
evil!
Write a Comment
User Comments (0)
About PowerShow.com