cvs: presentations /slides/gtk clock.php clock.xml mainloop2.xml
| From: | Andrei Zmievski | Date: | Wed, 21 Jan 2004 22:44:41 +0000 |
| Subject: | cvs: presentations /slides/gtk clock.php clock.xml mainloop2.xml | ||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-954@lists.php.net to get a copy of this message | ||
andrei Wed Jan 21 17:44:41 2004 EDT
Added files:
/presentations/slides/gtk clock.php clock.xml mainloop2.xml
Log:
Add clock example.
http://cvs.php.net/co.php/presentations/slides/gtk/clock.php?r=1.1&p=1
Index: presentations/slides/gtk/clock.php
+++ presentations/slides/gtk/clock.php
<?php
dl('php_gtk.so');
$window =& new GtkWindow(GTK_WINDOW_DIALOG);
$window->set_title('Clock');
$window->set_border_width(10);
$window->connect('destroy', 'destroy');
$label =& new GtkLabel();
$window->add($label);
gtk::timeout_add(1000, 'update', $label);
update($label);
$window->show_all();
gtk::main();
function update($label)
{
$time = strftime('%H:%M:%S %p');
$label->set_text($time);
return true;
}
function destroy($window)
{
gtk::main_quit();
}
?>
http://cvs.php.net/co.php/presentations/slides/gtk/clock.xml?r=1.1&p=1
Index: presentations/slides/gtk/clock.xml
+++ presentations/slides/gtk/clock.xml
<slide title="A Simple Clock" logo1="images/php-gtk.gif"
navColor="#b0c2d3" navsize="1.4em">
<blurb>
"Hello, World" programs are boring. Let's do something a little more
interesting.
</blurb>
<link align="center" text="Clock"
href="presentations/slides/gtk/clock.php" />
<example fontsize="1ex" filename="clock.php" />
</slide>
http://cvs.php.net/co.php/presentations/slides/gtk/mainloop2.xml?r=1.1&p=1
Index: presentations/slides/gtk/mainloop2.xml
+++ presentations/slides/gtk/mainloop2.xml
<slide title="Main Loop" logo1="images/php-gtk.gif"
navColor="#b0c2d3" navsize="1.4em">
<blurb fontsize="2.3ex">
Sometimes you want to have a piece of code be called periodically. Register a
~timeout~ function, and the main loop will call it after the specified time has
elapsed. If you want to stop being called, return %FALSE% from the function.
</blurb>
<example fontsize="1ex"><![CDATA[<?php
function do_something_every_second($arg1, $arg2)
{
/* do useful thing */
return true;
}
gtk::timeout_add(1000, 'do_something_every_second', $my_arg1, $my_arg2);
gtk::main();
?>]]></example>
<blurb fontsize="2.3ex">
If you want to monitor a socket, pipe, or a file for data available for
reading or writing, you can do it with %gtk::input_add()% function.
Pass it the resource to be watched, the input condition, and the callback with
optional data.
</blurb>
<example fontsize="1ex"><![CDATA[<?php
function show_log($stream, $condition, $my_data) { }
$stream = ...; // open the log via pipe, for example
gtk::input_add($stream, GDK_INPUT_READ, 'show_log', $some_data);
gtk::main();
?>]]></example>
</slide>