fang0654 has asked for the wisdom of the Perl Monks concerning the following question:
Then I would run the system commands with the following:# Code to open the filehandle my $fh = FileHandle->new(); open ($fh, "tail -f /usr/rip/cdimport.log |"); # Code to draw the actual textview $frame = Gtk2::Frame->new('Console Window'); my $ctextBox = Gtk2::TextView->new; my $cscroll = Gtk2::ScrolledWindow->new; my $cevent_box = Gtk2::EventBox->new; $color = Gtk2::Gdk::Color->parse ("black"); $cevent_box->modify_bg ('normal', $color); my $calign = Gtk2::Alignment->new (0.5, 0.5, 1.0, 1.0); $calign->set_border_width (1); $cevent_box->add ($calign); $calign->add ($ctextBox); $cscroll->add($cevent_box); my $cbuffer = $ctextBox->get_buffer; my $cend_mark = $cbuffer->create_mark( 'end', $cbuffer->get_end_iter, +FALSE ); $cbuffer->signal_connect( insert_text => sub { $ctextBox->scroll_to_mark( $cend_mark, 0.0, TRUE, 0.0, 0.0 ); } ); $frame->add($cscroll); $box1->pack_end($frame, TRUE, TRUE, 0); $ctextBox->set_buffer($cbuffer); $ctextBox->set_editable(FALSE); $cbuffer->set_text("Console window"); # Code to set up the watch on the opened filehandle my $ctag; $ctag = Gtk2::Helper->add_watch ( $fh->fileno, 'in', sub { watch_console ($ctag, $fh, $cbuffer) } ); sub watch_console { my ($fd, $fh, $buffer) = @_; my $sysbuffer; if ( not sysread($fh, $sysbuffer, 4096) ) { # obviously the connected pipe was closed Gtk2::Helper->remove_watch ($fd) or die "couldn't remove watcher"; close($fh); return 1; } $buffer->set_text($sysbuffer); return 1; }
This works, to an extent. The refresh of the textview is slow and fragmented. Any suggestions on a better implementation?BTW, I know that the scrollview doesn't work in the above piece of code - I'll figure that one out next.system("find /tmp/$id/ -iname \"*.wav\" -print0 | xargs -0 -n +1 -I '{}' ffmpeg -i '{}' -f mp3 '{}'.mp3 2>> /usr/rip/cdimport.log")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Realtime update of a textbuffer from STDOUT/STDERR in Gtk2
by zentara (Cardinal) on Aug 31, 2007 at 16:51 UTC | |
|
Re: Realtime update of a textbuffer from STDOUT/STDERR in Gtk2
by almut (Canon) on Aug 31, 2007 at 16:51 UTC | |
|
Re: Realtime update of a textbuffer from STDOUT/STDERR in Gtk2
by fang0654 (Initiate) on Aug 31, 2007 at 18:02 UTC | |
by zentara (Cardinal) on Aug 31, 2007 at 19:12 UTC | |
by fang0654 (Initiate) on Aug 31, 2007 at 20:05 UTC |