#!perl
use strict;
use warnings;
use 5.010;
use Tk;
printf "Tk::VERSION %s\n",$Tk::VERSION;
# Declarations
my $breed = 400; # width
my $hoog = 200; # height
my $netspdx = 1;
my $netspdy = 0;
my $netuse = 0.05;
my $fsizex = 3;
my $fsizey = 0;
my $mw = new MainWindow(
-height => $hoog,
-width => $breed,
-title => 'Downloadtime estimator'
);
init();
MainLoop;
sub init {
my $center = $breed/2;
my @col = (40,$center-35,$center+30,$breed-40);
my @row = (20,40,60,80,90,110);
my @speed = ( undef,
['Gb',1000000000],
['Mb',1000000],
['kb',1000],
);
my @button = ();
# Row 0
my $y = $row[0];
$mw->Label(-text=>"Fill in the fields and check the right boxes")
->place( -x=>$center, -y=>$y, -anchor=>'center' );
# Row 1
$y = $row[1];
$mw->Label(-text=>"Network speed")
->place( -x=>$col[0], -y=>$y, -anchor=>'w' );
$mw->Entry( -justify=>'right',-textvariable=> \$netspdx, -width=>5 )
->place( -x=>$center, -y=>$y, -anchor=>'center' );
my $x = $col[2];
for my $i (1..3){
$button[$i] = $mw-> Radiobutton(
-variable=> \$netspdy,
-text => $speed[$i][0],
-value => $speed[$i][1])
-> place( -x =>$x, -y=>$y, -anchor=>'w' );
$x += 50;
}
$button[1]->select();
# Row 2
$y = $row[2];
$mw->Label( -text=>"Avg network use in %" )
->place( -x=>$col[0], -y=>$y, -anchor=>'w' );
$mw->Entry( -textvariable=> \$netuse, -width => 5, -justify => 'righ
+t', )
->place( -x=>$center, -y=>$y, -anchor=>'center' );
# Row 3
$y = $row[3];
$mw->Label( -text=>"File size" )
+
->place( -x=>$col[0], -y=>$y, -anchor=>'w' );
$mw->Entry(
-textvariable=> \$fsizex,
-width => 5,
-justify=>'right'
)
->place( -x=>$center, -y=>$y, -anchor=>'center' );
$x = $col[2];
for my $i (1..3){
$button[$i+3] = $mw-> Radiobutton(
-variable=> \$fsizey,
-text => uc $speed[$i][0],
-value => $speed[$i][1])
->place( -x=>$x, -y=>$y, -anchor=>'w' );
$x += 50;
}
$button[4]->select();
# Row 5
$y = $row[5];
$mw->Label( -text=>"Estimated time" )
->place( -x=>$col[0], -y=>$y, -anchor=>'w' );
my $result = $mw->Label( -text=>'' )
->place( -x=>$center, -y=>$y, -anchor=>'center' );
my $units = $mw->Label( -text=>'' )
->place( -x=>$col[2], -y=>$y, -anchor=>'w' );
# Row 6
$y = $hoog-50;
# OK button
$mw->Button( -text => "Okay",
-width => 10,
-command => [\&Calc,$result,$units] )
->place( -x=>$center-100, -y=>$y );
# Exit button
$mw->Button(-text => "Exit",
-width => 10,
-command => sub { exit })
->place( -x=>$center+100, -y=>$y );
}
sub Calc {
my ($result,$units) = @_;
my $time = $fsizex*$fsizey / ($netspdx*$netspdy/100*$netuse);
my $text = 'Seconds';
if ($time > 60){
$time = $time / 60;
$text = 'Minutes';
if ($time > 60){
$time = $time / 60;
$text = 'Hours';
if ($time > 24){
$time = $time / 24;
$text = 'Days';
}
};
}
$units->configure(-text=>$text);
$result->configure(-text=>sprintf "%.2f",$time);
};