Re: Re: Gtk::input_add() for a popen() filehandle?
| From: | Andrei Zmievski | Date: | Tue, 09 Apr 2002 19:28:47 +0000 |
| Subject: | Re: Re: Gtk::input_add() for a popen() filehandle? | ||
| References: | 1 2 3 4 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-1767@lists.php.net to get a copy of this message | ||
On Tue, 09 Apr 2002, Alan Knowles wrote:
> I'm not getting anywhere with this :) - and it's getting late. (this is
> using php-gtk CVS and php4.2Rc2)
> - simple proof of concept: press the button, and the program is supposed
> to do a fopen or popen, and add a callback.
>
>
> Am I missing something here....
> regards
> alan
>
>
> <?
> error_reporting(E_ALL);
> dl('php_gtk.'.(strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
>
> class MyClass {
>
> var $window;
> var $pixmap;
> var $mask;
> var $w;
>
> function build() {
> $this->window = &new GtkWindow();
> $this->window->set_position(GTK_WIN_POS_CENTER);
> $this->window->set_name('my_window');
> $this->window->connect_object('destroy', array('gtk',
> 'main_quit'));
> $this->box = &new GtkVbox();
> $this->window->add($this->box);
>
> $this->gtktext = &new GtkText();
> $this->box->add($this->gtktext);
>
> $this->button = &new GtkButton("press me");
> $this->button->connect("pressed",array(&$this,"pressed"));
> $this->box->add($this->button);
>
> $this->window->show_all();
> }
> function pressed() {
> echo "starting something";
> $fp = fopen("/home/alan/access.log","r");
> Gtk::input_add($fp, GDK_INPUT_READ, array(&$this,"reader"));
>
> }
> function reader($a,$b,$c) {
> echo "got something";
> echo serialize(array($a,$b,$c));
> }
> }
>
> $gui = new MyClass;
> $gui->build();
>
> gtk::main();
> ?>
Okay, my previous patch was right and the reader function will keep
getting called indefinitely until you use gtk::input_remove() so the
proper way to do it is:
<?
dl('php_gtk.so');
function reader($source, $condition)
{
global $fd;
if ($data = fgets($source, 200)) {
print $data;
} else {
gtk::input_remove($fd);
gtk::main_quit();
}
}
$fp = fopen("config.m4", "r");
$fd = gtk::input_add($fp, GDK_INPUT_READ, 'reader');
gtk::main();
fclose($fp);
?>
-Andrei
* Only 19,999 lines of C++ to my next ski trip... *