|
In addition to the signal mechanism described above, there is a set of events that reflect the X event mechanism. Callbacks may also be attached to these events. These events are:
In order to connect a callback function to one of these events you use the method connect() , as described above, using one of the above event names as the name parameter. The callback function (or method) for events has a slightly different form than that for signals:
GdkEvent is a python object type whose type attribute will indicate which of the above events has occurred. The other attributes of the event will depend upon the type of the event. Possible values for the types are:
These values are accessed by prefacing the event type with gtk.gdk. for example gtk.gdk.DRAG_ENTER. So, to connect a callback function to one of these events we would use something like:
This assumes that button is a GtkButton widget. Now, when the mouse is over the button and a mouse button is pressed, the function button_press_callback will be called. This function may be defined as:
The value returned from this function indicates whether the event should be propagated further by the GTK+ event handling mechanism. Returning True indicates that the event has been handled, and that it should not propagate further. Returning False continues the normal event handling. See Chapter 20, Advanced Event and Signal Handling for more details on this propagation process. The GDK selection and drag-and-drop APIs also emit a number of events which are reflected in GTK+ by signals. See Section 22.3.2, “Signals On the Source Widget” and Section 22.3.4, “Signals On the Destination Widget” for details on the signatures of the callback functions for these signals:
|