File: Callbacks.html

package info (click to toggle)
octave 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 124,192 kB
  • sloc: cpp: 322,665; ansic: 68,088; fortran: 20,980; objc: 8,121; sh: 7,719; yacc: 4,266; lex: 4,123; perl: 1,530; java: 1,366; awk: 1,257; makefile: 424; xml: 147
file content (199 lines) | stat: -rw-r--r-- 8,900 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Callbacks (GNU Octave (version 6.2.0))</title>

<meta name="description" content="Callbacks (GNU Octave (version 6.2.0))">
<meta name="keywords" content="Callbacks (GNU Octave (version 6.2.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Advanced-Plotting.html" rel="up" title="Advanced Plotting">
<link href="Application_002ddefined-Data.html" rel="next" title="Application-defined Data">
<link href="Marker-Styles.html" rel="prev" title="Marker Styles">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<span id="Callbacks"></span><div class="header">
<p>
Next: <a href="Application_002ddefined-Data.html" accesskey="n" rel="next">Application-defined Data</a>, Previous: <a href="Marker-Styles.html" accesskey="p" rel="prev">Marker Styles</a>, Up: <a href="Advanced-Plotting.html" accesskey="u" rel="up">Advanced Plotting</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Callbacks-1"></span><h4 class="subsection">15.4.4 Callbacks</h4>
<span id="index-callbacks"></span>

<p>Callback functions can be associated with graphics objects and triggered
after certain events occur.  The basic structure of all callback function
is
</p>
<div class="example">
<pre class="example">function mycallback (hsrc, evt)
  &hellip;
endfunction
</pre></div>

<p>where <code>hsrc</code> is a handle to the source of the callback, and <code>evt</code>
gives some event specific data.
</p>
<p>The function can be provided as a function handle to a plain Octave function,
as an anonymous function, or as a string representing an Octave command.  The
latter syntax is not recommended since syntax errors will only occur when the
string is evaluated.
See <a href="Function-Handles-and-Anonymous-Functions.html">Function Handles section</a>.
</p>
<p>This can then be associated with an object either at the object&rsquo;s creation, or
later with the <code>set</code> function.  For example,
</p>
<div class="example">
<pre class="example">plot (x, &quot;DeleteFcn&quot;, @(h, e) disp (&quot;Window Deleted&quot;))
</pre></div>

<p>where at the moment that the plot is deleted, the message
<code>&quot;Window Deleted&quot;</code> will be displayed.
</p>
<p>Additional user arguments can be passed to callback functions, and will be
passed after the two default arguments.  For example:
</p>
<div class="example">
<pre class="example">plot (x, &quot;DeleteFcn&quot;, {@mycallback, &quot;1&quot;})
&hellip;
function mycallback (h, evt, arg1)
  fprintf (&quot;Closing plot %d\n&quot;, arg1);
endfunction
</pre></div>

<p><strong>Caution:</strong> The second argument in callback functions&mdash;<code>evt</code>&mdash;is
only partially implemented in the Qt graphics toolkit:
</p>
<ul>
<li> Mouse click events:
<code>evt</code> is a class <code>double</code> value: 1 for left, 2 for middle, and 3 for
right click.

</li><li> Key press events:
<code>evt</code> is a structure with fields <code>Key</code> (string), <code>Character</code>
(string), and <code>Modifier</code> (cell array of strings).

</li><li> Other events:
<code>evt</code> is a class <code>double</code> empty matrix.
</li></ul>

<p>The basic callback functions that are available for all graphics objects are
</p>
<ul>
<li> CreateFcn:
called at the moment of the objects creation.  It is not called if the
object is altered in any way, and so it only makes sense to define this
callback in the function call that defines the object.  Callbacks that
are added to <code>CreateFcn</code> later with the <code>set</code> function will
never be executed.

</li><li> DeleteFcn:
called at the moment an object is deleted.

