Re: Question about selecting images from Draw Widgets [message #53048 is a reply to message #53047] |
Fri, 16 March 2007 20:49   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
gearoid.k@gmail.com writes:
> This program takes in 10 images and displays the first 4 (image0 to
> image3) in the GUI. For the final function 'viewNext', I would like
> all the images (which are saved in the array 'images_array' which is
> defined in the OpenFile function) to shift up by one place, such that
> image1 to image4 are displayed.
>
> Could you tell me how to do this?
Well, to start with, I wouldn't be using the GUI Builder
to build your widget program. The possibility that you might
actually understand how the program works is slim, to say
the least. :-)
Typically, what we do is store ALL the information we
need to run our program in an "info" structure. Suppose
we need the four drawIDs, the window index numbers that go
with the draw widgets, and the 10 images themselves. And
suppose we have stored these in the variables drawIDs,
wIDs, and theImages. (The array containing the images
is probably a pointer array, because we don't really
want to carry around 10 images.) We probably need some
kind of counter, so we know which image is first in the
image display. Let's call this imgCounter and suppose it
starts off at 0, so the first 4 of 10 images are displayed
in our windows.
info = {drawIDs:drawIDs, wIDs:wIDs, theImages:theImages, $
imgCounter:imgCounter, numImages:numImages)
Usually, we make info a pointer, then we store it in
the user value of the top-level base, so it is accessible
to all the even handlers:
info = Ptr_New(info, /No_Copy)
Widget_Control, tlb, Set_UValue=info
This is typically done just before you call XMANAGER
to start your program running in the widget definition
module (or sometimes called the command module).
Ok, so somewhere you have created a couple of buttons
named NEXT and PREVIOUS, and you have assigned an event
handler to them. Maybe you did something like this:
buttonID = Widget_Button(baseID, Value='Next', $
Event_Pro='MyProgram_ButtonEvents')
buttonID = Widget_Button(baseID, Value='Next', $
Event_Pro='MyProgram_ButtonEvents')
So when the user hits either the NEXT or PREVIOUS
button, the event will go to this event handler.
Here is how you write it:
PRO MyProgram_ButtonEvents, event
; Get the information you need to run the program.
Widget_Control, event.top, Get_UValue=info
; Which button is this?
Widget_Control, event.ID, Get_Value=buttonValue
; Set the image counter.
CASE buttonValue OF
'Next': (*info).imgCounter = 0 > ((*info).imgCounter) + 1 < $
((*info).numImages-4)
'Previous': (*info).imgCounter = 0 > ((*info).imgCounter) - 1 < $
((*info).numImages-4)
ENDCASE
; Display the four images in the four draw widget windows.
cnt = Indgen(4) + (*info).imgCounter
FOR j=0,3 DO BEGIN
WSet, (*info).wIDs[j]
TV, *((*info).theImages[cnt[j]])
ENDFOR
END
That's it. Pretty simple. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|