ginput is turning off mouse cursor

5 次查看(过去 30 天)
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 );

采纳的回答

Sven
Sven 2011-11-28
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.

更多回答(2 个)

Peter
Peter 2011-11-28
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 个评论
Sven
Sven 2011-11-28
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')

请先登录,再进行评论。


Divakar Roy
Divakar Roy 2012-11-13
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.

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by