All I'm saying, is watch for memory gains, and do it often, before your script gets too complex.
#!/usr/bin/perl use strict; use Tk; use Tk::HList; use YAML; #use MeM; #demonstrates the internal counter of HList #and why it is better to reconfigure entries #rather than deleting them and adding new my $mw = MainWindow->new(); #create some sample data my %data; foreach (0..100) { $data{$_}{'name'} = 'name'.$_.rand(1000);; $data{$_}{'id'} = rand(time); } #get random list of keys my @keys = keys %data; ################# my $h = $mw->Scrolled( 'HList', -header => 1, -columns => 2, -width => 50, -height => 60, -takefocus => 1, -background => 'steelblue', -foreground =>'snow', -selectmode => 'single', -selectforeground => 'pink', -selectbackground => 'black', # -browsecmd => \&browseThis, )->pack(-side => "left", -anchor => "n"); my $nameh = $h->header('create', 0, -text => ' Name ', -borderwidth => 3, -headerbackground => 'steelblue', -relief => 'raised'); my $idh = $h->header('create', 1, -text => ' ID ', -borderwidth => 3, -headerbackground => 'lightsteelblue', -relief => 'raised'); foreach (@keys) { my $e = $h->addchild(""); #will add at end $h->itemCreate ($e, 0, -itemtype => 'text', -text => $data{$_}{'name'}, ); $h->itemCreate($e, 1, -itemtype => 'text', -text => $data{$_}{'id'}, ); } my $button = $mw->Button(-text => 'exit', -command => sub{exit})->pack; my $buildbut = $mw->Button(-text => 'rebuild list', -command => [\&rebuild] )->pack; my $dumpbut = $mw->Button(-text => 'Dump', -command => sub{ my @entries = $h->info('children'); foreach my $entry(@entries){ print Dump([\$entry]),"\n"; } } )->pack; MainLoop; ######################################################### sub rebuild{ my @entries = $h->info('children'); foreach my $entry(@entries){ $h->delete('entry',$entry); } foreach (0..100) { $data{$_}{'name'} = 'name'.$_.rand(1000); $data{$_}{'id'} = rand(time); } #get random list of keys my @keys = keys %data; foreach (@keys) { my $e = $h->addchild(""); #will add at end $h->itemCreate ($e, 0, -itemtype => 'text', -text => $data{$_}{'name'}, ); $h->itemCreate($e, 1, -itemtype => 'text', -text => $data{$_}{'id'}, ); } $mw->update; }
In reply to Re: Auto-refreshing Perl TK HLists/Tables
by zentara
in thread Auto-refreshing Perl TK HLists/Tables
by GriffinP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |