#!Perl #$^W = 1; # is there a reason why you don't just use warnings? use strict; use warnings; use Tk; use Tk::BrowseEntry; use Cwd; use List::Util qw(shuffle); #Declarations# my $VERSION = 2.7; my $loadhistory = 0; my $sort_cnt = 3; my ($ftp, $port, $after_id,); my $cwd = cwd; my $mw = MainWindow->new( -relief => 'raised', -bd => 2, ); $mw->title("Asociacion de Agentes Aduanales de Matamoros --- Validacion Automatica"); $mw->geometry("1024x764+4+25"); # Make all your widget groups my $entry = Build_User_Entry($mw); my $dd = Build_Dropdown($mw); my $box1 = Build_Listbox_One($mw); my $box2 = Build_Listbox_Two($mw); my $button = Build_Exit_Button($mw); # Lay them out - use only one geometry manager per containing frame. $entry->grid( -columnspan => 2 ); $dd->grid( -columnspan => 2 ); $box1->grid( $box2 ); $button->grid( -columnspan => 2 ); # Start monitoring my ($enviados, $respuestas) = Start_Directory_Monitors( $mw, $box1, $box2 ); MainLoop(); ################################################### # Build widgets sub Build_User_Entry { my $mw = shift; my $f = $mw->Frame(); my $label_wert = $f->Label( -text => 'Tu respuesta :', )->pack( -side => 'left', ); my $entry_wert = $f->Entry( -width => 20, )->pack( -expand => 1, -fill => 'y', ); return $f; } sub Build_Dropdown { my $mw = shift; my $f = $mw->Frame(); my $label_text = "nothing selected"; my $dropdown_value; my $showlabel = $f->Label( -textvariable => \$label_text, ); my $dropdown = $f->BrowseEntry( -label => "Label", -variable => \$dropdown_value, -browsecmd => sub { $label_text = "Ha seleccionado: $dropdown_value"; }, ); # Populate dropdown with values foreach ( qw/Enviados Recibido Errores/ ) { $dropdown->insert('end', $_); } # Set the initial value for the dropdown $dropdown_value = "Enviados"; $showlabel->pack; $dropdown->pack; return $f; } sub Build_Listbox_One { my $mw = shift; my $box1 = $mw->Scrolled( 'Listbox', -scrollbars => 'e', -relief => 'sunken', -height => 5, -setgrid => 0, ); return $box1; } sub Build_Listbox_Two { my $mw = shift; my $box2 = $mw->Scrolled( 'Listbox', -scrollbars => 'e', -relief => 'sunken', -height => 5, -setgrid => 0, ); return $box2; } sub Build_Exit_Button { my $mw = shift; my $button = $mw->Button( -text => "Salir", -command => sub { exit }, ); return $button; } ############################################################## sub Start_Directory_Monitors { my $mw = shift; my $enviados_display = shift; my $respuesta_display = shift; my $env = $mw->repeat(5000, [ \&list_dir_enviados, $enviados_display ] ); my $res = $mw->repeat(5000, [ \&list_dir_respuesta, $respuesta_display ] ); return $env, $res; } # monitor enviados sub list_dir_enviados { my $box = shift; $box->delete(0,'end'); # empty listbox #my @items = glob "c:/AAAvalida/valida/enviados/*.*"; my @items = shuffle qw(One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve); foreach (@items) { $box1->insert('end', $_); } } # monitor respuestas sub list_dir_respuesta { my $box = shift; $box->delete(0,'end'); # empty listbox #my @items = glob "c:/AAAvalida/valida/respuestas/*.*"; my @items = shuffle qw(One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve); foreach (@items) { $box->insert('end', $_); } } #########################################################################