Gtk2::GladeXML — Perl bindings for libglade

Connecting signals

There are two ways of connecting signals in Gtk2::GladeXML--the standard Gtk2-Perl way and the Gtk2::GladeXML way. Using the Gtk2::GladeXML way consists of calling signal_autoconnect_from_package after specifying the signals and handlers in the .glade file (handlers are just another name for callback functions). There are three caveats to using this method: the callback functions must be within a package namespace (not that big a deal, it just needs to be remembered), there are no predefined helper functions such as gtk_main_quit (though these are easy to define), and it makes passing extra or different parameters to the function more difficult. (As with libglade, only a single parameter can be passed to such callbacks, and it must be another widget in the .glade file).

The second way, the Gtk2-Perl way, is to manually connect a function to the appropriate signal for the appropriate wiget, via use of the signal_connect function. The specified callback function can even be an anonymous subroutine, which can be handy for short and simple callbacks.