ashervin has asked for the wisdom of the Perl Monks concerning the following question:
I have a pipe delimited file containing lines consisting of various record types. The number of fields in these records are variable. There can be up to 9 different record types. The file begins with lines consisting of the header data for the record types. I currently can view this data within Excel, but would like to have a Perl Tk application that mimics Excel's "Freeze Row" feature.
I have settled on 2 Scrolled Panes and grid layout to accomplish this. Using Frames, I am able to equate the grid cell widths in the header and data frames using gridColumnconfigure(). But I cannot scroll the data using frames. Calling $mw->idletasks was the trick that allowed this to work.
Using Panes, this does not work -- the widths of the cells do not align (lines 75-90 below). Also, lines 25 - 27 do not appear to gang the horizontal slider bars together. Sliding the data frame x scrollbar has no impact on the header frame. What gives, mon friar?
1 #!/usr/bin/perl -- 2 3 use warnings; 4 use strict; 5 use Tk; 6 7 require Tk::Pane; 8 9 my $mw = MainWindow->new(); 10 $mw->geometry("1400x900"); 11 12 #my $mainFrame = $mw->Frame(); 13 14 my $headFrame = $mw->Scrolled('Pane', 15 -scrollbars => 'se', 16 -height=>30, 17 -width=>1300, 18 -bg=>'orange')->grid( -row => 0, -column => 0); 19 my $dataFrame = $mw->Scrolled('Pane', 20 -scrollbars => 'se', 21 -height=>700, 22 -width=>1300, 23 -bg=>'gray')->grid( -row => 4, -column => 0); 24 25 my $horiz = $dataFrame->Subwidget('xscrollbar'); 26 $horiz->configure(-command => 27 sub { $dataFrame->xview(@_); $dataFrame->xview(@_) }); 28 29 open my $dataFH, "<", $ARGV[0] or die "Could not open $ARGV[0]"; 30 my $row = 0; 31 my $hRow = 0; 32 while(!eof $dataFH) 33 { 34 my $data=readline($dataFH); 35 my @dataArr = split '\|', $data; 36 my $column = 0; 37 my $bg='gray'; 38 if($dataArr[0] =~ m/^Record/) 39 { 40 $bg='orange'; 41 foreach my $field (@dataArr) 42 { 43 my $label = $headFrame->Label(-height=>2, 44 -bg=>$bg, 45 -fg=>'black', 46 -text => $field, 47 -relief => 'ridge'); 48 $label->grid( -sticky=> 'ew', 49 -row => $hRow, 50 -column => $column++); 51 } 52 $hRow++; 53 } 54 else 55 { 56 foreach my $field (@dataArr) 57 { 58 my $label = $dataFrame->Label(-height=>2, 59 -bg=>$bg, 60 -fg=>'black', 61 -text => $field, 62 -relief => 'ridge'); 63 $label->grid( -sticky=> 'ew', 64 -row => $row, 65 -column => $column++); 66 } 67 $row += 1; 68 } 69 } 70 $mw->idletasks; 71 72 my ($columns, $rows) = $dataFrame->gridSize(); 73 74 my $cnt=0; 75 while($cnt < $columns) 76 { 77 my ($arg1, $arg2, $width, $arg4) = 78 $dataFrame->gridBbox($cnt, 4); 79 my( $arg1a, $arg2a, $hWidth, $arg4a) = 80 $headFrame->gridBbox($cnt, 0); 81 if($hWidth > $width) 82 { 83 $dataFrame->gridColumnconfigure($cnt, -minsize=>$hWidth); 84 } 85 else 86 { 87 $headFrame->gridColumnconfigure($cnt, -minsize=>$width); 88 } 89 $cnt++; 90 } 91 92 $mw->MainLoop;
This is cygwin perl -- perl5 (revision 5 version 22 subversion 3). My company has its own distro and has host machines locked down.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Tk Gang together two Scrolled Panes
by tybalt89 (Monsignor) on Nov 29, 2018 at 16:19 UTC | |
by ashervin (Novice) on Nov 29, 2018 at 17:10 UTC | |
by tybalt89 (Monsignor) on Nov 29, 2018 at 17:37 UTC | |
|
Re: Perl Tk Gang together two Scrolled Panes
by tybalt89 (Monsignor) on Nov 29, 2018 at 17:54 UTC | |
|
Re: Perl Tk Gang together two Scrolled Panes
by zentara (Cardinal) on Nov 29, 2018 at 14:48 UTC | |
by ashervin (Novice) on Nov 29, 2018 at 14:59 UTC | |
by ashervin (Novice) on Nov 29, 2018 at 16:12 UTC |