Re: cvs: php-gtk-doc /examples/tutorials/signals custom.phpw multiple.phpw simple.phpw /manual tutorials.xml /manual/en/tutorials signals.xml
| From: | Scott Mattocks | Date: | Fri, 31 Mar 2006 18:21:09 +0000 |
| Subject: | Re: cvs: php-gtk-doc /examples/tutorials/signals custom.phpw multiple.phpw simple.phpw /manual tutorials.xml /manual/en/tutorials signals.xml | ||
| References: | 1 | Groups: | php.gtk.doc |
| Request: | Send a blank email to php-gtk-doc+get-2055@lists.php.net to get a copy of this message | ||
Hi Anant,
This is a good start but I have a few comments. Sorry if I sound picky but this is a very important topic. Plus I have been doing peer reviews all day so I am in a picky mood :)
Anant Narayanan wrote:
$win->connect_simple("destroy", array('gtk', 'main_quit'));Please use single quotes whenever possible ('destroy' not "destroy") and use Gtk not gtk.
<para>You define four terms.First, it will be useful to define three terms that we will use frequently.</para>
<para>
<itemizedlist>
<listitem>
Action: This is something that occurs. For example, the user clicking on a
button counts as an action.
</listitem>
I think you should use the term event here. It is the standard term used to describe what you are talking about.
<listitem>
Callback: This is where you get to handle a signal. A callback is just a
function that defines what happens when a particular signal is emitted.
</listitem>
A callback is a function or method normally called by some other piece of code. A "signal handler" is a callback that is called in response to a signal being emitted.
<listitem>
Events: These are a continuous stream of impulses that communicate low-level
changes the environment of the underlying windowing system.
</listitem>
Events are things that happen (what you called actions above). They are not tied to the windowing system and do not necessarily represent changes in the environment. An event occurs when a widget is added to a container. That is all internal to PHP-GTK and has nothing to do with environmental change.
</itemizedlist> </para> <para> Signal handling basically consists of connecting a signal to its callback, and of course, writing the callback function itself. The job of generating the signal whenever an action occurs is taken care by PHP-GTK 2. Another important thing to note is that it is not necessary for an action to occur to generate a signal. It is possible to manually generate a signal, and PHP-GTK 2 generates signals internally all the time. </para>Signals are indications that an event has occurred. They may not be generated by the user but they still indicate that something has happened.
<para> A common instance of a signal being internally generated and used is when <classname>GtkAdjustment</classname> emits the <signalname class="GtkAdjustment">value-changed</signalname> for a <classname>GtkProgressBar</classname> to use it. Hence, most signals have a default handler already inbuilt, which will be executed whether or not you manually connect a callback to that signal. </para> </sect1>I wouldn't say "most signals". Usually if you want something to happen when a signal is emitted, you need to create a signal handler for it.
<para> An important concept to know here is that it is possible to emit a signal without an action taking place at all. All widgets have functions that will emit a particular signal when you use them, irrespective of whether the user has actually performed an action or not. An example of such a function is the <function class="GtkButton">clicked</function> method of <classname>GtkButton</classname>, which will emit the <literal>clicked</literal> signal for the button. </para> </sect1>It is not safe to say "it is possible to emit a signal without an action taking place at all." A signal may be emitted without a user initiated action but something must occur for the signal to be emitted. The event may be a method call but that is still something. Also, not all widgets have functions that will emit a signal. GtkLabel does not have any methods for emitting its signals.
<sect1 id="tutorials.signals.callbacks"> <title>Callbacks</title> <note> Callbacks are functions that are executed when signals are emitted by widgets. </note>Callbacks can be methods and are not tied to signals. Signal handlers are called in response to a signal being emitted. Please use signal handler throughout this section.
<para> Callbacks are also known as signal handler functions. Callbacks are of two kinds: <literal>default handlers</literal> and <literal>user-defined handlers</literal>. The <literal>default handlers</literal> are called automatically on receipt of their corresponding signals. <literal>Default handlers</literal> on the other hand have to be explicitly <emphasis>connected</emphasis> to signals by the programmer (that's you!). </para> </sect1>You have default handlers twice. The second one should be user-defined.
<note> The *_after methods are used if you want your callback to be invoked <emphasis>after</emphasis> the default handler. We will be discussing only the <literal>connect_simple</literal> and <literal>connect</literal> methods. The respective *_after methods behave in the same way except for the fact that the callback is guaranteed to be invoked only after the <literal>default handler</literal> has. </note>Signal handlers are called in the order they are defined. Sometimes it is not possible to know when a signal handler will be called because of the order a program executes and the signal handlers are created. The *_after methods force a given signal handler to be called after the signal handlers created with connect or connect_simple. This allows signal handlers to be grouped into two batches. The second batch will always be called after the first batch (unless one of the first batch signal handlers return true in which case no more singal handers will be called for the current signal).
<para> There are two more methods: <literal>connect_object</literal> and <literal>connect_object_after</literal>, but they are deprecated and provide no additional functionality. It is highly recommended that you use the above mentioned methods instead, in your PHP-GTK 2 programs. </para>I don't think you should even mention connect_object*. I haven't had a chance to go through the rest yet. I will try to get to it a little later. Thanks, -- Scott Mattocks Author of the soon to be published: Pro PHP-GTK http://www.crisscott.com