Re: Display Portions of an Image




On Monday, July 28, 2003, at 06:25 PM, Jörn Reder wrote:

Also the return value of signal callbacks are important. Returning true
indicates that the signal was handled finally and no other signal
handlers will be called

note that not all callbacks are expected to return values, and not all of those that do are expected to return boolean status. it is mostly event handlers (e.g., callbacks that receive a GdkEvent structure) that follow the "return true if you handled it" convention. things like "clicked" on a button do not.

also, the actual semantics of how signal emission stops are a little more complicated than that, and changed between gtk 1.x and 2.x. see the Glib API reference and whatever tutorial info you can find for details.


(only important in case there is more than one
handler connected to the signal, which is not unusal). If you have
"strange" behaviour on the GUI, check your return values. They are
important and you need them! ;)

the C function call signature expected for each callback is documented in the "Signal Prototypes" section of each object's page in the C API reference[1], and you can translate this to what to expect for a perl signal handler quite easily. here are a few examples, for any of you who don't understand C very well:

Gtk2::Dialog's "response" signal:
Gtk2::Dialog in perl is GtkDialog in C. under the signal prototypes heading of http://developer.gnome.org/doc/API/2.0/gtk/GtkDialog.html you'll see

"response" void user_function (GtkDialog *dialog,
gint arg1,
gpointer user_data);

if you don't know a C prototype, it basically has the form

return_type function_name (arg_type arg_name, arg_type arg_name, ...);

thus, for response, we see void as the return type, which is C for "doesn't return anything". the first argument is a pointer to a GtkDialog; in perl this will be a Gtk2::Dialog reference. the second parameter is a gint, which is glib-ese for "int", which is an integer; it says "arg1", but this is really the response code. to add more confusion, the response types are an enum (a set of string values in perl) *and* and integer. this parameter's declaration as gint explains why you get -5 instead of 'ok' in the "response" callback. the last parameter is declared as a gpointer; this is glib-ese for "void*", which is C for "a pointer to any type of value", or a generic pointer value to be interpreted as you see fit. in perl, this will be whatever scalar value you passed as user data when you connected the signal. if you don't attach anything, this parameter won't exist.

Gtk2::Widget's button-press-event:
"button-press-event" gboolean user_function (GtkWidget *widget,

GdkEventButton *event,

gpointer user_data);


this is what happens when the user presses a mouse button inside a widget's boundary. the callback is expected to return a boolean value: http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-button-press-event tells us that if you return TRUE, the event stops being processed.

there, now you've seen it all. :-)

[1] as always, http://developer.gnome.org/doc/API/

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]