Use all 4 SelectionType options in a ButtonDownFcn callback?
9 次查看(过去 30 天)
显示 更早的评论
I'm doodling with a gui where I would like to use all four "SelectionType" posibilities to select different responses to the button selection ofthe users. Somehow I cannot manage to get a clean single use of the "open" selectiontype. With the function below set to the buttondownfcn of an axes, I cannot manage to get a single evaluation of the "open" option by double clicking. Either I get the "normal" output before (ptime = 0) or after (ptime = 0.3), that is not what I wanted. Does anyone have an example to show how this is supposed to be done?
Example function:
function seltest(ptime)
point1 = get(gcf,'CurrentPoint');
seltype = get(gcf,'SelectionType')
pause(ptime)
switch seltype
case 'alt'
disp(['ALT: ',datestr(clock,'HH:MM:SS.FFF')])
case 'extend'
disp(['EXTEND: ',datestr(clock,'HH:MM:SS.FFF')])
case 'normal'
disp(['NORMAL: ',datestr(clock,'HH:MM:SS.FFF')])
case 'open'
disp(['open: ',datestr(clock,'HH:MM:SS.FFF')])
otherwise
disp(['VERY ODD: ',datestr(clock,'HH:MM:SS.FFF')])
end
This is then tested with:
figure,set(gca,'buttonDownFcn',@(src,event) seltest(0))
and then clicking away, followed by:
set(gca,'buttonDownFcn',@(src,event) seltest(0.2))
This is one typical outcome:
>> set(gca,'buttonDownFcn',@(src,event) seltest(0.2))
>> seltype =
normal
seltype =
open
open: 20:22:19.773
NORMAL: 20:22:19.907
A single run through the "open" case is what I hoped for here.
2 个评论
Walter Roberson
2014-1-27
I am not sure why the pause() is there considering that you are checking seltype before the pause() rather than after?
Bjorn Gustavsson
2014-1-28
Good suggestion. That worked better - but I still get two "open", and the function runs twice. It's tolerable but not what I'd like to see - if a double click is one "open" event then I'd like the function to run once afte that, not twice. One possibility is that I'm motorically challenged and can't double-click, but I've managed OK this far.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!