use strict;
use Tk;
use Threads;
my ($mw,$sent_recvd_listbox,$server_list_listbox);
threads->new(\&update_thread)->detach;
create_tk_window();
$mw->MainLoop;
sub update_thread {
print "update_thread called...\n";
while(1) {
if(defined($server_list_listbox)) {
# This never gets executed because the objects from
# the tk module are out of scope ??????
$server_list_listbox->insert('end',"Some string data");
}else{
print "Couldn't insert any data cause this thread can't see the tk objects !?\n";
}
sleep 1;
}
exit();
}
sub create_tk_window {
$mw=MainWindow->new
(
-background=>'#dedede',
-foreground=>'yellow',
-title=>"FingerLick"
);
$mw->geometry("802x618");
$mw->minsize(802,618);
$mw->maxsize(802,618);
$sent_recvd_listbox=$mw->Listbox
(
-height=>1,
-width=>60,
-background=>'black',
-foreground=>'yellow'
)->pack(-side=>'bottom',-anchor=>'s',-pady=>2);
$server_list_listbox=$mw->Scrolled
(
"Listbox",
-height=>20,
-width=>60,
-background=>'white',
-foreground=>'black',
-scrollbars=>'se',
)->pack();
}
####
my $wt_display_code:shared;
my $wt_data:shared;
$mw->repeat(0.001,sub { display_worker_data() });
####
my $wt_display_code:shared;
my $wt_data:shared;
$mw->repeat(0.001,sub { display_worker_data() });
sub display_worker_data() {
if($wt_display_code eq "SENT_RECVD") {
my $data_for_display="Sent recvd: $wt_data";
$sent_recvd_listbox->insert('end',$data_for_display");
}elsif($wt_display_code eq "TIME_STATUS") {
my $data_for_display="Time: $local_time";
$time_stats_listbox->insert('end',"$data_for_display");
}elsif(...) {
...
}elsif(...) {
...
} etc...
}