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.


In reply to Perl Tk Gang together two Scrolled Panes by ashervin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.