Hi,
i'm just starting using wxPerl and have the following problem:
in the code below, in the package myFrame, i have a tree and a
textcontrol and want to print
some data into the textcontrol each time an item in the treecontrol is
selected (e.g. directory-listing);
how can i access the textcontrol from within the sub OnSelChange in
package myTreeCtrl ?
myFrame->TextCtrl->AppendText() doesn't work.
regards and thanks in advance
Paul
############################
use Wx;
package myFrame;
use strict;
use vars qw(@ISA);
@ISA = qw(Wx::Frame);
my($ID_QUIT) = ( 1 );
use Wx qw(:treectrl :window :sizer :textctrl
wxDefaultPosition wxDefaultSize);
sub new {
my $class = shift;
my $this = $class->SUPER::new( undef, -1, $_[0], [ @_[1, 2] ],
[ @_[3, 4] ] );
$this->SetIcon( Wx::GetWxPerlIcon() );
my $sizer1 = Wx::BoxSizer->new( wxHORIZONTAL);
$this->{TREECTRL} =
myTreeCtrl->new($this, -1, wxDefaultPosition, wxDefaultSize,
wxTR_HAS_BUTTONS|wxTR_EDIT_LABELS|wxSUNKEN_BORDER);
$this->{TEXTCTRL} =
Wx::TextCtrl->new($this, -1, '', wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxSUNKEN_BORDER);
$sizer1->Add($this->{TREECTRL}, 2, wxGROW);
$sizer1->Add($this->{TEXTCTRL}, 1, wxGROW);
$this->SetSizer($sizer1);
$this->SetAutoLayout(1);
my $file = Wx::Menu->new;
$file->Append($ID_QUIT, "E&xit" );
my $bar = Wx::MenuBar->new;
$bar->Append($file, "&File");
$this->SetMenuBar( $bar );
use Wx::Event qw(EVT_MENU EVT_UPDATE_UI);
EVT_MENU($this, $ID_QUIT, \&OnQuit);
$this;
}
sub OnQuit {
my( $this, $event ) = @_;
$this->Close( 1 );
}
#######################################
package myTreeCtrl;
use strict;
use vars qw(@ISA);
@ISA = qw(Wx::TreeCtrl);
sub new {
my $class = shift;
my $this = $class->SUPER::new( @_ );
...
use Wx::Event qw(EVT_TREE_SEL_CHANGED );
EVT_TREE_SEL_CHANGED($this, $this, \&OnSelChange);
$this;
}
.
.
.
sub OnSelChange {
my( $this, $event ) = @_;
my $item = $event->GetItem;
if ($item != $this->GetRootItem) {
my ($dir, $data) = split (/,/, $this->GetPlData($item));
-> here i would like to print $data to the TextCtrl from package myFrame
}
}
#######################################
package myApp;
use strict;
use vars qw(@ISA);
@ISA = qw(Wx::App);
sub OnInit {
my $this = shift;
my $frame = myFrame->new("Frame", 50, 50, 450, 450);
$frame->Show(1);
$this->SetTopWindow($frame);
1;
}
#######################################
package main;
my $app = myApp->new;
$app->MainLoop;
#######################################
|