Well, I stripped a lot of stuff out of the leaving just the Tk stuff.
I hope it makes some sense
use strict;
use warnings;
use Tk;
use Tk::Dialog;
use Tk::HList;
use Tk::ItemStyle;
my @AllFields = (
{db => 'NAME', text => 'Name', all => 1, button => undef},
{db => 'TOOL_CLASS', text => 'Class', all => 1, button => undef},
{db => 'TOOL_ID', text => 'ID', all => 0, button => undef},
{db => 'OBJECTTYPE', text => 'Type', all => 0, button => undef},
{db => 'IS_2X_TOOL', text => '2X', all => 1, button => undef},
{db => 'COMMAND_LINE', text => 'Command Line', all => 1, button => undef},
);
my $mw = tkinit(-title => $toolLabel);
$mw->fontCreate('normal', -family => 'Helvetica', -size => 9);
$mw->fontCreate('option', -family => 'Helvetica', -size => 9);
$mw->fontCreate('button', -family => 'Helvetica', -size => 11, -weight => 'normal');
$mw->fontCreate('error', -family => 'Helvetica', -size => 11, -weight => 'bold');
$mw->fontCreate('colhead', -family => 'Helvetica', -size => 10, -weight => 'bold');
$mw->fontCreate('bold', -family => 'Helvetica', -size => 9, -weight => 'bold');
$mw->fontCreate('italic', -family => 'Helvetica', -size => 9, -slant => 'italic');
$mw->optionAdd('*font' => 'normal');
DisplayWindow();
MainLoop;
exit(0);
#==========================================================================
sub DisplayWindow {
#==========================================================================
my($row, $col);
my $fl = $mw->Frame->pack(-anchor => 'w');
$fl->Label(-textvariable => \$RecordCount)->pack(-side => 'left');
$HL = $mw->Scrolled('HList',
-header => 1,
-columns => scalar(@AllFields),
-selectmode => 'extended',
-scrollbars => 'osoe',
-exportselection => 1,
)->pack(-expand => 1, -fill => 'both');
$mw->bind('all', '<MouseWheel>',
[sub{ $HL->yview('scroll', -($_[1] / 120) * 3, 'units') }, Ev('D')],
);
my $f = $mw->Frame()->pack(-fill => 'x');
my $f0 = $f->Frame(-bd => 2, -relief => 'groove')->pack(-side => 'left', -padx => 8, -pady => 6, -ipady => 6);
for (0 .. $#AllFields) {
my $b = $HL->Button(
-text => $AllFields[$_]->{text},
-command => [\&ListTools, 0, $_],
-font => 'colhead',
-relief => 'flat',
);
$HL->headerCreate($_, -itemtype => 'window', -window => $b);
push(@Headers, $b);
$AllFields[$_]->{button} = $b;
}
$Headers[0]->configure(-fg => $HeaderHilite);
my $fRight = $f->Frame->pack(-side => 'left', -fill => 'both', -pady => 8);
my $fbut = $fRight->Frame->pack(-fill => 'x', -pady => 8);
$QueryButton = $fbut->Button(
-text => 'Query',
-command => [\&ListTools, 1, 0],
-width => 10,
-font => 'button',
)->pack(-side => 'left', -padx => 20);
$ExitButton = $fbut->Button(
-text => 'Exit',
-command => [$mw, 'destroy'],
-width => 10,
-font => 'button',
)->pack(-side => 'right', -anchor => 'e', -padx => 20);
$fRight->Label(
-font => 'error',
-fg => '#C00000',
-anchor => 'w',
-textvariable => \$ErrorMessage,
)->pack(-fill => 'x', -pady => 8);
}
#==========================================================================
sub ListTools {
#==========================================================================
my(
$query,
$sortBy,
) = @_;
#==========================================================================
$ErrorMessage = '';
$mw->update;
@Records = ();
for each record
extract fields from database and put them in @f
push(@Records, \@f);
}
@Records = sort { lc($a->[$sortBy]) cmp lc($b->[$sortBy]) } @Records;
$_->configure(-fg => '#000000') for @Headers;
$Headers[$sortBy]->configure(-fg => $HeaderHilite);
$HL->delete('all');
OutputData($HL);
$mw->update;
}
#==========================================================================
sub OutputData {
#==========================================================================
my(
$hlistWidget,
) = @_;
#==========================================================================
for (0 .. $#AllFields) {
my $b = $AllFields[$_]->{button};
$b->configure(-text => ($Params{misc_all_objects} or $AllFields[$_]->{all}) ? $AllFields[$_]->{text} : '') if $b;
}
my $r = 0;
for my $rec (@Records) {
$hlistWidget->add($r);
for (0 .. $#AllFields) {
my $text = $rec->[$_] || '';
my $style = $Styles{left}->[$r & 1];
$hlistWidget->itemCreate($r, $_, -text => $text, -style => $style);
}
$r++;
}
}
__END__