Next: , Previous: Using objects, Up: GObject high-level


10.5 Signals

To connect handler to a signal, connect-signal function is used. Function disconnect-signal removes the connected signal.

— Function: connect-signal
     (connect-signal object signal handler &key after) => handler-id
object
An instance of GObject object
signal
A signal name
handler
A function
after
A boolean specifying whether the handler should be called after the default handler
handler-id
An integer - identifier of signal handler; can be used to disconnect the signal handler with disconnect-signal

Connects the handler to signal signal on object object. Signature of handler should comply with signature of a signal. handler will be called with arguments of type specified by signal with the object (on which the signal was emitted) prepended to them and it should return the value of the signal's return type.

— Function: disconnect-signal
     (disconnect-signal object handler-id)

Disconnects the signal handler identified by handler-id from the corresponding signal for object. handler-id is the integer identifying the signal handler; connect-signal returns handler identifiers.

Example:

     (defvar *d* (make-instance 'gtk:dialog))
     =>
     *D*
     
     *d*
     =>
     #<GTK:DIALOG {1002D866F1}>
     
     (parse-signal-name "GtkDialog" "response")
     =>
     #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
     
     (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
     
     (emit-signal *d* "response" 14)
     =>
     ;; Prints:
     #<GTK:DIALOG {1002D866F1}>
     14

Function emit-signal is used to emit signals on objects.

— Function: emit-signal

(emit-signal object signal-name &rest args) => return-value

object
An object on which the signal should be emitted
signal-name
A string naming the signal
args
Arguments for a signal
return-value
Return value of a signal

Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from emit-signal.

Example:

     (defvar *d* (make-instance 'gtk:dialog))
     =>
     *D*
     
     *d*
     =>
     #<GTK:DIALOG {1002D866F1}>
     
     (parse-signal-name "GtkDialog" "response")
     =>
     #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
     
     (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
     
     (emit-signal *d* "response" 14)
     =>
     ;; Prints:
     #<GTK:DIALOG {1002D866F1}>
     14