Re: Gtk2::Helper or Glib::IO event watcher problem
- From: muppet <scott asofyet org>
- To: Vyacheslav Dikonov <sdiconov mail ru>
- Cc: gtk-perl-list gnome org
- Subject: Re: Gtk2::Helper or Glib::IO event watcher problem
- Date: Tue, 22 Mar 2005 08:33:00 -0500
On Mar 22, 2005, at 5:45 AM, Vyacheslav Dikonov wrote:
I need to write a perl script that would act as a frontend to another
perl
script and show its console output in a non-locking "realtime" manner.
The
backend script does a lengthy job and outputs some messages via print
"message\n"; . I want these messages to be received, parsed and
visualised
by the frontend.
It does sound like a FAQ, but unfortunately the FAQ did not help me.
hmmm. there appears to be an html problem in the FAQ.
my $line = ;
the "<IN>" has been eaten by the browser.
i dropped that into the snippet you posted and it worked fine. in
fact, it wouldn't compile without it.
Is there any other way to implement event based pipe reading with
Perl::Gtk2?
you could use Glib::IO->add_watch() directly; Gtk2::Helper is a wrapper
that makes it behave more like the old Gtk-Perl.
This worked for me:
#!/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->show_all;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
open(IN, q^perl -e '$|++; for($i=0;$i<10;$i++) { $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;
});
Gtk2->main;
--
I don't have a drinking problem,
'cept when i can't get drink.
-- Tom Waits
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]