manpagez: man pages & more
info octave
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15.2.7 Callbacks

Callback functions can be associated with graphics objects and triggered after certain events occur. The basic structure of all callback function is

 
function mycallback (src, data)
…
endfunction

where src gives a handle to the source of the callback, and code gives some event specific data. This can then be associated with an object either at the objects creation or later with the set function. For example

 
plot (x, "DeleteFcn", @(s, e) disp("Window Deleted"))

where at the moment that the plot is deleted, the message "Window Deleted" will be displayed.

Additional user arguments can be passed to callback functions, and will be passed after the 2 default arguments. For example

 
plot (x, "DeleteFcn", {@mycallback, "1"})
…
function mycallback (src, data, a1)
  fprintf ("Closing plot %d\n", a1);
endfunction

The basic callback functions that are available for all graphics objects are

The object and figure that the event occurred in that resulted in the callback being called can be found with the gcbo and gcbf functions.

Function File: h = gcbo ()
Function File: [h, fig] = gcbo ()

Return a handle to the object whose callback is currently executing. If no callback is executing, this function returns the empty matrix. This handle is obtained from the root object property "CallbackObject".

Additionally 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.

See also: gcf, gca, gcbf.

Function File: fig = gcbf ()

Return a handle to the figure containing the object whose callback is currently executing. 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 gcbo.

See also: gcf, gca, gcbo.

Callbacks can equally be added to properties with the addlistener function described below.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2017
Individual documents may contain additional copyright information.