Re: Using Gtk2::Helper->add_watch() or Glib::IO->add_watch

Thanks ! 

The FAQ however has some minor syntax errors. I found it being discussed here

I tried the code that muppet has posted in that thread. Somehow that
quite doesn't work for me either . I'm on windoze XP. I am wondering
if it has anything to do with the fact that I'm on win32.

The behaviour I notice is as follows. My textview buffer doesn't get
anything written into it. My command prompt gets filled with
"reading... read" messages (with no sleep in between) and it seems to
be in an infinite loop. (no stopping after 9 seconds).

Am I missing something here ? Does this have to do with buffering
related to open(FILEHANDLE, EXPR).

Here is the code that I'm running

#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
my $window = Gtk2::Window->new;
my $scroll = Gtk2::ScrolledWindow->new;
my $textview = Gtk2::TextView->new;
my $buffer = $textview->get_buffer;
$window->add ($scroll);
$scroll->add ($textview);
$window->signal_connect (destroy => sub { Gtk2->main_quit });

open(IN, q^perl -e '$|++; for $i (0..9) { $sum+= $i; print "Line $i:
sum = $sum\n"; sleep 1;}'|^)
        or die "Failed running perl subprocess\n";

Glib::IO->add_watch ( fileno(IN), ['in', 'hup'], sub {
        my ($fileno, $condition) = @_;
        if ($condition eq 'hup') {
                warn "done\n";
                close IN;
                return 0;  # uninstall
        warn "reading...\n";
        my $line;
        sysread IN, $line, 1024;
        warn "read $line\n";
        $buffer->insert($buffer->get_end_iter, $line);
        return 1;




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]