use strict; use warnings; use Getopt::Long; use LWP::Simple; use List::MoreUtils qw(indexes); use Tk; use Tk::HList; use Tk::ItemStyle; use Tk::BrowseEntry; use Tk::Toplevel; use Tk::ROText; use Tk::Menubutton; #Input file parsing my ($user,$file,$other); my $licHash = {}; my ($tool,$issued,$use,$vendor,$feature); my $sec = 30; #000; GetOptions("u=s" => \$user, "f=s" => \$file); my $timer; my $others = []; unless (defined $user) { $user = $ENV{USER}; } # url hash my %url = ( report => "http://webdesk.com:8002/cache/report.txt", srs => "http://webdesk.com:8002/cache/srs.txt", ); unless (defined $file) { $file = "report"; #default to snps prod } my $selectfile = $file; # Making the GUI my $mw = new MainWindow; $mw->title("View"); $mw->geometry("560x250"); my $userframe = $mw->Frame(-width=>5,-height=>10)->pack(-side=>'top',-anchor=>'nw'); $userframe->Label(-text => "USER: $user")->pack(-side => 'left',-anchor => 'w',-padx => 0); $userframe->Label(-text => "Set time(sec)")->pack(-side => 'left',-anchor => 'w',-padx => 0); my $frequency = $userframe->Entry(-width=> 5,-textvariable=> \$sec)->pack(-side => 'left',-anchor => 'nw',-padx => 0); $userframe->Label(-text => "Select File")->pack(-side => 'left',-anchor => 'w',-padx => 0); $userframe->BrowseEntry( -state => 'normal', -choices => [keys %url], -variable => \$selectfile, -browsecmd => \&read_file, )->pack(-side=>'right',-anchor =>'e'); my $hlistframe = $mw->Frame()->pack(-fill => 'both',-expand=>1); my $hl; my $bottomframe = $mw->Frame()->pack(-fill => 'both', -expand => 1); $bottomframe->Button(-text => "Display File",-command => \&dumpOnTerminal)->pack(-side=>'right',-anchor => 'se',-fill=>'both'); my ($general,$general_nw, $allok ,$allok_nw,$alert,$alert_nw,$cautious,$cautious_nw,$gray); my ($label1,$label2,$label3,$label4,$label5,$label6,$label7); sub dumpOnTerminal { } sub create_hlist { $hl = $hlistframe->Scrolled('HList', -scrollbars => 'ose', -columns =>7 , -header => 1, -width => 100, -command => sub {print "AAA\n";}, )->pack(-fill => 'both',-expand =>1 ); $label1 = $hl->Label(-text => "Tool", -anchor => 'w'); $hl->headerCreate(0,-itemtype => 'window',-widget => $label1) ; $label2 = $hl->Label(-text => "Vendor", -anchor => 'w'); $hl->headerCreate(1,-itemtype => 'window',-widget => $label2); $label3 = $hl->Label(-text => "Available", -anchor => 'w'); $hl->headerCreate(2,-itemtype => 'window',-widget => $label3); $label4 = $hl->Label(-text => "num.", -anchor => 'w'); $hl->headerCreate(3,-itemtype => 'window',-widget => $label4); $label5 = $hl->Label(-text => "usage%", -anchor => 'w'); $hl->headerCreate(4,-itemtype => 'window',-widget => $label5); $label6 = $hl->Label(-text => "user", -anchor => 'w'); $hl->headerCreate(5,-itemtype => 'window',-widget => $label6); $label7 = $hl->Label(-text => "user%", -anchor => 'w'); $hl->headerCreate(6,-itemtype => 'window',-widget => $label7); $general = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'center'); $general_nw = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw'); $allok = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'center',-background =>'green'); $allok_nw = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'green'); $alert = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'center',-background =>'red'); $alert_nw = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'red'); $cautious = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'center',-background =>'yellow'); $cautious_nw = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'yellow'); $gray = $hl->ItemStyle('text', -selectforeground =>'black', -anchor =>'nw',-background =>'gray'); } showData(); $mw->after($sec*1000, \&clearAndLoadData); MainLoop; sub read_file { # download the file from the url and extract info } sub showData { &read_file(); &create_hlist(); } sub clearAndLoadData { my $value = ${$frequency->cget(-textvariable)}; $hl->destroy; read_file(); &create_hlist(); my $path = 0; my @keys = keys %$licHash; my $pos = indexes {$keys[$_] eq $user } 0 ..$#keys; if($pos){ splice @keys,$pos,1; unshift @keys , $user; } foreach my $key (@keys) { for my $tool (sort keys %{$licHash->{$key}}) { # _insertData($path,$tool,$key); $path++; } } # make a lower bound for timer # in case your user sets $sec to 0 if( $sec < 1){ $sec = 1 } # reinstall 1 shot timer for another run $mw->after( $sec*1000, \&clearAndLoadData); } sub _insertData { # some itemCreate statements here } MainLoop;