cvs: php-gtk-doc /cs/userguide/chapters signals.xml
| From: | Adam Rambousek | Date: | Sun, 21 Apr 2002 16:21:02 +0000 |
| Subject: | cvs: php-gtk-doc /cs/userguide/chapters signals.xml | ||
| Groups: | php.gtk.doc | ||
| Request: | Send a blank email to php-gtk-doc+get-517@lists.php.net to get a copy of this message | ||
rambik Sun Apr 21 12:21:02 2002 EDT
Modified files:
/php-gtk-doc/cs/userguide/chapters signals.xml
Log:
Signals completed
Index: php-gtk-doc/cs/userguide/chapters/signals.xml diff -u php-gtk-doc/cs/userguide/chapters/signals.xml:1.1 php-gtk-doc/cs/userguide/chapters/signals.xml:1.2 --- php-gtk-doc/cs/userguide/chapters/signals.xml:1.1 Sat Apr 20 12:32:23 2002 +++ php-gtk-doc/cs/userguide/chapters/signals.xml Sun Apr 21 12:21:02 2002 @@ -54,253 +54,247 @@ </sect1> <sect1 id="gtk.signal.inheritance"> - <title>Signal Inheritance</title> + <title>Dìdìní signálù</title> <simpara> - Signals are inherited by objects, just as methods are. A widget can - emit any signals that its ancestor objects have defined, as well as its - own specific signals. + Objekty dìdí signály, stejnì jako metody. Widget mù¾e vyslat jakýkoli + signál definovaný u jeho rodièe, stejnì jako své vlastní signály. </simpara> <simpara> - In cases where the signal is not relevant to the widget but is nonetheless - inherited by it, there will be no error message when the signal is called - - but equally, there will be no obvious means for the widget to emit that - particular signal. + V pøípadì, ¾e signál není u widgetu relevantní, ale je pøesto zdìdìn, + nevypí¹e se pøi zavolání signálu ¾ádná chybová zpráva - ale vyvolání + tohoto signálu se nijak neprojeví. </simpara> </sect1> <sect1 id="gtk.signals.connection"> - <title>Connecting Signals</title> + <title>Pøipojování signálù</title> <sect2 id="gtk.signals.connection.simple"> - <title>Simple Connections</title> + <title>Jednoduché pøipojení</title> <simpara> - To react to a signal you must connect to it by specifying a callback - function for PHP-GTK to call when that signal is emitted. + Aby se po vyvolání signálu nìco stalo, musíte urèit, kterou funkci tento + signál spustí. </simpara> <simpara> - Connecting a function to a signal is achieved by calling the - <function class="GtkObject">connect()</function> method of the object. + Pøipojení funkce k signálu dosáhnete zavoláním metody + <function class="GtkObject">connect()</function> objektu. </simpara> <simpara> - The function that you register as the callback for a signal must have the - correct prototype. You can find what the prototype should be from the - <link linkend="reference">reference</link> section of this manual. + Funkce, kterou zaregistrujete jako obslu¾nou pro signál, musí mít + správný prototyp. Jak by mìla být funkce konstruována, zjistíte v + <link linkend="reference">referenèní</link> èásti manuálu. </simpara> <simpara> - For example, if you wanted to connect to the - <signalname>clicked</signalname> signal of an instance of - <classname>GtkButton</classname> you should define a function that - accepts one parameter, which will be the button that was clicked. + Napøíklad kdy¾ chcete pøipojit signál + <signalname>clicked</signalname> objektu + <classname>GtkButton</classname>, mìli byste definovat funkci, která + pøijímá jeden parametr, co¾ bude oznaèení stisknutého tlaèítka. </simpara> <para> - The code below shows how you might create a window, add a button to it, - wait for it to be clicked and then, when it is clicked, open a new - <classname>GtkWindow</classname> containing a message. + Následující kód ukazuje, jak mù¾ete vytvoøit okno, pøidat do nìj + tlaèítko, poèkat, a¾ na nìj u¾ivatel klikne, a poté otevøít nové + <classname>GtkWindow</classname> se zprávou. <example> - <title>Signals and Callbacks</title> + <title>Signály a volání</title> <programlisting role="php"> -function shutdown() +function vypni() { - print("Shutting down...\n"); + print("Vypínám...\n"); gtk::main_quit(); } -function you_clicked($button) +function kliknul_jste($tlacitko) { - $window = &new GtkWindow(); - $label = &new GtkLabel("You clicked the button"); - $window->add($label); - $window->connect("destroy","shutdown"); - $window->show_all(); + $okno = &new GtkWindow(); + $popisek = &new GtkLabel("Kliknul jste na tlaèítko"); + $okno->add($popisek); + $okno->connect("destroy","vypni"); + $okno->show_all(); return false; } -$window = &new GtkWindow(); -$window->connect("destroy", "shutdown"); -$window->set_border_width(10); - -$button = &new GtkButton("Click Me!!"); -$button->connect("clicked", "you_clicked"); -$window->add($button); +$okno = &new GtkWindow(); +$okno->connect("destroy", "vypni"); +$okno->set_border_width(10); + +$tlacitko = &new GtkButton("Klikni na mì!!"); +$tlacitko->connect("clicked", "kliknul_jste"); +$okno->add($tlacitko); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting> </example> </para> <para> - The important part here is where we call + Dùle¾itá èást je volání <informalexample> - <programlisting role="php">$button->connect();</programlisting> + <programlisting role="php">$tlacitko->connect();</programlisting> </informalexample> - The connect method here registers the <literal>you_clicked()</literal> - function as the callback that will be invoked when the - <signalname>clicked</signalname> signal is emitted by the - <classname>GtkButton</classname> widget. We also register the - <literal>shutdown()</literal> function as the handler for the - <signalname>destroy</signalname> signal for both windows so that we - can shut down the application properly. + Metoda connect zde registruje funkci <literal>kliknul_jste()</literal> + jako obslu¾nou funkci, která se spustí po vyvolání signálu + <signalname>clicked</signalname> widgetu + <classname>GtkButton</classname>. Také registrujeme funkci + <literal>shutdown()</literal> jako obslu¾nou funkci signálu + <signalname>destroy</signalname> obou oken, abychom mohli aplikaci øádnì + ukonèit. </para> </sect2> <sect2 id="gtk.signals.connection.multiple"> - <title>Multiple Connections</title> + <title>Vícenásobná pøipojení</title> <simpara> - With PHP-GTK you can register more than one function to be invoked when - a signal is emitted by a widget. This allows you to set up a whole set - of functions to be called in response to an expected action. + V PHP-GTK mù¾ete k signálu zaregistrovat více ne¾ jednu funkci. To vám + umo¾òuje spustit jako odpovìï na signál celou sadu funkcí. </simpara> <para> - When more than one function is connected to a signal, the functions are - called in the order in which they were registered when that signal is - emitted. + Kdy¾ pøipojujete k signálu více funkcí, volají se funkce v poøadí, v + jakém byly zaregistrovány. <example> - <title>Signal Callback Order</title> + <title>Poøadí volání funkcí</title> <programlisting role="php"> -function first($button) +function prvni($tlacitko) { - print "First function has been called\n"; + print "Byla zavolána první funkce\n"; } -function second($button) +function druha($tlacitko) { - print "Second function has been called\n"; + print "Byla zavolána druhá funkce\n"; } -$window = &new GtkWindow(); -$window->connect_object("destroy", array("gtk", +$okno = &new GtkWindow(); +$okno->connect_object("destroy", array("gtk", "main_quit")); -$button = &new GtkButton("Click Me!!"); -$button->connect("clicked","first"); -$button->connect("clicked","second"); -$window->add($button); +$tlacitko = &new GtkButton("Klikni na mì!!"); +$tlacitko->connect("clicked","prvni"); +$tlacitko->connect("clicked","druha"); +$okno->add($tlacitko); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting> </example> - In the above example we connect two functions to a button's - <signalname>clicked</signalname> signal. The first call to the - <function class="GtkObject">connect()</function> method connects the - <signalname>clicked</signalname> signal to the <literal>first()</literal> - function, the second call connects the <signalname>clicked</signalname> - signal to the <literal>second()</literal> function. + V tomto pøíkladu pøipojíme na signál + <signalname>clicked</signalname> tlaèítka rovnou dvì funkce. První + volání metody <function class="GtkObject">connect()</function> pøipojí k + signálu <signalname>clicked</signalname> funkci + <literal>prvni()</literal> a druhé zavolání pøipojí k signálu + <signalname>clicked</signalname> funkci <literal>druha()</literal>. </para> <para> - The output from this program would be: + Výstup tohoto programu bude vypadat následovnì: <programlisting> -First function has been called. -Second function has been called. +Byla zavolána první funkce +Byla zavolána druhá funkce </programlisting> </para> </sect2> </sect1> <sect1 id="gtk.signals.custom.params"> - <title>Using Custom Parameters</title> + <title>Pou¾ívání u¾ivatelských parametrù</title> <sect2 id="gtk.signals.custom.data"> - <title>Passing Custom Data as a Parameter</title> + <title>Pøedávání u¾ivatelských dat jako parametru</title> <simpara> - When <link linkend="gtk.signals.connection">connecting</link> signals, - it is possible to add an extra custom parameter to the callback. This - is useful for passing the object you want to perform an action on, to - your callback function. + Kdy¾ <link linkend="gtk.signals.connection">pøipojujete</link> signál, + mù¾ete pøidat volané funkci vlastní parametry navíc. Toto je u¾iteèné, + potøebujete-li pøedávat volané funkci objekty ke zpracování. </simpara> <simpara> - For example, when a button is pressed we might want to destroy the parent - instance of <classname>GtkWindow</classname> that that instance of - <classname>GtkButton</classname> has been - <function class="gtkcontainer">add</function>ed to. + Napøíklad mù¾ete chtít zavøít rodièovské okno, do nìho¾ bylo pøidání + tlaèítko stisknuté u¾ivatelem. </simpara> <simpara> - You can do this by including an optional third parameter to the - <function class="GtkObject">connect()</function> call. This will then be - passed to your signal handler function as the final callback parameter. + Toho dosáhnete tak, ¾e k volání + <function class="GtkObject">connect()</function> pøidáte tøetí nepovinný + parametr. Tento bude pøedán obslu¾né funkci jako dal¹í parametr. </simpara> <para> <example> <title> - Using Custom Parameters with the - <function class="GtkObject">connect()</function> method. + Pou¾ívání u¾ivatelských parametrù s metodou + <function class="GtkObject">connect()</function>. </title> <programlisting role="php"> -function button_clicked($button, $window) +function stisknuti_tlacitka($tlacitko, $okno) { - $window->destroy(); + $okno->destroy(); gtk::main_quit(); } -$window = &new GtkWindow(); +$okno = &new GtkWindow(); -$button = &new GtkButton("exit"); -$button->connect("clicked","button_clicked", $window); +$tlacitko = &new GtkButton("konec"); +$tlacitko->connect("clicked","stisknuti_tlacitka", +$okno); -$window->add($button); -$window->show_all(); +$okno->add($tlacitko); +$okno->show_all(); gtk::main(); </programlisting> </example> - In the above code you can see that we pass not only the - <literal>$button</literal> variable, an instance of - <classname>GtkButton</classname>, to the <signalname>clicked</signalname> - callback but also the <literal>$window</literal> variable, an instance - of the <classname>GtkWindow</classname> class. This allows us to call - the <function class="GtkObject">destroy()</function> method on the window. + V tomto pøíkladu vidíte, ¾e volané funkci pøedáváme nejen promìnnou + <literal>$tlacitko</literal>, instanci tøídy + <classname>GtkButton</classname>, + ale také promìnnou <literal>$okno</literal>, instanci + tøídy <classname>GtkWindow</classname>. Tak mù¾eme na okno zavolat + metodu <function class="GtkObject">destroy()</function>. </para> <note> <simpara> - You can have as many custom parameters as you want. + U¾ivatelských parametrù mù¾ete pøedat, kolik jen budete chtít. </simpara> </note> <para> - By passing the <literal>$button</literal> variable as our calling object - parameter and the <literal>$window</literal> variable as our custom - parameter, we could use this same callback for more than one - <classname>GtkButton</classname> on more than one - <classname>GtkWindow</classname>. Note that the names given to the - parameters within the callback are irrelevant outside the callback - function; PHP-GTK picks up on the positions of the parameters in the - connect* method calls and passes these to the variables listed in the - callback declaration as an array, so that any instance of a connection - using the same parameter structure can use that same callback. This is - demonstrated in the code below using a single custom parameter, but is - equally true for more than one. + Tím, ¾e pøedáváme promìnnou <literal>$tlacitko</literal> jako + identifikátor volajícího objektu a promìnnou + <literal>$okno</literal> jako u¾ivatelský parametr, mù¾eme pou¾ít + stejnou obslu¾nou funkci pro více + <classname>GtkButton</classname> v jednom + <classname>GtkWindow</classname>. Pov¹imnìte si, ¾e pojmenování + parametrù v obslu¾né funkci nemá mimo tuto funkci význam; PHP-GTK vezme + parametry metody connect* a pøedá je jako promìnné urèené v deklaraci + obslu¾né funkce, tudí¾ ka¾dé pøipojení se stejnou strukturou parametrù + mù¾e pou¾ít stejnou obslu¾nou funkci. Pøedvedeme si to na pøíkladu, + který pou¾ívá jeden u¾ivatelský parametr, ale stejné zásady platí i pro + více parametrù. <example> - <title>Using the same callback for more than one window</title> + <title>Pou¾ití stejné funkce pro více ne¾ jedno okno</title> <programlisting role="php"> -function button_clicked($button, $window) +function stisknuti_tlacitka($tlacitko, $okno) { - $window->set_title("titled"); + $okno->set_title("oznaèeno"); } -$window1 = &new GtkWindow(); -$window1->connect_object("destroy", array("gtk", +$okno1 = &new GtkWindow(); +$okno1->connect_object("destroy", array("gtk", "main_quit")); -$window2 = &new GtkWindow(); -$window2->connect_object("destroy", array("gtk", +$okno2 = &new GtkWindow(); +$okno2->connect_object("destroy", array("gtk", "main_quit")); -$button1 = &new GtkButton("click me"); -$button2 = &new GtkButton("or me"); +$tlacitko1 = &new GtkButton("Klikni na mì"); +$tlacitko2 = &new GtkButton("Nebo rad¹i na mì"); -$button1->connect("clicked", "button_clicked", -$window1); -$button2->connect("clicked", "button_clicked", -$window2); +$tlacitko1->connect("clicked", "stisknuti_tlacitka", +$okno1); +$tlacitko2->connect("clicked", "stisknuti_tlacitka", +$okno2); -$window1->add($button1); -$window2->add($button2); +$okno1->add($tlacitko1); +$okno2->add($tlacitko2); -$window1->show_all(); -$window2->show_all(); +$okno1->show_all(); +$okno2->show_all(); gtk::main(); </programlisting> @@ -309,179 +303,172 @@ </sect2> <sect2 id="gtk.signals.connect.object"> - <title>Using the connect_object* methods</title> + <title>Pou¾ití metody connect_object*</title> <para> - Both <function class="GtkObject">connect_object()</function> and - <function class="GtkObject">connect_object_after()</function> allow you - to pass an object other than the calling object as the first parameter - to your callback function. This is mainly used for calling static - PHP-GTK functions, as in (for example) the - <function>gtk::main_quit()</function> function: + Jak <function class="GtkObject">connect_object()</function>, tak + <function class="GtkObject">connect_object_after()</function> umo¾òují + pøedat obslu¾né funkci jako první parametr jiný objekt ne¾ volající + objekt. Pou¾ívá se to hlavnì pøi volání statických PHP-GTK funkcí, jako + napøíklad funkce <function>gtk::main_quit()</function>: <example> <title> - Using the <function class="GtkObject">connect_object()</function> - method to specify a built-in function as callback. + Pou¾ití metody + <function class="GtkObject">connect_object()</function> + k urèení vestavìné funkce jako obslu¾né. </title> <programlisting role="php"> -$window = &new GtkWindow(); -$window->connect_object("destroy", array("gtk", +$okno = &new GtkWindow(); +$okno->connect_object("destroy", array("gtk", "main_quit")); -$window->show(); +$okno->show(); gtk::main(); </programlisting> </example> - This could be called on any static function or method by using the - <literal>gtkobject::method</literal> syntax expressed as an array. + Takto mù¾ete registrovat jakoukoli statickou funkci nebo metodu + pou¾itím syntaxe <literal>gtkobject::method</literal> vyjádøené polem. </para> <para> - It also means you can have a single callback for multiple signals. For - example; you might create a window containing (within the necessary - container widgets) a <classname>GtkMenuBar</classname>, a - <classname>GtkToolbar</classname> and a <classname>GtkButton</classname>. - When <literal>Exit</literal> is chosen by the user through any of these - widgets, a shutdown function could be invoked by passing the instance of - <classname>GtkWindow</classname> as its first parameter, allowing the - window to be destroyed from any of those connections. The callback - function and the connections in this instance would look like this: + Také to znamená, ¾e mù¾ete mít jednu obslu¾nou funkci pro nìkolik + signálù. Napø. chcete vytvoøit okno obsahující (v pøíslu¹ných + kontejnerech) <classname>GtkMenuBar</classname>, + <classname>GtkToolbar</classname> a <classname>GtkButton</classname>. + Jakmile u¾ivatel zvolí <literal>Konec</literal> skrze kterýkoli z tìchto + widgetù, zavolá se funkce vypni(), které se jako první parametr pøedá + instance <classname>GtkWindow</classname>, díky èemu¾ mù¾eme okno zavøít + z kteréhokoli widgetu. Obslu¾ná funkce a pøipojení bude vypadat nìjak + takto: <example> <title> - Using the <function class="GtkObject">connect_object()</function> - method to pass another object as first parameter. + Pou¾ití metody + <function class="GtkObject">connect_object()</function> k pøedání + jiného objektu jako prvního parametru. </title> <programlisting role="php"> -function destroy_window($window) +function vypni($okno) { - $window->destroy(); + $okno->destroy(); gtk::main_quit(); } -$exit_button->connect_object("clicked", -"destroy_window", $window); +$ukoncovaci_tlacitko->connect_object("clicked", +"vypni", $okno); </programlisting> </example> </para> <para> - The connect_after* methods allow callbacks to be "run after" - the default signal handler for that signal. This can be useful - in some situations; for example, where you want to destroy only one of - several windows in a given circumstance. However, connect_after* methods - will only work when a signal has been created in the GTK source with a - <literal>GTK_RUN_LAST</literal> flag. The - <signalname>destroy</signalname> signal and all the - <literal>'event'</literal> signals have this flag; beyond that, - the only way to check is to either test the signal within PHP-GTK or - read the GTK source. + Metoda connect_after* umo¾òuje volat obslu¾nou funkci "po" + zavolání standardní obslu¾né funkce pro tento signál. V nìkterých + situacích se to mù¾e hodit; napø. kdy¾ chcete zavøít jen jedno z + nìkolika oken. Metoda connect_after* v¹ak bude fungovat, jen pokud je + signál v zdrojovém souboru GTK aktivován s pøíznakem + <literal>GTK_RUN_LAST</literal>. Tento pøíznak má nastaven signál + <signalname>destroy</signalname> a v¹echny + <literal>'event'</literal> signály; jediný zpùsob, jak to zjistit, je + buï otestovat signál v PHP-GTK nebo prozkoumat zdrojové soubory GTK. <example> - <title>Using the - <function class="GtkObject">connect_after()</function> method. + <title>Pou¾ití metody + <function class="GtkObject">connect_after()</function>. </title> <programlisting role="php"> -function quit_routine($window) +function ukoncovaci_rutina($okno) { - print("Shutting down...\n"); + print("Vypínám...\n"); gtk::main_quit(); } -$window1 = &new GtkWindow(); -$window1->set_title("Quit the main loop"); -$window1->connect("destroy", "quit_routine"); - -$window2 = &new GtkWindow(); -$window2->set_title("Destroy this window"); -$window2->connect_after("destroy", "quit_routine"); +$okno1 = &new GtkWindow(); +$okno1->set_title("Ukonèí hlavní smyèku"); +$okno1->connect("destroy", "ukoncovaci_rutina"); + +$okno2 = &new GtkWindow(); +$okno2->set_title("Zavøe toto okno"); +$okno2->connect_after("destroy", "ukoncovaci_rutina"); -$window1->show(); -$window2->show(); +$okno1->show(); +$okno2->show(); gtk::main(); </programlisting> </example> </para> <simpara> - See also: <classname>GtkObject</classname>, + Viz také: <classname>GtkObject</classname>, <function class="GtkObject">connect_after()</function> - <function class="GtkObject">connect_object()</function> and + <function class="GtkObject">connect_object()</function> a <function class="GtkObject">connect_object_after()</function>. </simpara> </sect2> </sect1> <sect1 id="gtk.signals.events"> - <title>Signals and Events</title> + <title>Signály a události</title> <simpara> - <emphasis>GTK Signals, GDK Events.</emphasis> + <emphasis>GTK Signály, GDK události.</emphasis> </simpara> <simpara> - Signals are not events, and events are not signals. A signal is a message - emitted by an instance of a <classname>GtkObject</classname> in response - to some predetermined element in its environment, e.g. an action by the - end user, or an instruction from a function or method. Signals are always - programmed into the code, either internally within GTK or externally by - the PHP-GTK programmer. + Signály nejsou události a události nejsou signály. Signál je zpráva + vyslaná instancí <classname>GtkObject</classname> jako reakce na nìjaký + pøedurèený prvek v prostøedí, tj. èinnost u¾ivatele, nebo instrukci z + funkce èi metody. Signály jsou v¾dy naprogramovány do skriptu, buï + vnitønì v GTK nebo zvenku PHP-GTK programátorem. </simpara> <simpara> - Events, on the other hand, are a continual stream of impulses - communicating messages concerning environmental changes in the underlying - windowing system. The GTK main loop is made up of this stream of events, - among other things. + Události jsou, na druhou stranu, nepøetr¾itý tok zpráv ohlednì zmìn + prostøedí ve spodní vrstvì zobrazovacího systému. Hlavní smyèka GTK je, + mimo jiné, vytvoøena tokem událostí. </simpara> <note> <simpara> - It is not possible to connect a callback function to a - <classname>GdkEvent</classname> directly. + Nelze pøipojit obslu¾nou funkci pøímo na <classname>GdkEvent</classname>. </simpara> </note> <simpara> - Any widget having its own <classname>GdkWindow</classname> may capture - events that are relevant to it. Widgets lacking a - <classname>GdkWindow</classname> - those created with the - <literal>GTK_NO_WINDOW</literal> flag - cannot do so, unless they are - housed within a <classname>GtkEventBox</classname> - a widget created for - this specific purpose. There are occasions when it is useful to be able - to capture events; one obvious example would be the creation of an instance - of <classname>GtkToolTips</classname> which is triggered when its subject - widget captures the <literal>GDK_ENTER_NOTIFY</literal> event and - destroyed when the same widget captures the - <literal>GDK_LEAVE_NOTIFY</literal> event. + Jakýkoli widget, který má vlastní <classname>GdkWindow</classname>, mù¾e + zachytávat pøíslu¹né události. Widgety bez + <classname>GdkWindow</classname> - vytvoøené s pøíznakem + <literal>GTK_NO_WINDOW</literal> - to dìlat nemohou, pokud nejsou + umístìny do <classname>GtkEventBox</classname> - widgetu vytvoøeného pro + tento specifický úèel. V urèitých pøípadech je u¾iteèné zachytávat + události; zøejmým pøíkladem je vytvoøení instance + <classname>GtkToolTips</classname>, které se spou¹tí, kdy¾ daný widget + zachytí událost <literal>GDK_ENTER_NOTIFY</literal>, a ukonèují, kdy¾ + stejný widget zachytí událost <literal>GDK_LEAVE_NOTIFY</literal>. </simpara> <simpara> - Although it is not possible to use an event to trigger a callback in the - same way as a signal, there are a series of signals derived from - <classname>GtkWidget</classname> collectively known as - <literal>'event' signals</literal>. These are effectively ways - of describing an event in terms of a signal, allowing callbacks to be - indirectly triggered through a captured occurrence of most of the - <enumname>GdkEventTypes</enumname>. The - <classname>GtkTooltips</classname> object itself uses the - <function class="GktObject">connect_object()</function> method and the - generic <signalname>event</signalname> signal in order to monitor its - subject widget. + Aèkoli není mo¾no pou¾ít událost ke spu¹tìní funkce stejným zpùsobem, + jako u signálu, existuje nìkolik signálù vycházejících z + <classname>GtkWidget</classname>, které jsou dohromady známé jako + <literal>'event' signály</literal>. Takto mù¾ete úèinnì popisovat + události jako signály a spou¹tìt obslu¾né funkce pøi zachycení vìt¹iny + <enumname>GdkEventTypes</enumname>. Samotný objekt + <classname>GtkTooltips</classname> pou¾ívá ke sledování svého widgetu + metodu <function class="GktObject">connect_object()</function> a v¹eobecný + <signalname>event</signalname> signál. </simpara> <para> - The concept of events is not an easy one to grasp. Please copy, paste - and run the following script in order to see the flow of events over a - widget in action. + Koncepce událostí je tì¾ká na pochopení. Vyzkou¹ejte si, prosím, + následující pøíklad, abyste vidìli tok událostí nad widgety v chodu. <example> - <title>Demonstration of the flow of events across a + <title>Pøedvedení toku událostí nad <classname>GtkButton</classname> </title> <programlisting role="php"> dl("php_gtk." . (strstr(PHP_OS, "WIN") ? "dll" : "so")) || -die("Can't load php_gtk module!\n"); +die("Nelze nahrát PHP-GTK modul!\n"); -function show_event_type($button, $event, $text) +function ukaz_typ_udalosti($tlacitko, $udalost, $text) { - $event_type = $event->type; + $typ_udalosti = $udalost->type; $insert = $text->get_length(); $text->freeze(); - switch($event_type) { + switch($type_udalosti) { case 2: $text->insert_text("GDK_EXPOSE\n", $insert); break; @@ -493,7 +480,7 @@ break; case 5: $text->insert_text("GDK_2BUTTON_PRESS\n", $insert); - $button->hide(); + $tlacitko->hide(); break; case 7: $text->insert_text("GDK_BUTTON_RELEASE\n", $insert); @@ -518,25 +505,24 @@ break; case 15: $text->insert_text("GDK_UNMAP\n", $insert); - $button->destroy(); + $tlacitko->destroy(); $text->insert_text( -"\n* GDK EVENTS AND GTK SIGNALS - background stream vs foreground -messaging * +"\n* GDK UDÁLOSTI A GTK SIGNÁLY - tok na pozadí vs. zprávy na popøedí * \n -* Most GdkEventTypes have counterpart GTK signals, known as 'event' - signals, implemented in GtkWidget. The types on your screen are there - because the GtkButton was programmed to emit the generic 'event' signal - each time it captured one of the stream of GDK events that makes up the - GTK main loop. In each case, the captured GdkEvent was passed as a - callback parameter so that its enumerated type value could be determined - within the signal handler function. Scroll down to see the series of event - values captured during your recent interaction with the GtkButton widget. * +* Vìt¹ina GdkEventTypes má protìj¹ek mezi GTK signály, známý jako 'event' + signál, implementovaný v GtkWidget. Typy na obrazovce uvidíte, proto¾e + GtkButton je naprogramován tak, aby vysílal obecný 'event' signál poka¾dé, + kdy¾ zachytí nìkterou z GDK událostí, které vytváøí hlavní smyèku GTK. + V ka¾dém pøípadì je zachycená GdkEvent pøedána jako parametr obslu¾né + funkce, aby se ve funkci dala zjistit její èíselná hodnota. Podívejte se + na konec textu a uvidíte sérií událostí zachycených bìhem va¹í nedávné + interakce s widgetem GtkButton. * \n -* Please note that the majority of GTK signals do NOT correspond to GDK - events in this or any other way! For example, the signal connection - \$button->connect('pressed', 'whatever'); - has no relationship to the GDK_BUTTON_PRESS event it generates, which - refers to mouse-button activity and not to the GtkButton 'pressed' signal. * +* Pov¹imnìte si, ¾e vìt¹ina GTK signálù ¾ádným zpùsobem NEODPOVÍDÁ GDK + událostem! Napø. pøipojení signálu + \$tlacitko->connect('pressed', 'cokoli'); + nemá ¾ádný vztah k události GDK_BUTTON_PRESS, kterou generuje; tato + událost reaguje na aktivitu tlaèítka my¹i a nikoli na signál 'pressed'. * \n", 0); break; } @@ -544,27 +530,27 @@ return false; } -$window = &new GtkWindow(); -$window->set_position(GTK_WIN_POS_CENTER); -$window->set_default_size((gdk::screen_width()/1.5), +$okno = &new GtkWindow(); +$okno->set_position(GTK_WIN_POS_CENTER); +$okno->set_default_size((gdk::screen_width()/1.5), (gdk::screen_height()-20)); -$window->connect_object("destroy", array("gtk", +$okno->connect_object("destroy", array("gtk", "main_quit")); -$window->realize(); +$okno->realize(); $box = &new GtkVBox(false, 5); -$window->add($box); +$okno->add($box); $scrlwin = &new GtkScrolledWindow(); $box->pack_start($scrlwin, true, true, 0); $text = &new GtkText(); $scrlwin->add($text); -$button = &new GtkButton("Double-click here for information.."); -$button->add_events(GDK_ALL_EVENTS_MASK); -$button->connect("event", "show_event_type", $text); -$box->pack_end($button, false, false, 5); +$tlacitko = &new GtkButton("2x kliknìte zde a dozvíte se více"); +$tlacitko->add_events(GDK_ALL_EVENTS_MASK); +$tlacitko->connect("event", "ukaz_typ_udalosti", $text); +$box->pack_end($tlacitko, false, false, 5); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting>
Index: php-gtk-doc/cs/userguide/chapters/signals.xml diff -u php-gtk-doc/cs/userguide/chapters/signals.xml:1.1 php-gtk-doc/cs/userguide/chapters/signals.xml:1.2 --- php-gtk-doc/cs/userguide/chapters/signals.xml:1.1 Sat Apr 20 12:32:23 2002 +++ php-gtk-doc/cs/userguide/chapters/signals.xml Sun Apr 21 12:21:02 2002 @@ -54,253 +54,247 @@ </sect1> <sect1 id="gtk.signal.inheritance"> - <title>Signal Inheritance</title> + <title>Dìdìní signálù</title> <simpara> - Signals are inherited by objects, just as methods are. A widget can - emit any signals that its ancestor objects have defined, as well as its - own specific signals. + Objekty dìdí signály, stejnì jako metody. Widget mù¾e vyslat jakýkoli + signál definovaný u jeho rodièe, stejnì jako své vlastní signály. </simpara> <simpara> - In cases where the signal is not relevant to the widget but is nonetheless - inherited by it, there will be no error message when the signal is called - - but equally, there will be no obvious means for the widget to emit that - particular signal. + V pøípadì, ¾e signál není u widgetu relevantní, ale je pøesto zdìdìn, + nevypí¹e se pøi zavolání signálu ¾ádná chybová zpráva - ale vyvolání + tohoto signálu se nijak neprojeví. </simpara> </sect1> <sect1 id="gtk.signals.connection"> - <title>Connecting Signals</title> + <title>Pøipojování signálù</title> <sect2 id="gtk.signals.connection.simple"> - <title>Simple Connections</title> + <title>Jednoduché pøipojení</title> <simpara> - To react to a signal you must connect to it by specifying a callback - function for PHP-GTK to call when that signal is emitted. + Aby se po vyvolání signálu nìco stalo, musíte urèit, kterou funkci tento + signál spustí. </simpara> <simpara> - Connecting a function to a signal is achieved by calling the - <function class="GtkObject">connect()</function> method of the object. + Pøipojení funkce k signálu dosáhnete zavoláním metody + <function class="GtkObject">connect()</function> objektu. </simpara> <simpara> - The function that you register as the callback for a signal must have the - correct prototype. You can find what the prototype should be from the - <link linkend="reference">reference</link> section of this manual. + Funkce, kterou zaregistrujete jako obslu¾nou pro signál, musí mít + správný prototyp. Jak by mìla být funkce konstruována, zjistíte v + <link linkend="reference">referenèní</link> èásti manuálu. </simpara> <simpara> - For example, if you wanted to connect to the - <signalname>clicked</signalname> signal of an instance of - <classname>GtkButton</classname> you should define a function that - accepts one parameter, which will be the button that was clicked. + Napøíklad kdy¾ chcete pøipojit signál + <signalname>clicked</signalname> objektu + <classname>GtkButton</classname>, mìli byste definovat funkci, která + pøijímá jeden parametr, co¾ bude oznaèení stisknutého tlaèítka. </simpara> <para> - The code below shows how you might create a window, add a button to it, - wait for it to be clicked and then, when it is clicked, open a new - <classname>GtkWindow</classname> containing a message. + Následující kód ukazuje, jak mù¾ete vytvoøit okno, pøidat do nìj + tlaèítko, poèkat, a¾ na nìj u¾ivatel klikne, a poté otevøít nové + <classname>GtkWindow</classname> se zprávou. <example> - <title>Signals and Callbacks</title> + <title>Signály a volání</title> <programlisting role="php"> -function shutdown() +function vypni() { - print("Shutting down...\n"); + print("Vypínám...\n"); gtk::main_quit(); } -function you_clicked($button) +function kliknul_jste($tlacitko) { - $window = &new GtkWindow(); - $label = &new GtkLabel("You clicked the button"); - $window->add($label); - $window->connect("destroy","shutdown"); - $window->show_all(); + $okno = &new GtkWindow(); + $popisek = &new GtkLabel("Kliknul jste na tlaèítko"); + $okno->add($popisek); + $okno->connect("destroy","vypni"); + $okno->show_all(); return false; } -$window = &new GtkWindow(); -$window->connect("destroy", "shutdown"); -$window->set_border_width(10); - -$button = &new GtkButton("Click Me!!"); -$button->connect("clicked", "you_clicked"); -$window->add($button); +$okno = &new GtkWindow(); +$okno->connect("destroy", "vypni"); +$okno->set_border_width(10); + +$tlacitko = &new GtkButton("Klikni na mì!!"); +$tlacitko->connect("clicked", "kliknul_jste"); +$okno->add($tlacitko); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting> </example> </para> <para> - The important part here is where we call + Dùle¾itá èást je volání <informalexample> - <programlisting role="php">$button->connect();</programlisting> + <programlisting role="php">$tlacitko->connect();</programlisting> </informalexample> - The connect method here registers the <literal>you_clicked()</literal> - function as the callback that will be invoked when the - <signalname>clicked</signalname> signal is emitted by the - <classname>GtkButton</classname> widget. We also register the - <literal>shutdown()</literal> function as the handler for the - <signalname>destroy</signalname> signal for both windows so that we - can shut down the application properly. + Metoda connect zde registruje funkci <literal>kliknul_jste()</literal> + jako obslu¾nou funkci, která se spustí po vyvolání signálu + <signalname>clicked</signalname> widgetu + <classname>GtkButton</classname>. Také registrujeme funkci + <literal>shutdown()</literal> jako obslu¾nou funkci signálu + <signalname>destroy</signalname> obou oken, abychom mohli aplikaci øádnì + ukonèit. </para> </sect2> <sect2 id="gtk.signals.connection.multiple"> - <title>Multiple Connections</title> + <title>Vícenásobná pøipojení</title> <simpara> - With PHP-GTK you can register more than one function to be invoked when - a signal is emitted by a widget. This allows you to set up a whole set - of functions to be called in response to an expected action. + V PHP-GTK mù¾ete k signálu zaregistrovat více ne¾ jednu funkci. To vám + umo¾òuje spustit jako odpovìï na signál celou sadu funkcí. </simpara> <para> - When more than one function is connected to a signal, the functions are - called in the order in which they were registered when that signal is - emitted. + Kdy¾ pøipojujete k signálu více funkcí, volají se funkce v poøadí, v + jakém byly zaregistrovány. <example> - <title>Signal Callback Order</title> + <title>Poøadí volání funkcí</title> <programlisting role="php"> -function first($button) +function prvni($tlacitko) { - print "First function has been called\n"; + print "Byla zavolána první funkce\n"; } -function second($button) +function druha($tlacitko) { - print "Second function has been called\n"; + print "Byla zavolána druhá funkce\n"; } -$window = &new GtkWindow(); -$window->connect_object("destroy", array("gtk", +$okno = &new GtkWindow(); +$okno->connect_object("destroy", array("gtk", "main_quit")); -$button = &new GtkButton("Click Me!!"); -$button->connect("clicked","first"); -$button->connect("clicked","second"); -$window->add($button); +$tlacitko = &new GtkButton("Klikni na mì!!"); +$tlacitko->connect("clicked","prvni"); +$tlacitko->connect("clicked","druha"); +$okno->add($tlacitko); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting> </example> - In the above example we connect two functions to a button's - <signalname>clicked</signalname> signal. The first call to the - <function class="GtkObject">connect()</function> method connects the - <signalname>clicked</signalname> signal to the <literal>first()</literal> - function, the second call connects the <signalname>clicked</signalname> - signal to the <literal>second()</literal> function. + V tomto pøíkladu pøipojíme na signál + <signalname>clicked</signalname> tlaèítka rovnou dvì funkce. První + volání metody <function class="GtkObject">connect()</function> pøipojí k + signálu <signalname>clicked</signalname> funkci + <literal>prvni()</literal> a druhé zavolání pøipojí k signálu + <signalname>clicked</signalname> funkci <literal>druha()</literal>. </para> <para> - The output from this program would be: + Výstup tohoto programu bude vypadat následovnì: <programlisting> -First function has been called. -Second function has been called. +Byla zavolána první funkce +Byla zavolána druhá funkce </programlisting> </para> </sect2> </sect1> <sect1 id="gtk.signals.custom.params"> - <title>Using Custom Parameters</title> + <title>Pou¾ívání u¾ivatelských parametrù</title> <sect2 id="gtk.signals.custom.data"> - <title>Passing Custom Data as a Parameter</title> + <title>Pøedávání u¾ivatelských dat jako parametru</title> <simpara> - When <link linkend="gtk.signals.connection">connecting</link> signals, - it is possible to add an extra custom parameter to the callback. This - is useful for passing the object you want to perform an action on, to - your callback function. + Kdy¾ <link linkend="gtk.signals.connection">pøipojujete</link> signál, + mù¾ete pøidat volané funkci vlastní parametry navíc. Toto je u¾iteèné, + potøebujete-li pøedávat volané funkci objekty ke zpracování. </simpara> <simpara> - For example, when a button is pressed we might want to destroy the parent - instance of <classname>GtkWindow</classname> that that instance of - <classname>GtkButton</classname> has been - <function class="gtkcontainer">add</function>ed to. + Napøíklad mù¾ete chtít zavøít rodièovské okno, do nìho¾ bylo pøidání + tlaèítko stisknuté u¾ivatelem. </simpara> <simpara> - You can do this by including an optional third parameter to the - <function class="GtkObject">connect()</function> call. This will then be - passed to your signal handler function as the final callback parameter. + Toho dosáhnete tak, ¾e k volání + <function class="GtkObject">connect()</function> pøidáte tøetí nepovinný + parametr. Tento bude pøedán obslu¾né funkci jako dal¹í parametr. </simpara> <para> <example> <title> - Using Custom Parameters with the - <function class="GtkObject">connect()</function> method. + Pou¾ívání u¾ivatelských parametrù s metodou + <function class="GtkObject">connect()</function>. </title> <programlisting role="php"> -function button_clicked($button, $window) +function stisknuti_tlacitka($tlacitko, $okno) { - $window->destroy(); + $okno->destroy(); gtk::main_quit(); } -$window = &new GtkWindow(); +$okno = &new GtkWindow(); -$button = &new GtkButton("exit"); -$button->connect("clicked","button_clicked", $window); +$tlacitko = &new GtkButton("konec"); +$tlacitko->connect("clicked","stisknuti_tlacitka", +$okno); -$window->add($button); -$window->show_all(); +$okno->add($tlacitko); +$okno->show_all(); gtk::main(); </programlisting> </example> - In the above code you can see that we pass not only the - <literal>$button</literal> variable, an instance of - <classname>GtkButton</classname>, to the <signalname>clicked</signalname> - callback but also the <literal>$window</literal> variable, an instance - of the <classname>GtkWindow</classname> class. This allows us to call - the <function class="GtkObject">destroy()</function> method on the window. + V tomto pøíkladu vidíte, ¾e volané funkci pøedáváme nejen promìnnou + <literal>$tlacitko</literal>, instanci tøídy + <classname>GtkButton</classname>, + ale také promìnnou <literal>$okno</literal>, instanci + tøídy <classname>GtkWindow</classname>. Tak mù¾eme na okno zavolat + metodu <function class="GtkObject">destroy()</function>. </para> <note> <simpara> - You can have as many custom parameters as you want. + U¾ivatelských parametrù mù¾ete pøedat, kolik jen budete chtít. </simpara> </note> <para> - By passing the <literal>$button</literal> variable as our calling object - parameter and the <literal>$window</literal> variable as our custom - parameter, we could use this same callback for more than one - <classname>GtkButton</classname> on more than one - <classname>GtkWindow</classname>. Note that the names given to the - parameters within the callback are irrelevant outside the callback - function; PHP-GTK picks up on the positions of the parameters in the - connect* method calls and passes these to the variables listed in the - callback declaration as an array, so that any instance of a connection - using the same parameter structure can use that same callback. This is - demonstrated in the code below using a single custom parameter, but is - equally true for more than one. + Tím, ¾e pøedáváme promìnnou <literal>$tlacitko</literal> jako + identifikátor volajícího objektu a promìnnou + <literal>$okno</literal> jako u¾ivatelský parametr, mù¾eme pou¾ít + stejnou obslu¾nou funkci pro více + <classname>GtkButton</classname> v jednom + <classname>GtkWindow</classname>. Pov¹imnìte si, ¾e pojmenování + parametrù v obslu¾né funkci nemá mimo tuto funkci význam; PHP-GTK vezme + parametry metody connect* a pøedá je jako promìnné urèené v deklaraci + obslu¾né funkce, tudí¾ ka¾dé pøipojení se stejnou strukturou parametrù + mù¾e pou¾ít stejnou obslu¾nou funkci. Pøedvedeme si to na pøíkladu, + který pou¾ívá jeden u¾ivatelský parametr, ale stejné zásady platí i pro + více parametrù. <example> - <title>Using the same callback for more than one window</title> + <title>Pou¾ití stejné funkce pro více ne¾ jedno okno</title> <programlisting role="php"> -function button_clicked($button, $window) +function stisknuti_tlacitka($tlacitko, $okno) { - $window->set_title("titled"); + $okno->set_title("oznaèeno"); } -$window1 = &new GtkWindow(); -$window1->connect_object("destroy", array("gtk", +$okno1 = &new GtkWindow(); +$okno1->connect_object("destroy", array("gtk", "main_quit")); -$window2 = &new GtkWindow(); -$window2->connect_object("destroy", array("gtk", +$okno2 = &new GtkWindow(); +$okno2->connect_object("destroy", array("gtk", "main_quit")); -$button1 = &new GtkButton("click me"); -$button2 = &new GtkButton("or me"); +$tlacitko1 = &new GtkButton("Klikni na mì"); +$tlacitko2 = &new GtkButton("Nebo rad¹i na mì"); -$button1->connect("clicked", "button_clicked", -$window1); -$button2->connect("clicked", "button_clicked", -$window2); +$tlacitko1->connect("clicked", "stisknuti_tlacitka", +$okno1); +$tlacitko2->connect("clicked", "stisknuti_tlacitka", +$okno2); -$window1->add($button1); -$window2->add($button2); +$okno1->add($tlacitko1); +$okno2->add($tlacitko2); -$window1->show_all(); -$window2->show_all(); +$okno1->show_all(); +$okno2->show_all(); gtk::main(); </programlisting> @@ -309,179 +303,172 @@ </sect2> <sect2 id="gtk.signals.connect.object"> - <title>Using the connect_object* methods</title> + <title>Pou¾ití metody connect_object*</title> <para> - Both <function class="GtkObject">connect_object()</function> and - <function class="GtkObject">connect_object_after()</function> allow you - to pass an object other than the calling object as the first parameter - to your callback function. This is mainly used for calling static - PHP-GTK functions, as in (for example) the - <function>gtk::main_quit()</function> function: + Jak <function class="GtkObject">connect_object()</function>, tak + <function class="GtkObject">connect_object_after()</function> umo¾òují + pøedat obslu¾né funkci jako první parametr jiný objekt ne¾ volající + objekt. Pou¾ívá se to hlavnì pøi volání statických PHP-GTK funkcí, jako + napøíklad funkce <function>gtk::main_quit()</function>: <example> <title> - Using the <function class="GtkObject">connect_object()</function> - method to specify a built-in function as callback. + Pou¾ití metody + <function class="GtkObject">connect_object()</function> + k urèení vestavìné funkce jako obslu¾né. </title> <programlisting role="php"> -$window = &new GtkWindow(); -$window->connect_object("destroy", array("gtk", +$okno = &new GtkWindow(); +$okno->connect_object("destroy", array("gtk", "main_quit")); -$window->show(); +$okno->show(); gtk::main(); </programlisting> </example> - This could be called on any static function or method by using the - <literal>gtkobject::method</literal> syntax expressed as an array. + Takto mù¾ete registrovat jakoukoli statickou funkci nebo metodu + pou¾itím syntaxe <literal>gtkobject::method</literal> vyjádøené polem. </para> <para> - It also means you can have a single callback for multiple signals. For - example; you might create a window containing (within the necessary - container widgets) a <classname>GtkMenuBar</classname>, a - <classname>GtkToolbar</classname> and a <classname>GtkButton</classname>. - When <literal>Exit</literal> is chosen by the user through any of these - widgets, a shutdown function could be invoked by passing the instance of - <classname>GtkWindow</classname> as its first parameter, allowing the - window to be destroyed from any of those connections. The callback - function and the connections in this instance would look like this: + Také to znamená, ¾e mù¾ete mít jednu obslu¾nou funkci pro nìkolik + signálù. Napø. chcete vytvoøit okno obsahující (v pøíslu¹ných + kontejnerech) <classname>GtkMenuBar</classname>, + <classname>GtkToolbar</classname> a <classname>GtkButton</classname>. + Jakmile u¾ivatel zvolí <literal>Konec</literal> skrze kterýkoli z tìchto + widgetù, zavolá se funkce vypni(), které se jako první parametr pøedá + instance <classname>GtkWindow</classname>, díky èemu¾ mù¾eme okno zavøít + z kteréhokoli widgetu. Obslu¾ná funkce a pøipojení bude vypadat nìjak + takto: <example> <title> - Using the <function class="GtkObject">connect_object()</function> - method to pass another object as first parameter. + Pou¾ití metody + <function class="GtkObject">connect_object()</function> k pøedání + jiného objektu jako prvního parametru. </title> <programlisting role="php"> -function destroy_window($window) +function vypni($okno) { - $window->destroy(); + $okno->destroy(); gtk::main_quit(); } -$exit_button->connect_object("clicked", -"destroy_window", $window); +$ukoncovaci_tlacitko->connect_object("clicked", +"vypni", $okno); </programlisting> </example> </para> <para> - The connect_after* methods allow callbacks to be "run after" - the default signal handler for that signal. This can be useful - in some situations; for example, where you want to destroy only one of - several windows in a given circumstance. However, connect_after* methods - will only work when a signal has been created in the GTK source with a - <literal>GTK_RUN_LAST</literal> flag. The - <signalname>destroy</signalname> signal and all the - <literal>'event'</literal> signals have this flag; beyond that, - the only way to check is to either test the signal within PHP-GTK or - read the GTK source. + Metoda connect_after* umo¾òuje volat obslu¾nou funkci "po" + zavolání standardní obslu¾né funkce pro tento signál. V nìkterých + situacích se to mù¾e hodit; napø. kdy¾ chcete zavøít jen jedno z + nìkolika oken. Metoda connect_after* v¹ak bude fungovat, jen pokud je + signál v zdrojovém souboru GTK aktivován s pøíznakem + <literal>GTK_RUN_LAST</literal>. Tento pøíznak má nastaven signál + <signalname>destroy</signalname> a v¹echny + <literal>'event'</literal> signály; jediný zpùsob, jak to zjistit, je + buï otestovat signál v PHP-GTK nebo prozkoumat zdrojové soubory GTK. <example> - <title>Using the - <function class="GtkObject">connect_after()</function> method. + <title>Pou¾ití metody + <function class="GtkObject">connect_after()</function>. </title> <programlisting role="php"> -function quit_routine($window) +function ukoncovaci_rutina($okno) { - print("Shutting down...\n"); + print("Vypínám...\n"); gtk::main_quit(); } -$window1 = &new GtkWindow(); -$window1->set_title("Quit the main loop"); -$window1->connect("destroy", "quit_routine"); - -$window2 = &new GtkWindow(); -$window2->set_title("Destroy this window"); -$window2->connect_after("destroy", "quit_routine"); +$okno1 = &new GtkWindow(); +$okno1->set_title("Ukonèí hlavní smyèku"); +$okno1->connect("destroy", "ukoncovaci_rutina"); + +$okno2 = &new GtkWindow(); +$okno2->set_title("Zavøe toto okno"); +$okno2->connect_after("destroy", "ukoncovaci_rutina"); -$window1->show(); -$window2->show(); +$okno1->show(); +$okno2->show(); gtk::main(); </programlisting> </example> </para> <simpara> - See also: <classname>GtkObject</classname>, + Viz také: <classname>GtkObject</classname>, <function class="GtkObject">connect_after()</function> - <function class="GtkObject">connect_object()</function> and + <function class="GtkObject">connect_object()</function> a <function class="GtkObject">connect_object_after()</function>. </simpara> </sect2> </sect1> <sect1 id="gtk.signals.events"> - <title>Signals and Events</title> + <title>Signály a události</title> <simpara> - <emphasis>GTK Signals, GDK Events.</emphasis> + <emphasis>GTK Signály, GDK události.</emphasis> </simpara> <simpara> - Signals are not events, and events are not signals. A signal is a message - emitted by an instance of a <classname>GtkObject</classname> in response - to some predetermined element in its environment, e.g. an action by the - end user, or an instruction from a function or method. Signals are always - programmed into the code, either internally within GTK or externally by - the PHP-GTK programmer. + Signály nejsou události a události nejsou signály. Signál je zpráva + vyslaná instancí <classname>GtkObject</classname> jako reakce na nìjaký + pøedurèený prvek v prostøedí, tj. èinnost u¾ivatele, nebo instrukci z + funkce èi metody. Signály jsou v¾dy naprogramovány do skriptu, buï + vnitønì v GTK nebo zvenku PHP-GTK programátorem. </simpara> <simpara> - Events, on the other hand, are a continual stream of impulses - communicating messages concerning environmental changes in the underlying - windowing system. The GTK main loop is made up of this stream of events, - among other things. + Události jsou, na druhou stranu, nepøetr¾itý tok zpráv ohlednì zmìn + prostøedí ve spodní vrstvì zobrazovacího systému. Hlavní smyèka GTK je, + mimo jiné, vytvoøena tokem událostí. </simpara> <note> <simpara> - It is not possible to connect a callback function to a - <classname>GdkEvent</classname> directly. + Nelze pøipojit obslu¾nou funkci pøímo na <classname>GdkEvent</classname>. </simpara> </note> <simpara> - Any widget having its own <classname>GdkWindow</classname> may capture - events that are relevant to it. Widgets lacking a - <classname>GdkWindow</classname> - those created with the - <literal>GTK_NO_WINDOW</literal> flag - cannot do so, unless they are - housed within a <classname>GtkEventBox</classname> - a widget created for - this specific purpose. There are occasions when it is useful to be able - to capture events; one obvious example would be the creation of an instance - of <classname>GtkToolTips</classname> which is triggered when its subject - widget captures the <literal>GDK_ENTER_NOTIFY</literal> event and - destroyed when the same widget captures the - <literal>GDK_LEAVE_NOTIFY</literal> event. + Jakýkoli widget, který má vlastní <classname>GdkWindow</classname>, mù¾e + zachytávat pøíslu¹né události. Widgety bez + <classname>GdkWindow</classname> - vytvoøené s pøíznakem + <literal>GTK_NO_WINDOW</literal> - to dìlat nemohou, pokud nejsou + umístìny do <classname>GtkEventBox</classname> - widgetu vytvoøeného pro + tento specifický úèel. V urèitých pøípadech je u¾iteèné zachytávat + události; zøejmým pøíkladem je vytvoøení instance + <classname>GtkToolTips</classname>, které se spou¹tí, kdy¾ daný widget + zachytí událost <literal>GDK_ENTER_NOTIFY</literal>, a ukonèují, kdy¾ + stejný widget zachytí událost <literal>GDK_LEAVE_NOTIFY</literal>. </simpara> <simpara> - Although it is not possible to use an event to trigger a callback in the - same way as a signal, there are a series of signals derived from - <classname>GtkWidget</classname> collectively known as - <literal>'event' signals</literal>. These are effectively ways - of describing an event in terms of a signal, allowing callbacks to be - indirectly triggered through a captured occurrence of most of the - <enumname>GdkEventTypes</enumname>. The - <classname>GtkTooltips</classname> object itself uses the - <function class="GktObject">connect_object()</function> method and the - generic <signalname>event</signalname> signal in order to monitor its - subject widget. + Aèkoli není mo¾no pou¾ít událost ke spu¹tìní funkce stejným zpùsobem, + jako u signálu, existuje nìkolik signálù vycházejících z + <classname>GtkWidget</classname>, které jsou dohromady známé jako + <literal>'event' signály</literal>. Takto mù¾ete úèinnì popisovat + události jako signály a spou¹tìt obslu¾né funkce pøi zachycení vìt¹iny + <enumname>GdkEventTypes</enumname>. Samotný objekt + <classname>GtkTooltips</classname> pou¾ívá ke sledování svého widgetu + metodu <function class="GktObject">connect_object()</function> a v¹eobecný + <signalname>event</signalname> signál. </simpara> <para> - The concept of events is not an easy one to grasp. Please copy, paste - and run the following script in order to see the flow of events over a - widget in action. + Koncepce událostí je tì¾ká na pochopení. Vyzkou¹ejte si, prosím, + následující pøíklad, abyste vidìli tok událostí nad widgety v chodu. <example> - <title>Demonstration of the flow of events across a + <title>Pøedvedení toku událostí nad <classname>GtkButton</classname> </title> <programlisting role="php"> dl("php_gtk." . (strstr(PHP_OS, "WIN") ? "dll" : "so")) || -die("Can't load php_gtk module!\n"); +die("Nelze nahrát PHP-GTK modul!\n"); -function show_event_type($button, $event, $text) +function ukaz_typ_udalosti($tlacitko, $udalost, $text) { - $event_type = $event->type; + $typ_udalosti = $udalost->type; $insert = $text->get_length(); $text->freeze(); - switch($event_type) { + switch($type_udalosti) { case 2: $text->insert_text("GDK_EXPOSE\n", $insert); break; @@ -493,7 +480,7 @@ break; case 5: $text->insert_text("GDK_2BUTTON_PRESS\n", $insert); - $button->hide(); + $tlacitko->hide(); break; case 7: $text->insert_text("GDK_BUTTON_RELEASE\n", $insert); @@ -518,25 +505,24 @@ break; case 15: $text->insert_text("GDK_UNMAP\n", $insert); - $button->destroy(); + $tlacitko->destroy(); $text->insert_text( -"\n* GDK EVENTS AND GTK SIGNALS - background stream vs foreground -messaging * +"\n* GDK UDÁLOSTI A GTK SIGNÁLY - tok na pozadí vs. zprávy na popøedí * \n -* Most GdkEventTypes have counterpart GTK signals, known as 'event' - signals, implemented in GtkWidget. The types on your screen are there - because the GtkButton was programmed to emit the generic 'event' signal - each time it captured one of the stream of GDK events that makes up the - GTK main loop. In each case, the captured GdkEvent was passed as a - callback parameter so that its enumerated type value could be determined - within the signal handler function. Scroll down to see the series of event - values captured during your recent interaction with the GtkButton widget. * +* Vìt¹ina GdkEventTypes má protìj¹ek mezi GTK signály, známý jako 'event' + signál, implementovaný v GtkWidget. Typy na obrazovce uvidíte, proto¾e + GtkButton je naprogramován tak, aby vysílal obecný 'event' signál poka¾dé, + kdy¾ zachytí nìkterou z GDK událostí, které vytváøí hlavní smyèku GTK. + V ka¾dém pøípadì je zachycená GdkEvent pøedána jako parametr obslu¾né + funkce, aby se ve funkci dala zjistit její èíselná hodnota. Podívejte se + na konec textu a uvidíte sérií událostí zachycených bìhem va¹í nedávné + interakce s widgetem GtkButton. * \n -* Please note that the majority of GTK signals do NOT correspond to GDK - events in this or any other way! For example, the signal connection - \$button->connect('pressed', 'whatever'); - has no relationship to the GDK_BUTTON_PRESS event it generates, which - refers to mouse-button activity and not to the GtkButton 'pressed' signal. * +* Pov¹imnìte si, ¾e vìt¹ina GTK signálù ¾ádným zpùsobem NEODPOVÍDÁ GDK + událostem! Napø. pøipojení signálu + \$tlacitko->connect('pressed', 'cokoli'); + nemá ¾ádný vztah k události GDK_BUTTON_PRESS, kterou generuje; tato + událost reaguje na aktivitu tlaèítka my¹i a nikoli na signál 'pressed'. * \n", 0); break; } @@ -544,27 +530,27 @@ return false; } -$window = &new GtkWindow(); -$window->set_position(GTK_WIN_POS_CENTER); -$window->set_default_size((gdk::screen_width()/1.5), +$okno = &new GtkWindow(); +$okno->set_position(GTK_WIN_POS_CENTER); +$okno->set_default_size((gdk::screen_width()/1.5), (gdk::screen_height()-20)); -$window->connect_object("destroy", array("gtk", +$okno->connect_object("destroy", array("gtk", "main_quit")); -$window->realize(); +$okno->realize(); $box = &new GtkVBox(false, 5); -$window->add($box); +$okno->add($box); $scrlwin = &new GtkScrolledWindow(); $box->pack_start($scrlwin, true, true, 0); $text = &new GtkText(); $scrlwin->add($text); -$button = &new GtkButton("Double-click here for information.."); -$button->add_events(GDK_ALL_EVENTS_MASK); -$button->connect("event", "show_event_type", $text); -$box->pack_end($button, false, false, 5); +$tlacitko = &new GtkButton("2x kliknìte zde a dozvíte se více"); +$tlacitko->add_events(GDK_ALL_EVENTS_MASK); +$tlacitko->connect("event", "ukaz_typ_udalosti", $text); +$box->pack_end($tlacitko, false, false, 5); -$window->show_all(); +$okno->show_all(); gtk::main(); </programlisting>