#!/usr/bin/perl use strict; use warnings FATAL => 'all'; use Gtk2 '-init'; use Gtk2::Ex::TextView::FollowAppend; use IPC::Run qw( start pump finish timeout ); use FindBin qw($Bin); my $window = Gtk2::Window->new; $window->set_title('Diabytes meters downloader'); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); $window->set_border_width(3); my $vbox = Gtk2::VBox->new(0, 6); $window->add($vbox); my $frame = Gtk2::Frame->new('Buttons'); $vbox->pack_start($frame, 1, 1, 0); $frame->set_border_width(3); my $hbox = Gtk2::HBox->new(0 ,6); $frame->add($hbox); $hbox->set_border_width(3); my $incButton = Gtk2::Button->new('_Click Me'); $hbox->pack_start($incButton, 0 , 0, 0); my $quitButton = Gtk2::Button->new('_Quit'); $hbox->pack_start($quitButton, 0, 0 , 0); $quitButton->signal_connect( clicked => sub { Gtk2::main_quit(); }); my $scrolled = Gtk2::ScrolledWindow->new; $scrolled->set_policy('never', 'always'); $vbox->pack_start($scrolled, 1,1,0); my $textBuffer = Gtk2::TextBuffer->new(); $incButton->signal_connect( clicked => sub { &makeSomeNoise($textBuffer); }); my $textView = Gtk2::Ex::TextView::FollowAppend->new_with_buffer($textBuffer); $textView->set(wrap_mode => 'char', editable => 0); $scrolled->add($textView); $window->set_default_size(500, 250); $window->set_position('GTK_WIN_POS_CENTER'); $window->show_all; Gtk2->main; sub makeSomeNoise { my $textBuff = shift; # IPC::Run setup my $file = File::Spec->catfile($Bin, 'somefile.txt'); my $timeFile = File::Spec->catfile($Bin, 'downloadsession.tm'); my $scriptFile = File::Spec->catfile($Bin, 'downloadsession.out'); my @cat = ('cat', $file); #my @command = qw(scriptreplay -t downloadsession.tm -s downloadsession.out); my @command = ('scriptreplay', '-t', $timeFile, '-s', $scriptFile); my ($in, $out, $err, $t); #my $h = start( \@cat, \$in, \$out, $t = timeout( 180 ) ); my $h = start( \@command, \$in, \$out, $t = timeout( 180 ) ); while ($h->pump) { #&refreshTextBuffer($textBuffer, $out); #$textBuff->set_text($out); #print($out); } $h->finish(); }