[pygtk] what difference is between "Signal" and "Event"
jdennis at redhat.com
Tue Dec 18 06:42:29 WST 2007
Steven Brown wrote:
> Hmm, this bothered me before... from the top of my head:
> An event is higher level. GTK?
> A signal is lower level. GDK?
> An event is often a collection of signals and certain conditions. A
> button emits a "clicked" event when the mouse button is clicked (down,
> not moved off the button, and then up). The mouse-down would be a signal.
> OR... the Mouse-down event fires the Mouse-down signal. The difference
> here would be the user causes events, which emit signals, which are
> handled by the application. But the application can fire signals
> itself, without user input.
> I think the terms are often used interchangably.
> Anyone, please correct any false information. :)
I've got to jump in here, this is wildly inaccurate misinformation.
I don't have the time to write a full explanation, but here is the one
minute version. Signals and events have no particular relationship.
A signal is nothing other than a fancy callback mechanism. It's a way
for one object to register it's interest in being notified of another
objects action or state change. You register your interest by providing
a callback, when the object "emits a signal" it simply iterates over the
list of callbacks which have been registered with it and calls the
callback passing some predefined data with it.
An event is an almost one-to-one mapping of window system events. Window
system events are things like "key press" or "window move". Window
system events are reported to the applications main loop. GDK/GTK
interprets the window system events passes them along to you. What
better way to do that other than via signals!
Signals are very general. You can create your own, it's very useful. Any
object can create and emit signals, it's very powerful. In and of itself
signals have no relationship to events other than one of the many many
uses of signals is to communicate window system events.
FWIW, I never liked the term "signal" it's way too overloaded with other
meanings, callback would have been a better name. I suspect it was named
signal in the first place because it's a mechanism for one object to
"signal" an other object something has happened.
John Dennis <jdennis at redhat.com>
More information about the pygtk