Try this approach. The only problem with Table::Matrix is you have to use tags to color the cells, but it's easy once you get the hang of it. What flexibility problems are you concerned with?
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::TableMatrix;
my $mw = MainWindow->new;
my $dataHash = {
"0,0" => "abc",
"0,1" => "123\ndef",
};
my $table = $mw->Scrolled('TableMatrix',
-titlerows => 1,
-roworigin => 0,
-colorigin => 0,
-cols => 2,
-rowheight => 2,
-variable => $dataHash,
);
$table->pack(-expand => 1, -fill => 'both');
PushRow(1);
sub PushRow {
my $row = shift;
my $col;
my %ColValue = ( 0 => "ABC", 1 => "456\nDEF" );
for $col (0..1) { $dataHash->{"$row,$col"} = "$ColValue{$col}"; }
}
MainLoop;
| [reply] [d/l] |
I don't think you can (apparently listbox doesn't do multiline) ... so switch to Tk::Table :) | [reply] |
Thank you Anonymous for the quick reply.
I was afraid of that. Tk::Table and Tk::Tablematrix doesn't provide me with the flexibility, the finesse or just the intuitive feel that Mlistbox and Tk::Columns provide. Oh well.!! Sigh .!! Back to the drawing board again.
| [reply] |
Thank you zentara for your insight and code. I am looking at the Tk::Tablematrix module now to see if I can customize it to my needs. Well, I am looking for features like sorting and multiline entry while maintaining the look and feel of a simple yet elegant interface(table). I am currently using Tk::HList but I was looking for options to implement it in a neat way . | [reply] |
Just to shoot the breeze, as they say, I often feel confined by the current widget set of most popular GUI's. Just as you, I see limited building blocks to play with.
So, for what it is worth, I suggest you make you own widget on a Canvas, which gives you total control with tags and events. See Tk::CanvasDirTree
I wrote that module, solely for the purpose of making an educational example on how to use the Canvas to make a custom widget. Look at the code it is pretty simple. You can set Text anywhere you want on a canvas, and load arrays into lists with very little work.It is alot of fun designing your own widget, which inherits from a Canvas. Using tags is the secret to using the Canvas. For another instance, look at this code by rcseege:
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Pane;
# by rcseege
my $mw = MainWindow->new;
my $sPane = $mw->Scrolled("Pane",
-scrollbars => 'se',
-sticky => 'nsew',
-bg => 'black',
-width => 300,
-height => 300
)->pack(qw/-expand 1 -fill both/);
my $container = $sPane->Subwidget('scrolled');
foreach my $row (0 .. 3) {
foreach my $col (0 .. 3) {
createTile($container, $row, $col);
}
}
foreach my $i (0 .. 3) {
$container->gridRowconfigure($i, -weight => 1);
$container->gridColumnconfigure($i, -weight => 1);
}
MainLoop;
## Each 'Tile' is a Frame containing a Scrolled Canvas +
## another Frame containing zoom controls.
sub createTile
{
my ($parent, $x, $y) = @_;
my $tileColor = "black";
my $tile = $parent->Frame(-bg => $tileColor)->grid(
-padx => 5,
-pady => 5,
-row => $x,
-column => $y,
-sticky => 'nsew'
);
my $sc = $tile->Scrolled('Canvas',
-scrollbars => 'osoe',
-scrollregion => [0, 0, 200, 200],
-width => 125,
-height => 125,
-background => randColor()
)->pack(qw/-fill both -side top -expand 1/);
my $count = int(rand(6)) + 2;
foreach my $i (1 .. $count) {
my ($x, $y) = (randNumber(), randNumber());
my $size = randNumber();
$sc->createRectangle($x, $y, $x+$size, $y+$size,
-fill => randColor(),
-outline => 'black',
-width => 2
);
}
my $bFrame = $tile->Frame(-bg => $tileColor)->pack(qw/-side top/);
$bFrame->Button(
-text => " Zoom Out ",
-command => sub { $sc->scale(qw/all 0 0 .5 .5/); }
)->pack(qw/-side left -padx 5/);
$bFrame->Button(
-text => " Zoom In",
-command => sub { $sc->scale(qw/all 0 0 2 2/); }
)->pack(qw/-side right -padx 5/);
}
sub randColor {
my @colors = qw(red yellow blue orange green purple);
return $colors[rand($#colors + 1)];
}
sub randNumber {
my ($max, $min) = (100, 10);
my $size = int(rand($max));
$size += $min if $size < $min;
return $size;
}
| [reply] [d/l] |