Question

The very sparse wxPerl documentation that I have been able to find says it is supported and sure enough, I can create an instance of it.

my $layout = new Wx::GridBagSizer(5,5);

But I cannot make it work. Specifically, I cannot add a widget to $layout. Anyone done this?

And while I am on the subject, has anyone found any GOOD documentation for wxPerl?

Was it helpful?

Solution

First, checkout Wx::Demo for examples of just about every class.

You should add widgets using its Add method.

$sizer->Add($widget, Wx::GBPosition->new($row, $col));

and maybe

$sizer->Add($widget, [ $row, $col ]);

OTHER TIPS

ikegami got me going in the right direction. Wx::Demo was VERY helpful (like widget for PerlTk if anyone is familiar with that tool). But Wx::GridBagSizer is not explicitly discussed so it took some trial and error to finally get there. Here is what I was trying to do:

sub new 
{
    my( $class, $parent ) = @_;
    my $self = $class->SUPER::new
    (
        undef, 
        -1, 
        "Wx::GridBagSizer",
        wxDefaultPosition, wxDefaultSize,
        wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX
    );

    my $Grid = Wx::GridBagSizer->new(1,1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 1'), Wx::GBPosition->new(0, 0), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 2'), Wx::GBPosition->new(0, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 3'), Wx::GBPosition->new(1, 0), Wx::GBSpan->new(1, 2), wxGROW|wxALL, 1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 4'), Wx::GBPosition->new(2, 0), Wx::GBSpan->new(2, 1), wxGROW|wxALL, 1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 5'), Wx::GBPosition->new(2, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
    $Grid->Add(Wx::Button->new($self, -1, 'Button 6'), Wx::GBPosition->new(3, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
    $Grid->AddGrowableRow(1);
    $Grid->AddGrowableCol(1);

    $self->SetAutoLayout( 1 );
    $self->SetSizer( $Grid );
    $self->CenterOnScreen(wxBOTH);
    return $self;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top