Jorge,
AFAIK, the UNIX 'tail' command is not available on Win32. I have never used
Win32::ChangeNotify, but I doubt it would be compatible with Tk, as events
need to be processed while signals are being received. This likely does not
bode well (although, like I said, I haven't tried it).
I suggest using the 'repeat' method of Tk to poll the file for any changes.
Just use the stat command to get the last time the file was modified to make
sure it has changed, before you do all your parsing.
I have significantly changed your code to use the pack geometry manager,
deleted anything which had no functionality (ProgressBar, et al), and fixed
up your 'About' Code. You were creating a new Dialog 'every' time it got
called !
I think you need to read up a bit more on Tk, concentrating on geometry
management (place is likely overkill) and the types of widgets available to
you. Make good use of the demos and the widget program which come with the
distribution.
I include a working sample below, using your CYGWIN_SYSLOG.TXT file you
sent:
######################################
#!/usr/bin/perl -w
use Tk;
#---------------- User Defined Declarations -----------------
my $status_var = 0;
my $lw=40; #width of labels
my $ethernet_address ='Ceci est un test'; #fixed for now
my $IP_address; #self-explanatory
my $client_name; #as is this
my $boot_file; #another -textvariable to be used
my $install_file_path;
my $SYSLOG='C:/CYGWIN_SYSLOG.TXT'; #your file to be parsed
my $dialog; #declare here, not in the sub
my $msdelay=5000; #5 second delay..until callback
my $mtime=1; #initialize to something other than $thistime
my $thistime=0; #variable to hold current 'stat' check
#------------------------ Main Program -----------------------
my $mw = MainWindow->new( -title => "Serveur d'installation "
);
$mw->geometry('570x377');
&makemenu;
&makelabels;
$mw->repeat($msdelay,[\&check_syslog,$SYSLOG]);
MainLoop;
#------------------------ Subroutines ------------------------
sub makelabels
{
$mw->Label(-text => 'Client Ethernet adress')->pack(-anchor=>'w');
my $label1=$mw->Label(-relief=>'sunken',
-textvariable=>\$ethernet_address,
-width=>$lw,
-anchor=>'w',
-bg=>'white')->pack(-anchor=>'w');
$mw->Label(-text=> 'Client IP address')->pack(-anchor=>'w');
my $label2=$mw->Label(-relief=>'sunken',
-textvariable=>\$IP_address,
-width=>$lw,
-anchor=>'w',
-bg=>'white')->pack(-anchor=>'w');
$mw->Label(-text=> 'Client Name')->pack(-anchor=>'w');
my $label3=$mw->Label(-relief=>'sunken',
-textvariable=>\$client_name,
-width=>$lw,
-anchor=>'w',
-bg=>'white')->pack(-anchor=>'w');
$mw->Label(-text=> 'Boot File')->pack(-anchor=>'w');
my $label4=$mw->Label(-relief=>'sunken',
-textvariable=>\$boot_file,
-width=>$lw,
-anchor=>'w',
-bg=>'white')->pack(-anchor=>'w');
$mw->Label(-text=> 'Installation File Path')->pack(-anchor=>'w');
my $label5=$mw->Label(-relief=>'sunken',
-textvariable=>\$install_file_path,
-width=>$lw,
-anchor=>'w',
-bg=>'white')->pack(-anchor=>'w');
}
sub check_syslog
{
my ($f)=@_;
$thistime=(stat($f))[9];
return if ($thistime == $mtime);
$mtime=$thistime;
my $dummy;
open (FILE, $f) || warn "Couldn't open file $f: $!";
@lines=<FILE>;
close (FILE);
($dummy, $IP_address, $read, $status)=split(":",$lines[$#lines-2]);
$IP_address=~s/^\s*(.*)\s*$/$1/;
($client_name)=split(/\./,$IP_address);
$read=~/.*bootp(.*)\s*/;
$boot_file=$1;
}
#------------------------ SUBROUTINE makemenu -------------------------
sub makemenu{
my $menubar = $mw->Menu(-type => 'menubar',
-relief=>'flat');
$mw->configure(-menu => $menubar);
my $mnu0 = $menubar->cascade(-label => 'Control',
-tearoff => 0,
-font => "Arial 8 normal"
);
$mnu0->command( -label => 'Quitter',
-accelerator => 'Q',
-font => "Arial 8 normal",
-command =>sub{$mw->destroy()});
$mnu0->separator();
my $mnu1 = $menubar->cascade(-label => '~Options',
-tearoff => 0,
-font => "Arial 8 normal"
);
my $cc = $mnu1->cascade(-label=>'~Language');
$cc-> checkbutton (-label=>'Generic Alcatel', -variable => \$GENERIC);
$cc-> checkbutton (-label=>'French', -variable => \$FRENCH);
my $cc2 = $mnu1->cascade(-label=>'~Drive');
$cc2-> checkbutton (-label=>'A', -variable => \$A);
$cc2-> checkbutton (-label=>'B', -variable => \$B);
$cc2-> checkbutton (-label=>'C', -variable => \$C);
$cc2-> checkbutton (-label=>'D', -variable => \$D);
$cc2-> checkbutton (-label=>'E', -variable => \$E);
$cc2-> checkbutton (-label=>'F', -variable => \$F);
$cc2-> checkbutton (-label=>'G', -variable => \$G);
$cc2-> checkbutton (-label=>'H', -variable => \$H);
$cc2-> checkbutton (-label=>'I', -variable => \$I);
$mnu1->separator();
my $mnu2 = $menubar->cascade(-label => 'Alcatel',
-tearoff => 0,
-font => "Arial 8 normal"
);
$mnu2->command( -label => 'About',
-accelerator => 'A',
-font => "Arial 8 normal",
-command =>sub{about()}
);
} #end sub makemenu
sub about {
unless (Exists($dialog)){
require Tk::Dialog;
$dialog =$mw-> Dialog( -title => 'About',
-text => "Server d'installation Alcatel Business Systems\n"
. "$VERSION\n " .
"Written by Jorge Goncalves, " .
"goncal11\@col.bsf.com",
-font => "Arial 8 normal",
-justify => 'center',
-default_button => 'Ok!',
-bitmap =>'info',
-buttons => [qw/Ok!/] );
}
$dialog->Show;
} #end sub dialog
__END__
##########################################
Regards,
Jack
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users