Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

proportional resizing tk table

by welle (Beadle)
on Aug 04, 2011 at 21:41 UTC ( #918656=perlquestion: print w/ replies, xml ) Need Help??
welle has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I am trying to resize the columns of a Tablematrix according to the size of the main window and the (variable number of columns)

This is what I have so far:

First I create a simple Tablematrix table, then I set the width of my main Window (full screen)

my $sw = $mw->screenwidth; my $sw_new=int($sw*.99); $mw->geometry("${sw_new}x400+0+0");

I do my Tablematrix rezising here. The rezising of the table's column should be proportionally to the width of the window. If window is x and I have 2 columns, each column shold be x/2, if I have 3 columns each column should be x/3, etc...

if ($number_of_columns_in_GUI=~2){ my $col_new=int($sw*.50); $t->colWidth( 0=> $col_new, 1=> $col_new, 2=> 0); } if ($number_of_columns_in_GUI=~3){ my $col_new=int($sw*.33); $t->colWidth( 0=> $col_new, 1=> $col_new, 2=> $col_new, 3=> 80); }

Of course, this doesn't work. Window width is not appropriate to set the (I think) character number of a tablematrix column.

Any idea on how I could solve this? Thank you

Comment on proportional resizing tk table
Select or Download Code
Re: proportional resizing tk table
by kcott (Abbot) on Aug 05, 2011 at 00:40 UTC

    I haven't used Tablematrix but here's some general information you may find useful.

    See Tk::Widget (abstract base class for all Tk widgets) which has a lot of methods for querying metrics of this sort.

    Tk::Wm (communicate with window manager) also has useful information.

    I note you say "full screen" but don't show overrideredirect() (that's documented in Tk::Wm). The choice is yours but, if window decorations are displayed on the screen, you'll need to include their dimensions in your calculations. A note of caution: these dimensions will vary with operating system, window manager and user preferences.

    -- Ken

Re: proportional resizing tk table
by Marshall (Prior) on Aug 05, 2011 at 12:22 UTC
    Take a look at my demo code... The key lines for 5 columns are:
    -cols => 5, ################# -colwidth=> -( ($pix_width-30)/5), ################# # note: not -colWidth
    If the -colwidth is negative, it is in pixels. I subtracted a "fudge factor" to allow for the scrollbars. Change 5 in both places to be whatever you want and you will get that many evenly spaced columns.
    #!/usr/bin/perl -w use strict; use Tk; use Tk::TableMatrix; my $mw = MainWindow->new; $mw->configure(-title=> "Some Title"); my $pix_height = $mw->screenheight; my $pix_width = $mw->screenwidth; my $color_depth = $mw->screendepth; $mw->geometry("$pix_width"."x400+0+0"); ########### my $table_frame = $mw->Frame(-height=>'10',-width=>'30', -relief=>'groove',-borderwidth=>'3' )->pack(-expand=>1, -fill=>'both',-pady=>'0'); my %tMainHash; my $table = $table_frame->Scrolled('TableMatrix', -cols => 5, ################# -colwidth=> -( ($pix_width-30)/5), ################# -rows =>16, -variable => \%tMainHash, -state => 'disabled', # no direct editing of cells -resizeborders => 'col', -bg => 'white', -rowheight => 1, #make row display more compact.... -bd => [0,1,0,1], -justify => 'left', -drawmode => 'compatible', -wrap => 0, -relief => 'solid', -scrollbars=>'se', -exportselection =>0, )->pack(-expand =>1, -fill=>'both'); $table->rowHeight(0,2); #varies height of title row (0) $table->tagRow('title',0); $table->tagConfigure('title', -bd=>2, -relief=>'raised'); MainLoop;

      This is exactly what I was looking for! Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://918656]
Approved by sundialsvc4
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-10-31 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (225 votes), past polls