Mercurial > hg > octave-nkf
comparison scripts/plot/uiwait.m @ 13924:3b654a0753b1
Implement waitfor, uiwait and uiresume.
* liboctave/cmd-edit.h (command_editor::run_event_hooks): New static method.
* liboctave/cmd-edit.cc (command_editor::run_event_hooks): Implement it.
* src/graphics.h.in (listener_mode::PREDELETE): New enum value.
* src/graphics.cc (<ctime>, "cutils.h"): New included headers.
(base_properties::has_dynamic_properties): Look also into all_props.
(gh_manager::do_execute_callback): Allow any type of function to be specified,
not only function handles.
(waitfor_results): New utility static variable.
(compare_property_values, cleanup_waitfor_id, do_cleanup_waitfor_listener,
cleanup_waitfor_postset_listener, cleanup_waitfor_predelete_listener,
waitfor_listener, waitfor_del_listener): New utility static functions.
(Fwaitfor): New function.
* plot/uiwait.m: New function.
* plot/uiresume.m: Likewise.
* plot/modules.mk (plot_FCN_FILES): Add them to the list.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Wed, 23 Nov 2011 08:59:25 +0000 |
parents | |
children | 9cae456085c2 |
comparison
equal
deleted
inserted
replaced
13923:7b83576b3b48 | 13924:3b654a0753b1 |
---|---|
1 ## Copyright (C) 2011 Michael Goffioul | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} uiwait | |
21 ## @deftypefnx {Function File} uiwait (@var{h}) | |
22 ## @deftypefnx {Function File} uiwait (@var{h}, @var{timeout}) | |
23 ## Suspends program execution until the figure with handle @var{h} is | |
24 ## deleted or @code{uiresume} is called. When no figure handle is specified, | |
25 ## this function uses the current figure. | |
26 ## | |
27 ## If the figure handle is invalid or there is no current figure, this | |
28 ## functions returns immediately. | |
29 ## | |
30 ## When specified, @var{timeout} defines the number of seconds to wait | |
31 ## for the figure deletion or the @code{uiresume} call. The timeout value | |
32 ## must be at least 1. If a smaller value is specified, a warning is issued | |
33 ## and a timeout value of 1 is used instead. If a non integer value is | |
34 ## specified, it is truncated towards 0. If @var{timeout} is not specified, | |
35 ## the program execution is suspended indefinitely. | |
36 ## @seealso{uiresume, waitfor} | |
37 ## @end deftypefn | |
38 | |
39 ## Author: goffioul | |
40 | |
41 function uiwait (varargin) | |
42 | |
43 h = []; | |
44 timeout = []; | |
45 | |
46 if (nargin == 0) | |
47 h = get (0, "currentfigure"); | |
48 else | |
49 h = varargin{1}; | |
50 if (! ishandle (h) || ! strcmp (get (h, "type"), "figure")) | |
51 error ("uiwait: invalid figure handle"); | |
52 endif | |
53 if (nargin > 1) | |
54 timeout = varargin{2}; | |
55 endif | |
56 endif | |
57 | |
58 if (! isempty (h)) | |
59 unwind_protect | |
60 try | |
61 addproperty ("__uiwait_state__", h, "radio", "none|{active}|triggered"); | |
62 catch | |
63 if (! strcmp (get (h, "__uiwait_state__"), "none")) | |
64 error ("uiwait: an active uiwait call for this figure already exists"); | |
65 endif | |
66 set (h, "__uiwait_state__", "active"); | |
67 end_try_catch | |
68 waitfor_args = {h, "__uiwait_state__", "triggered"}; | |
69 if (! isempty (timeout)) | |
70 waitfor_args(end+1:end+2) = {"timeout", timeout}; | |
71 endif | |
72 waitfor (waitfor_args{:}); | |
73 unwind_protect_cleanup | |
74 if (ishandle (h) && isprop (h, "__uiwait_state__")) | |
75 set (h, "__uiwait_state__", "none"); | |
76 endif | |
77 end_unwind_protect | |
78 endif | |
79 | |
80 endfunction |