Mercurial > hg > octave-nkf
changeset 20407:2283dd03bf50
ginput.m: Don't hang if window is close while fcn active (bug #44897).
* ginput.m: Change closerequestfcn for figure to point to ginput_closerequestfcn.
* ginput.m (ginput_closerequestfcn): New callback routine. Stops collecting
data for ginput. Calls original closerequestfcn to shutdown window.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 15 May 2015 16:51:57 -0700 |
parents | 10414d7a25f8 |
children | 5fb4bc5f70ce |
files | scripts/plot/util/ginput.m |
diffstat | 1 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/ginput.m +++ b/scripts/plot/util/ginput.m @@ -69,12 +69,15 @@ ginput_accumulator (0, 0, 0, 0); # initialize accumulator orig_windowbuttondownfcn = get (fig, "windowbuttondownfcn"); - orig_ginput_keypressfcn = get (fig, "keypressfcn"); + orig_keypressfcn = get (fig, "keypressfcn"); + orig_closerequestfcn = get (fig, "closerequestfcn"); unwind_protect set (fig, "windowbuttondownfcn", @ginput_windowbuttondownfcn); set (fig, "keypressfcn", @ginput_keypressfcn); + set (fig, "closerequestfcn", {@ginput_closerequestfcn, + orig_closerequestfcn}); do if (strcmp (toolkit, "fltk")) @@ -95,8 +98,11 @@ endif unwind_protect_cleanup - set (fig, "windowbuttondownfcn", orig_windowbuttondownfcn); - set (fig, "keypressfcn", orig_ginput_keypressfcn); + if (isfigure (fig)) + ## Only execute if window still exists + set (fig, "windowbuttondownfcn", orig_windowbuttondownfcn); + set (fig, "keypressfcn", orig_keypressfcn); + endif end_unwind_protect varargout = {x, y, button}; @@ -123,12 +129,12 @@ endfunction -function ginput_windowbuttondownfcn (src, button) +function ginput_windowbuttondownfcn (~, button) point = get (gca (), "currentpoint"); ginput_accumulator (1, point(1,1), point(1,2), button); endfunction -function ginput_keypressfcn (src, evt) +function ginput_keypressfcn (~, evt) point = get (gca (), "currentpoint"); if (strcmp (evt.Key, "return")) ## Enter key stops ginput. @@ -141,6 +147,11 @@ endif endfunction +function ginput_closerequestfcn (hfig, ~, orig_closerequestfcn) + ginput_accumulator (2, NaN, NaN, NaN); # Stop ginput + feval (orig_closerequestfcn); # Close window with original fcn +endfunction + ## Remove from test statistics. No real tests possible. %!test