GUIDE: gcf windowscrollWheelFcn and gca ButtonDownFcn interaction

Hello, thanks for reading this,
I have a problem at the moment with a interaction of axes ButtonDownFcn and the gcf's windowscrollWheelFcn.
I made a simple gui in GUIDE with two axes, and when I ButtonDownFcn on either axes I can print unique messages. Additionally, when I click on a axes and use the windowscrollWheelFcn, I can perform a callback on the axes (I replot rand). However, when I do the windowscrollWheelFcn the callback to ButtonDownFcn no longer works: I can't reprint the message.
Any ideas? When I reprint, I set the HitTest of the image (not the axes) to off when I replot, but it doesn't help the problem. The windowscrollWheelFcn, however, works just fine, which makes me think its a HitTest issue somewhere that's not being set.
EDIT: I just put the additional command behind the windowscrollWheelFcn:
set(gca,'ButtonDownFcn', @axes1_ButtonDownFcn);
and I was able to use the ButtonDownFcn callback again, but only for one of the unique messages (the ButtonDownFcn I point to out of two possible ButtonDownFcn). Is there a way to preserve the original function passing for ButtonDownFcn when I create the axes?

 Réponse acceptée

without seeing the actual code I can only speculate - but it sounds like the ButtonDownFcn is being removed when you replot, this happens by design when the axes nextplot property is 'replace'.
See the example below on how changing the nextplot to be 'add' alters the behaviour (note you need to clear the axes "cla" when you want to draw a new plot.
function test
f = figure;
a1 = axes ( 'parent', f, 'position', [0 0 0.5 0.5], 'ButtonDownFcn', @redrawA1 );
a2 = axes ( 'parent', f, 'position', [0.5 0.5 0.5 0.5], 'ButtonDownFcn', @redrawA2, 'nextplot', 'add' );
end
function redrawA1 ( obj, event )
disp( 'in callback A1' );
plot ( gca, rand(10), rand(10) );
end
function redrawA2 ( obj, event )
cla ( gca )
disp( 'in callback A2' );
plot ( gca, rand(10), rand(10) );
end

3 commentaires

Brian
Brian le 30 Juil 2014
Modifié(e) : Brian le 30 Juil 2014
Thanks, this helps but doesn't really solve my problem though.
With your code, I can click on a figure and disp a unique sentence: in callback A1 or A2. That I don't have a problem with, my problem is when I use a gcf callback: windowscrollWheelFcn, my axes callbacks (ButtonDownFcn) don't work anymore. Here is what I have set up in GUIDE:
function axes1_CreateFcn(hObject, eventdata, handles)
h = plot(rand(10), 'HitTest', 'Off');
set(gcf,'windowscrollWheelFcn', {@scrolldatwheel, gca});
set(gca,'ButtonDownFcn', @axes1_ButtonDownFcn);
% ----------------------------------------------------- %
function axes1_ButtonDownFcn(hObject, eventdata, handles)
disp('Axes 1')
% ----------------------------------------------------- %
function scrolldatwheel(hObject, eventdata, handles)
cla(gca);
h = plot(rand(10), 'HitTest', 'Off');
set(gcf, 'HitTest', 'Off');
In addition:
function axes2_CreateFcn(hObject, eventdata, handles)
h = plot(rand(10), 'HitTest', 'Off');
set(gcf,'windowscrollWheelFcn', {@scrolldatwheel, gca});
set(gca,'ButtonDownFcn', @axes2_ButtonDownFcn);
with the other axes2_ButtonDownFcn printing axes 2.
WHen I use my code, I can press on either gca and the ButtonDownFcn will trigger just fine: I can print either message. However, when I scroll on my mouse, suddenly ButtonDownFcn never triggers anymore. The windowscrollWheelFcn works just fine all the way through, but for some reason the ButtonDownFcn for either axes doesn't work anymore.
Any ideas for this one?
Change the nextplot property of you axes. Thats what I was demonstrating.
When you re-issue a plot command your callback is being removed (i.e. in your scroll callback you have a plot command -> deleted buttondownfcn callback to the current axes)
Oh. Thanks! That made it work perfectly.
What I did was change my CreateFcn to include:
function axes1_CreateFcn(hObject, eventdata, handles)
h = plot(rand(10), 'HitTest', 'Off');
set(gcf,'windowscrollWheelFcn', {@scrolldatwheel, gca}, 'nextplot', 'add');
set(gca,'ButtonDownFcn', @axes1_ButtonDownFcn, 'nextplot', 'add');
And it worked. Thank you very much, this was a persisting problem in my GUI.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by