Re: window events [message #7446 is a reply to message #7369] |
Mon, 11 November 1996 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Phil Williams <williams@irc.chmcc.org> writes:
> I'm in the process of building a widget application and want to open
> some auxialliary windows for plotting and displaying images. Is there a
> way to get the mouse events that occur in these windows? If so, how do
> I do it?
Absolutely. Those graphic windows should be draw widgets that exist
in their own top-level bases. You will have to turn button events
(or motion events, or both) on for the draw widgets. I also make
sure they have a group leader so they die properly when the main
program dies. And I usually assign them their own event handler.
This means they will need to know where the "info" structure
that has all the program information is stored. (Normally,
an event handler looks in event.top for the info structure, but
of course, this is a *different* event.top than the one associated
with the main program.) I usually put the main programs top-level
base identifier in the user value of the draw widget as a "pointer"
to the info structure. Your definition code might look like this:
graphicsBase = WIDGET_BASE(TITLE='Image Window', GROUP_LEADER=tlb)
graphicsDrawID = WIDGET_DRAW(graphicsBase, XSIZE=imgXsize, $
YSIZE=imgYsize, BUTTON_EVENTS=1, $
EVENT_PRO='GRAPHICSBASE_EVENTS', UVALUE=tlb)
WIDGET_CONTROL, graphicsBase, /REALIZE
WIDGET_CONTROL, graphicsDrawID, GET_VALUE=graphicsWID
WSET, graphicsWID
A bare-bones event handler might look like this:
PRO GRAPHICSBASE_EVENTS, event
WIDGET_CONTROL, event.id, GET_UVALUE=infoStorageLocation
WIDGET_CONTROL, infoStorageLocation, GET_UVALUE=info, /NO_COPY
WSET, info.graphicsWID
; Here is where you do your thing with the event, whatever it is.
WIDGET_CONTROL, infoStorageLocation, SET_UVALUE=info, /NO_COPY
END
In actual practice, I never try to do any graphics into a detached graphics
window like this without first making sure its still around on the display.
Those darn users are always destroying things like graphics windows
with their mouse. I always have the ID of the graphics draw widget
in my info structure, so my event handler code looks more like this:
PRO GRAPHICSBASE_EVENTS, event
WIDGET_CONTROL, event.id, GET_UVALUE=infoStorageLocation
WIDGET_CONTROL, infoStorageLocation, GET_UVALUE=info, /NO_COPY
; Make sure the graphics window is still there. If not, recreate it.
IF WIDGET_INFO(info.graphicsDrawID, /VALID_ID) THEN BEGIN
WIDGET_CONTROL, info.graphicsDrawID, GET_VALUE=graphicsWID
WSET, graphicsWID
ENDIF ELSE BEGIN
graphicsBase = WIDGET_BASE(TITLE='Image Window', $
GROUP_LEADER=infoStorageLocation)
info.graphicsDrawID = WIDGET_DRAW(graphicsBase, XSIZE=info.imgXsize, $
YSIZE=info.imgYsize, BUTTON_EVENTS=1, $
EVENT_PRO='GRAPHICSBASE_EVENTS', UVALUE=infoStorageLocation)
WIDGET_CONTROL, graphicsBase, /REALIZE
WIDGET_CONTROL, info.graphicsDrawID, GET_VALUE=graphicsWID
WSET, graphicsWID
ENDELSE
; Here is where you do your thing with the event, whatever it is.
WIDGET_CONTROL, infoStorageLocation, SET_UVALUE=info, /NO_COPY
END
If you would like to see an example of this kind of thing, I cobbled
together an image profile program called XPROFILE. It has a main
program window, and detached window for the image, and a second
detached window for the profile plots. If you click in the image
window, you update the profile window with new column and
row profiles of the image at the location you clicked. If you
click in the profile window, you see the actual column and row
in the image window that was used create the profiles.
You can download it via anonymous ftp from the machine
ftp.frii.com. It is in the directory /pub/dfanning/outgoing/idl_examples.
It is named xprofile.pro.
Good luck!
David
*************************************************
* David Fanning, Ph.D.
* 2642 Bradbury Court, Fort Collins, CO 80521
* Phone: 970-221-0438 Fax: 970-221-4762
* E-Mail: davidf@dfanning.com
*
* Sometimes I go about pitying myself, and all along my
* soul is being blown by great winds across the sky.
* -- Ojibway saying
************************************************
|
|
|