ginput is turning off mouse cursor

5 Ansichten (letzte 30 Tage)
Peter
Peter am 28 Nov. 2011
Hi, I am not a MATLAB programmer but have a lot of experience with C and Basic. Therefore, for my sins, I have been asked to look at a problem one of our researchers is having with some code written a long time ago which works fine in version 7.1.0.246 but is giving a problem in MATLAB version 7.10.0.499
There is a GUI as part of the program that shows the mouse cursor when it is initially displayed, ie the mouse can be moved around the screen and is always visible.
On clicking a button to execute a function, in the earlier version of MATLAB, the mouse cursor remains visible inside this GUI along with the ginput crosshairs. However, in the later version, the mouse cursor disappears and all that is visible are the crosshairs as the mouse is moved around.
I have tracked down the point in the code where the cursor becomes invisible and it is when this function is executed. I have copied it below.
Can anyone tell me why this should be happening and, even better, how I can make the cursor remain visible using the later version of MATLAB, please.
The earlier version of MATLAB is running under Windows XP. The later version is on both an XP and Windows 7 machine and both display this problem.
Very many thanks,
Peter
% --- Executes on button press in markEnclosuresPushbutton. function markEnclosuresPushbutton_Callback(hObject, eventdata, handles)
px = ones( 1, 16 ); py = ones( 1, 16 );
for encCnt = 1 : 16
[ px( encCnt ), py( encCnt ) ] = ginput(1);
hold on;
plot( px( encCnt ), py( encCnt ), 'r.' )
h = text( px( encCnt ) + 2, py( encCnt ) -2, num2str( encCnt ) );
set(h,'color','r');
drawnow;
end
handles.data.spec.encPx = px;
handles.data.spec.encPy = py;
set( handles.startPushbutton, 'enable', 'on' );
guidata( hObject, handles );

Akzeptierte Antwort

Sven
Sven am 28 Nov. 2011
Does the code by any chance rely on window events such as buttondownfcn, buttonmotionfcn, etc? ginput() has the annoying behaviour of overwriting these function (so it can show the cross-hairs) but not putting them back when it's done. Try encasing your loop in the following:
% Collect old fig handle functions overwritten by ginput
fcnNames = {'WindowButtonDownFcn','WindowButtonMotionFcn'};
fcnVals = get(gcf,fcnNames);
oldFcnNameValPairs = cat(1, fcnNames, fcnVals);
... % Your loop here %
set(gcf, oldFcnNameValPairs{:}) % Restore the original figure functions
Now, admittedly I would expect that if this were the problem it wouldn't only appear in the later MATLAB version, and the single calls to ginput() should at least return your original mouse cursor, but you might get lucky.

Weitere Antworten (2)

Peter
Peter am 28 Nov. 2011
Hi Sven,
Many thanks for taking the time to reply. I tried what you suggested but it did not cure the problem, I'm afraid.
However, I have found an acceptable workaround from the web. What I have done is:
copy ginput.m to my working folder
rename it ginputx.m
change "fullcrosshair" to "crosshair" within ginputx.m
change ginput.m to ginputx.m within the function as in my original post
Now when the function is executed, I get a small crosshair (about 5mm x 5mm on the screen) which is very visible and perfectly acceptable for this application. The normal mouse cursor is still not visible.
I would still be keen to hear of any other comments on the problem but at least I have a solution for now.
Many thanks again,
Peter
  1 Kommentar
Sven
Sven am 28 Nov. 2011
No problem, glad you have an acceptable workaround. Sorry, I misread the original question as you were losing your cursor _after_ ginput, rather than during ginput.
Similar to your solution, there are a number of other options you can try:
crosshair | {arrow} | watch | topl |
topr | botl | botr | circle | cross |
fleur | left | right | top | bottom |
fullcrosshair | ibeam | custom | hand
(see doc "Figure Properties" -> Pointer)
Such as:
figure, imagesc(rand(5)), set(gcf,'Pointer','cross')

Melden Sie sich an, um zu kommentieren.


Divakar Roy
Divakar Roy am 13 Nov. 2012
I have just uploaded to file-exchange, codes that are supposed to solve the original problem. Here's the link - http://www.mathworks.com/matlabcentral/fileexchange/38997 . Basically it uses BUTTONDOWNFCN, alongwith uipanel. Would appreciate to know if the codes are any help to people still interested in the problem.

Kategorien

Mehr zu Data Exploration finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by