Glade and Events

Creating signals in Glade

Now that we know what signals are and how to connect them, we need to know how to handle them, and more specifically which ones we need to handle for each case. Luckily, Glade provides a mechanism for creating signal handlers for all of the gtk signals, which means we don't have to memorize them all. However, you still need to know what signal's are produced for what actions, and although most of the names are pretty self explanatory, there are some places that you can get caught.

So, going back to glade now, make the "app" window visible by double clicking it in the glade project's window (if its not open already). Right click on the window, and from the app1 submenu, select "select". The properties window should have changed to signify that it is now displaying the properties of the whole application widget (remember, we made a gnome_application_window, not a regular window). Switch over to the signals tab in the properties window, and lets add a "destroy signal" to our application. Click on the elipsis ('...') button to get a list of signals, and down in the gtkObject section, double click the "destroy" option.

Destroy Signal

The default name for the signal handler is fine (for now; later we will follow a naming convention for signals and handling functions that makes it a little easier to see what is going on in the code). Before we create a signal handler back in our code, add the signal by clicking "add" and save the glade project, and I'll go on a small aside about some of the more important/used signals.

Delete Signals

The delete signal is the signal passed by the window manager when a window is closed. The return code of the delete signal handler is a boolean; if gtk.true is returned, the destroy signal won't be sent; if gtk.false is sent, the destroy signal will be sent.

Destroy Signals

The destroy signal is sent when a delete signal is sent and the delete signal handler returns false. The destroy signal can be used for a few purposes; the first and most obvious use is to exit the program cleanly. Upon delete being called on the main app window, call destroy and then exit the gtk main loop via gtk.main_quit().

Optionally, the destroy signal handler can simply destroy the current window to remove it from memory. Since we'll be using libglade, we won't really have this option, since libglade will be handling all of the gtk objects that we're creating. However, in a larger project where libglade is not used, it could be useful to free up some memory by destroying the objects that make up more complicated

On Clicked Signals

The on clicked signal is sent when a button is clicked. Anything can go in the handler, but it's an important signal to know as your program won't be of much use without it.

Activate Signals

The activate signal is sent when a menu item is clicked. Like the on clicked signal, the handler is up to you, and it is equally important to utilize as menu's are perhaps the most important part of your program's UI.

back to Signals Events | First Signal Handler
up to the index