Invoke a callback progammatically without interrupting the current callback.

5 views (last 30 days)
I'm trying to call callback_A from callback_B (same GUI). Callback_A contains a simple while loop that that gets interrupted just fine if it is called by clicking its button. However when I call callback_A from inside callback_B like so,
pollBtn_callback(ud.fig.pollBtn,[])
callback_B does not exit until I kill the loop. I tried changing the 'Interruptible' property of callback_B's object to 'off' but the behavior does not change.
How can I call callback_A so that, similar to if the button is clicked, callback_B will finish then callback_A will execute?

Answers (1)

Walter Roberson
Walter Roberson on 19 Oct 2016
Leave the callback set to Interruptible and Busy Action set to Queue, which are the defaults. But in callback A, you need to call one of drawnow() or pause() or uiwait() or waitfor() or figure() in order for the graphics queue to be processed to allow the push button to interrupt.
  2 Comments
Clint Cass
Clint Cass on 20 Oct 2016
Thanks for the reply. What you described is how it currently works, but I do not want callback_A to interrupt interrupt callback_B. callback_A is a loop that I want to run while the gui is open and get interrupted by other callbacks, which works. I would like to start this loop as a callback either when the gui opens or from a separate callback.
However I know that if I just call it as a nested function, say from another button, it will not give up control of that button.
I'm wondering if there is a way to invoke a callback as if it's button were clicked so that it follows the interruption rules.
Thanks!
Walter Roberson
Walter Roberson on 20 Oct 2016
You want a button to be able to interrupt the function of callback_A when the function is called from a callback_B that is being run because the user clicked on something for which callback_B is the callback. The callback_B -> callback_A chain is interruptable by graphics events if the graphics object that calls callback_B is set for Queue and Interruptable and callback_A is using drawnow() or pause() to give opportunities for the queue to be serviced.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!