From: Mark D. <mar...@zn...> - 2006-08-15 18:13:28
|
It was a quote from my own mail. It was an apology for posting none working code of my own. Peter Theobald wrote: > At 04:27 AM 8/15/2006, Mark Dootson wrote: >> > I'm afraid I don't know enough about Perl and Wx internals > > I don't know where you copied this piece of text, but I never wrote it. > >> or much else it would seem. I'm sure I ran this successfully !!! > > No need to be insulting. Your code doesn't work. You defined a variable $app in > the main scope. You try to use it in the DemoApp scope, where it can't be seen. > >> Anyhow, $self->ReleaseMouse(); in your original code at the appropriate >> place does the trick. (as below_ > > This certainly DOES fix the problem! Thank you very much. > It's an odd fix, because the docs state that: > 'you must release the mouse [with ReleaseMouse()] as many times as you capture > it [with CaptureMouse()]' > Since I never explicitly called CaptureMouse I shouldn't have to explicitly call > ReleaseMouse. But regardless, it WORKS and that's all that matters! > -Peter > > >> #!/usr/bin/perl -w -- >> use strict; >> use Wx qw[:everything]; >> >> package main; >> >> unless(caller){ >> local *Wx::App::OnInit = sub{1}; >> my $app = Wx::App->new(); >> Wx::InitAllImageHandlers(); >> >> my $ui = Test_ui->new(); >> >> $app->SetTopWindow($ui); >> $ui->Show(1); >> $app->MainLoop(); >> } >> >> package Test_ui; >> >> use Wx qw[:everything :allclasses]; >> use Wx::Event qw(EVT_LEFT_UP); >> >> our $mainframe; >> our @keywords=(); >> >> 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 ); >> $mainframe=$self; >> >> 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); >> >> $keywords[0]="Apples"; >> $keywords[1]="Bananas"; >> $keywords[2]="Cherries"; >> $keywords[3]="Durian"; >> >> return $self; >> } >> >> sub handle_keywords_left_up { >> my ($self, $event) =@_; >> my $ip=$self->GetInsertionPoint(); >> my ($col,$row)=$self->PositionToXY($ip); >> $self->ReleaseMouse(); >> print("editing keyword #$row\n"); >> return unless $keywords[$row]; >> my $newtext=Wx::GetTextFromUser( "Edit keyword $keywords[$row]", >> "Edit keyword $keywords[$row]", $keywords[$row], >> $mainframe, 0, 0); >> if ($newtext) { >> $keywords[$row]=$newtext; >> my $keyword_text=''; >> my $i=1; >> foreach my $k ( @keywords) { >> $keyword_text .= "$i.\t$k\n"; >> $i++; >> } >> $mainframe->{keywords_text}->SetValue( $keyword_text); >> } >> >> #$event->Skip(1); >> } >> >> 1; >> >> >> Peter Theobald wrote: >> > Mark, your code doesn't work. Error: 'Can't call method 'SetTopWindow' on an >> > undefined value line 15' >> > I would very much like to see what you did to get my code working. Please >> post a >> > fixed version. >> > -Peter >> > >> > At 08:45 PM 8/14/2006, Mark Dootson wrote: >> > >> >> 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........ >> > >> > >> > -------------------- >> > Peter Theobald >> > Turtle Cove Technology, Inc. >> > PO Box 28, Greenlawn NY 11740-0028 >> > (631) 261-4507 >> > > > __--=Peter Theobald=--__ > www.PeterTheobald.com > <http://www.petertheobald.com/> > |