Problems using CURSOR [message #5501] |
Wed, 17 January 1996 00:00  |
hahn
Messages: 108 Registered: November 1993
|
Senior Member |
|
|
Hi,
My IDL program generates output on a terminal (either X Windows System
or MS Windows) and wants to return 4 coordinate pairs the users
selects. However, the following program waits only once for input and
returns 4 time the same coordinates. The problem occurs with both IDL
version 3.6.1b and 4.0.1 on both Unix and MS Windows, so I guess I
might have overlooked some basic fundamentals using CURSOR.
The following procedure is called after Set_plot, 'x':
pro rd4
;
xr=[0,300] & yr=[-4000,4000]
;
; Some test data
dat = [100,200,-50,-300,-1200,-3000,-2000,0,500,800,3000,2400]
x = IndGen(12)*28
Plot, x, dat, xrange=xr, yrange=yr
;
;Position the cursor at the center of the drawing area
;
tvcrs, 150, 0, /data
Print, 'Enter 4 coordinates by clicking the left mouse key'
xin = FltArr(4) & yin = xin
for i=0,3 do begin
cursor, isx, isy, wait=3
xin(i) = isx
yin(i) = isy
print, isx, isy
endfor
end
What is wrong ?
Norbert Hahn
|
|
|
Re: Problems using CURSOR [message #5502 is a reply to message #5501] |
Wed, 17 January 1996 00:00   |
Ken Knighton
Messages: 44 Registered: May 1995
|
Member |
|
|
hahn@hrz.th-darmstadt.de (Norbert Hahn) wrote:
> Hi,
>
> My IDL program generates output on a terminal (either X Windows System
> or MS Windows) and wants to return 4 coordinate pairs the users
> selects. However, the following program waits only once for input and
> returns 4 time the same coordinates.
snip, snip
>
> for i=0,3 do begin
> cursor, isx, isy, wait=3
> xin(i) = isx
> yin(i) = isy
> print, isx, isy
> endfor
> end
>
> What is wrong ?
The WAIT keyword to the cursor procedure causes the cursor procedure to
wait until a mouse button is pressed or to return immediately if the
mouse button is already pressed. Using wait=3 has the same meaning
as just /WAIT. I suspect that you have confused the WAIT keyword
with the Wait argument to the cursor function. See the documentation.
What is happening with your program is that your mouse finger is too
slow. When you click the mouse, your program polls the state of the
mouse several times while the button is still down and completes the
loop. What you really want is for CURSOR to wait until a button
transition occurs.
You could have supplied the wait argument (not keyword) by:
cursor, isx, isy, 3
This would have caused CURSOR to return when a mouse button was depressed.
Alternately, (and better for readability) you could have written:
cursor, isx, isy, /DOWN
NOTE: Using X-Windows over a network is slow enough that this problem may
only occur intermittently and produce a real bothersome and hard to notice
and locate feature in your code.
I hope this helps.
Ken Knighton
Fusion Division
General Atomics
San Diego, CA
|
|
|
Re: Problems using CURSOR [message #5639 is a reply to message #5501] |
Thu, 18 January 1996 00:00  |
M.Reuss
Messages: 4 Registered: January 1996
|
Junior Member |
|
|
It is certainly a nasty behaviour.
To overcome it, you should insert the line
CURSOR,xdummy,ydummy,4
directly after your CURSOR,isx,... call.
This forces IDL to wait for the button to be RELEASED again.
BTW:
CURSOR,isx,isy,wait=3
is probably not what you meant to code. (wait in the description is a
parameter, not a keyword)
To make the procedure return at the button-down transition, you type either
CURSOR,isx,isy,/down
or
CURSOR,isx,isy,3
Your command made IDL wiat for the button being depressed.
However, correcting this does not change the nasty behaviour you noticed,
so that the CURSOR,...,...,4 call is necessary
Best regards
Matthias Reuss (reuss@osf1.mpae.gwdg.de)
|
|
|