From: Jeffrey Moffitt on
Hi,

I am currently trying to dynamically change the KeyPressFcn and WindowButtonDownFcn in a figure. I have a main figure with one set of callback functions. When a specific key is pressed, the figure handle is passed to a separate function which changes these callback functions. When execution is returned to the original function, the callback functions are changed back to their original values.

I delay the execution of both programs by invoking waitforbuttonpress. This allows the user to dynamically control when control of the figure is returned to the original function by pressing a specific key.

In Matlab r2008a this works fine, but I have recently ported this code to matlab r2009a, and I am having problems. The original callback functions work properly, but when execution is passed to the second program, the callback functions are unresponsive. I have confirmed that the callback functions are actually changed, but they no longer appear to be executed when a key is pressed or there is a mouse click in the figure.

Does anyone have any suggestions?
From: Karsten Joensen on
Hi Jeffrey,

I have had a similar observation porting my code from 2008a to 2010a and have not found a satisfying solution or even an explanation.

In my case I was able to work out a hack by changing my code from

set(gcf,'WindowButtonDownFcn','create_poly_wbdf')
while kk==0
kk=waitforbuttonpress;
if (kk==1)
% we have keyboard press
else
% we have mouse press and can act on what happened in
% create_poly_wbdf after the button press
end
end
to the following

%set(gcf,'WindowButtonDownFcn','create_poly_wbdf')
while kk==0
kk=waitforbuttonpress;
% this was included on March 16 since there was trouble
% with the WindowButtonDownFcn being called. So now we call
% it explicitly if there is a left-mouse click i.e. normal
if kk==0 && strcmp(get(gcf,'Selectiontype'),'normal')
create_poly_wbdf
%now we can further act on it
end
if (kk==1)
%there was a keyboard hit
end
end

This seems to work for me..for now..but I am not happy about this functionality disappearing. Especially since in other parts of the code it works perfectly.



"Jeffrey Moffitt" <jeffmoffitt(a)hotmail.com> wrote in message <hm0ovh$akv$1(a)fred.mathworks.com>...
> Hi,
>
> I am currently trying to dynamically change the KeyPressFcn and WindowButtonDownFcn in a figure. I have a main figure with one set of callback functions. When a specific key is pressed, the figure handle is passed to a separate function which changes these callback functions. When execution is returned to the original function, the callback functions are changed back to their original values.
>
> I delay the execution of both programs by invoking waitforbuttonpress. This allows the user to dynamically control when control of the figure is returned to the original function by pressing a specific key.
>
> In Matlab r2008a this works fine, but I have recently ported this code to matlab r2009a, and I am having problems. The original callback functions work properly, but when execution is passed to the second program, the callback functions are unresponsive. I have confirmed that the callback functions are actually changed, but they no longer appear to be executed when a key is pressed or there is a mouse click in the figure.
>
> Does anyone have any suggestions?
From: Etienne Balmes on
Just to add a little more info on this bug which does not make sense. Which we reproduce on windows and linux starting Matlab >= 2009a

In our case, a callback dynamically changes the
'WindowButtonDownFcn' of a second figure (the calling uicontrol is not in the figure whos 'WindowButtonDownFcn' is changed) and the freezing of all callbacks of HG elements except UICONTROLS happens in the figure of the calling uicontrol.
From: Etienne Balmes on
Note that there seems to be a bug report on the issue but no workaround

http://www.mathworks.com/support/bugreports/517438