Hi Peter,
Code below works.
I'm afraid I don't know enough about Perl and Wx internals to explain
why your original doesn't work which is probably unsatisfactory - but at
least it means you have some working code! Its all in the way Wx::App is
instantiated, I think.
I also removed the variables declared as 'our' from the Test_ui package
as I'm sure they are not what you want. (but this was not cause of problem)
Regards
Mark
#!/usr/bin/perl -w --
my $app = DemoApp->new();
$app->MainLoop();
package DemoApp;;
use strict;
use Wx qw[:everything];
use base qw (Wx::App);
sub OnInit {
Wx::InitAllImageHandlers();
my $ui = Test_ui->new();
$app->SetTopWindow($ui);
$ui->Show(1);
}
package Test_ui;
use Wx qw[:everything :allclasses];
use Wx::Event qw(EVT_LEFT_UP);
use base qw(Wx::Frame);
sub new {
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef unless defined $parent;
$id = -1 unless defined $id;
$title = "" unless defined $title;
$pos = wxDefaultPosition unless defined $pos;
$size = wxDefaultSize unless defined $size;
$name = "" unless defined $name;
$style = wxDEFAULT_FRAME_STYLE unless defined $style;
$self = $self->SUPER::new( $parent, $id, $title, $pos, $size,
$style, $name );
my $main_sizer=Wx::BoxSizer->new(wxVERTICAL);
$self->{keywords_text} = Wx::TextCtrl->new($self, -1,
"1. Apples\n2. Bananas\n3. Cherries\n4. Durian",
wxDefaultPosition, wxDefaultSize,
wxTE_READONLY|wxTE_MULTILINE|wxTE_DONTWRAP);
$main_sizer->Add( $self->{keywords_text}, 1, wxEXPAND|wxALL, 2);
$self->SetAutoLayout(1);
$self->SetSizer($main_sizer);
$self->Layout();
EVT_LEFT_UP( $self->{keywords_text}, \&handle_keywords_left_up);
$self->{__wordlist} = ['Apples','Bananas','Cherries','Durian'];
$self->{ISFRAME} = 1;
return $self;
}
sub handle_keywords_left_up {
my ($control, $event) =@_;
my $self = $control->GetParent();
my $ip = $self->{keywords_text}->GetInsertionPoint();
my ($col,$row)=$self->{keywords_text}->PositionToXY($ip);
my @keywords = @{ $self->{__wordlist} };
print("editing keyword #$row\n");
return unless $keywords[$row];
my $newtext=Wx::GetTextFromUser( "Edit keyword $keywords[$row]",
"Edit keyword $keywords[$row]", $keywords[$row], $self,
0, 0);
if ($newtext) {
$keywords[$row]=$newtext;
my $keyword_text='';
my $i=1;
foreach my $k ( @keywords) {
$keyword_text .= "$i.\t$k\n";
$i++;
}
$self->{keywords_text}->SetValue( $keyword_text);
}
$event->Skip(1);
}
1;
Peter Theobald wrote:
> I have a TextCtrl with keywords in it. When the user clicks on a keyword I
> pop
> up a modal dialog to edit the keyword........
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
|