#!/usr/bin/perl -w use strict; use Tk; use Tk::Zinc; use Proc::ProcessTable; my $title = time(); my $xtermparentpid; my $pttydev; my $id; my $count = 0; my $mw = MainWindow->new(); my $zinc = $mw->Zinc(-backcolor => 'gray', -relief => 'sunken', -width => 400, -height => 300)->pack(-expand => 1, -fill => 'both'); my $xtermWidth = 300; my $xtermHeight = 200; ## this Frame is needed for including the xterm in Tk::Zinc my $xtermContainer = $zinc->Frame(-container => 1); my $xtid = $xtermContainer->id(); # converting the id from HEX to decimal as xterm requires a decimal Id my ($xtId) = sprintf hex $xtid; my $label = $zinc->add('text', 1, -text => "Hide xterm", -position => [150, 30]); my $dcontitem = $zinc->add('window', 1, -window => $xtermContainer, -position => [50, 75], -width => $xtermWidth+4, -height => $xtermHeight+4, -visible => 1); $zinc->bind($label, '<1>', \&hideShow); sub hideShow { if ($zinc->itemcget($label, -text) =~ /Hide/) { $zinc->itemconfigure($label, -color => 'yellow', -text => "Show xterm"); $zinc->itemconfigure($dcontitem, -visible => 0); } else { $zinc->itemconfigure($label, -color => 'black', -text => "Hide xterm"); $zinc->itemconfigure($dcontitem, -visible => 1); } } my $width = $xtermWidth/10; my $height = $xtermHeight/20; system("xterm -T $title -fn 10x20 -geometry ${width}x${height} -into $xtId &"); my $button = $mw->Button(-text => "Start", -command => \&do_slave_write)->pack(); my $exit = $mw->Button(-text => "Exit", -command => sub{Tk::exit})->pack(); MainLoop(); sub do_slave_write{ $button->configure(-text => 'Stop', -command => \&do_slave_stop); $mw->update; my $t = new Proc::ProcessTable; foreach my $p (@{$t->table}) { if($p->cmndline =~ /$title/){$xtermparentpid = $p->pid} } foreach my $p (@{$t->table}) { if($p->ppid == $xtermparentpid){$pttydev = $p->ttydev} } open(FH,">$pttydev") or warn $!; $id = Tk::After->new($mw,1000,'repeat', sub{print STDOUT $count,"\n"; print FH $count.'a',"\n";$count++}); } sub do_slave_stop{ $id->cancel; $button->configure(-text => 'Start', -command => \&do_slave_write); $mw->update; # $count=0; close FH; #to reset count }