[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Catching Figure close button - callbacks not running?

From: Richardson, Anthony
Subject: RE: Catching Figure close button - callbacks not running?
Date: Tue, 29 Jan 2019 19:31:20 +0000

> -----Original Message-----
> From: pavel <address@hidden>
> Sent: Tuesday, January 29, 2019 1:22 PM
> To: Richardson, Anthony <address@hidden>; address@hidden
> Subject: Re: Catching Figure close button - callbacks not running?
> Hi Tony,
> Dne 29. 01. 19 v 19:19 Richardson, Anthony napsal(a):
> >
> > Define a callback for the 'DeleteFcn' property of the current figure
> > window (or a handle returned by the figure() function):
> >
> >     set(gcf, 'DeleteFcn', @(h, e) mycallback(h, e))
> >
> > The callback will be run when the window is pressed.
> >
> > Here is a simple (specific) example.  Enter at the command prompt:
> >
> >     set(gct, 'DeleteFcn' @(h, e) disp('bye bye'))
> >
> Thanks a lot! This is what I was looking for, works great.
> There was another problem - I did not call drawnow() in the infinite reading
> the messages. Took me a while to learn that the UI code is single-threaded
> and drawnow executes the queued callbacks.
> Since my callbacks use a lot of pauses and take several secs each, I must
> either run them in a different thread (parallel?) or rewrite the code to run
> the callbacks code interleaved with reading the messages. I wonder if people
> face the same issue and how they tackle it.
> Please do you have any idea how to catch the Ctrl+C command from IDE
> command window so that the figure can be closed automatically when
> forced-stopping the script  in IDE?
> I very much appreciate your advice and help.
> Best regards,
> Pavel.

I *think* the callbacks are run when the event occurs.  That is consistent with 
my experience anyway. It's just that the figure window is not updated until 
drawnow() is run.

It looks as if the onCleanup() function ('help onCleanup') may allow you to 
hook Ctrl+C.  Not sure though, I haven't tried it myself.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]