ginput is turning off mouse cursor
9 次查看(过去 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 );
0 个评论
采纳的回答
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.
0 个评论
更多回答(2 个)
Peter
2011-11-28
1 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visual Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!