</li><li> ButtonDownFcn:
called if a mouse button is pressed while the pointer is over this
object.  Note, that the gnuplot interface does not implement this
callback.
</li></ul>

<p>By default callback functions are queued (they are executed one after the other
in the event queue) unless the <code>drawnow</code>, <code>figure</code>, <code>waitfor</code>,
<code>getframe</code>, or <code>pause</code> functions are used.  If an executing callback
invokes one of those functions, it causes Octave to flush the event queue,
which results in the executing callback being interrupted.
</p>
<p>It is possible to specify that an object&rsquo;s callbacks should not be interrupted
by setting the object&rsquo;s <code>interruptible</code> property to <code>&quot;off&quot;</code>.  In
this case, Octave decides what to do based on the <code>busyaction</code> property of
the <strong>interrupting</strong> callback object:
</p>
<dl compact="compact">
<dt><code>queue</code> (the default)</dt>
<dd><p>The interrupting callback is executed after the executing callback has
returned.
</p>
</dd>
<dt><code>cancel</code></dt>
<dd><p>The interrupting callback is discarded.
</p></dd>
</dl>

<p>The <code>interruptible</code> property has no effect when the interrupting callback
is a <code>deletefcn</code>, or a figure <code>resizefcn</code> or <code>closerequestfcn</code>.
Those callbacks always interrupt the executing callback.
</p>
<p>The handle to the object that holds the callback being executed can be
obtained with the <code>gcbo</code> function.  The handle to the ancestor figure
of this object may be obtained using the <code>gcbf</code> function.
</p>
<span id="XREFgcbo"></span><dl>
<dt id="index-gcbo">: <em><var>h</var> =</em> <strong>gcbo</strong> <em>()</em></dt>
<dt id="index-gcbo-1">: <em>[<var>h</var>, <var>fig</var>] =</em> <strong>gcbo</strong> <em>()</em></dt>
<dd><p>Return a handle to the object whose callback is currently executing.
</p>
<p>If no callback is executing, this function returns the empty matrix.  This
handle is obtained from the root object property <code>&quot;CallbackObject&quot;</code>.
</p>
<p>When called with a second output argument, return the handle of the figure
containing the object whose callback is currently executing.  If no callback
is executing the second output is also set to the empty matrix.
</p>

<p><strong>See also:</strong> <a href="#XREFgcbf">gcbf</a>, <a href="Graphics-Objects.html#XREFgco">gco</a>, <a href="Graphics-Objects.html#XREFgca">gca</a>, <a href="Graphics-Objects.html#XREFgcf">gcf</a>, <a href="Graphics-Objects.html#XREFget">get</a>, <a href="Graphics-Objects.html#XREFset">set</a>.
</p></dd></dl>


<span id="XREFgcbf"></span><dl>
<dt id="index-gcbf">: <em><var>fig</var> =</em> <strong>gcbf</strong> <em>()</em></dt>
<dd><p>Return a handle to the figure containing the object whose callback is
currently executing.
</p>
<p>If no callback is executing, this function returns the empty matrix.  The
handle returned by this function is the same as the second output argument
of <code>gcbo</code>.
</p>

<p><strong>See also:</strong> <a href="#XREFgcbo">gcbo</a>, <a href="Graphics-Objects.html#XREFgcf">gcf</a>, <a href="Graphics-Objects.html#XREFgco">gco</a>, <a href="Graphics-Objects.html#XREFgca">gca</a>, <a href="Graphics-Objects.html#XREFget">get</a>, <a href="Graphics-Objects.html#XREFset">set</a>.
</p></dd></dl>


<p>Callbacks can equally be added to properties with the <code>addlistener</code>
function described below.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Application_002ddefined-Data.html" accesskey="n" rel="next">Application-defined Data</a>, Previous: <a href="Marker-Styles.html" accesskey="p" rel="prev">Marker Styles</a>, Up: <a href="Advanced-Plotting.html" accesskey="u" rel="up">Advanced Plotting</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>