From: Peter T. <peter@PeterTheobald.com> - 2006-08-15 15:10:48
|
<html> <body> <font size=3>At 04:27 AM 8/15/2006, Mark Dootson wrote:<br> <blockquote type=cite class=cite cite="">> I'm afraid I don't know enough about Perl and Wx internals</font></blockquote><br> I don't know where you copied this piece of text, but I never wrote it.<br><br> <blockquote type=cite class=cite cite=""><font size=3>or much else it would seem. I'm sure I ran this successfully !!!</font></blockquote><br> 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.<br><br> <blockquote type=cite class=cite cite=""><font size=3>Anyhow, $self->ReleaseMouse(); in your original code at the appropriate<br> place does the trick. (as below_</font></blockquote><br> This certainly DOES fix the problem! Thank you very much.<br> It's an odd fix, because the docs state that:<br> '<font size=3>you must release the mouse [with ReleaseMouse()] as many times as you capture it [with CaptureMouse()]</font>'<br> Since I never explicitly called CaptureMouse I shouldn't have to explicitly call ReleaseMouse. But regardless, it WORKS and that's all that matters!<br> -Peter<br><br> <br> <blockquote type=cite class=cite cite=""><font size=3>#!/usr/bin/perl -w --<br> use strict;<br> use Wx qw[:everything];<br><br> package main;<br><br> unless(caller){<br> local *Wx::App::OnInit = sub{1};<br> my $app = Wx::App->new();<br> Wx::InitAllImageHandlers();<br><br> my $ui = Test_ui->new();<br><br> $app->SetTopWindow($ui);<br> $ui->Show(1);<br> $app->MainLoop();<br> }<br><br> package Test_ui;<br><br> use Wx qw[:everything :allclasses];<br> use Wx::Event qw(EVT_LEFT_UP);<br><br> our $mainframe;<br> our @keywords=();<br><br> use base qw(Wx::Frame);<br> sub new {<br> my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;<br> $parent = undef unless defined $parent;<br> $id = -1 unless defined $id;<br> $title = "" unless defined $title;<br> $pos = wxDefaultPosition unless defined $pos;<br> $size = wxDefaultSize unless defined $size;<br> $name = "" unless defined $name;<br> $style = wxDEFAULT_FRAME_STYLE unless defined $style;<br><br> $self = $self->SUPER::new( $parent, $id, $title, $pos, $size,<br> $style,<br> $name );<br> $mainframe=$self;<br><br> my $main_sizer=Wx::BoxSizer->new(wxVERTICAL);<br><br> $self->{keywords_text} = Wx::TextCtrl->new($self, -1,<br> "1. Apples\n2. Bananas\n3. Cherries\n4. Durian",<br> wxDefaultPosition, wxDefaultSize,<br> wxTE_READONLY|wxTE_MULTILINE|wxTE_DONTWRAP);<br> $main_sizer->Add( $self->{keywords_text}, 1, wxEXPAND|wxALL, 2);<br><br> $self->SetAutoLayout(1);<br> $self->SetSizer($main_sizer);<br> $self->Layout();<br><br> EVT_LEFT_UP( $self->{keywords_text}, \&handle_keywords_left_up);<br><br> $keywords[0]="Apples";<br> $keywords[1]="Bananas";<br> $keywords[2]="Cherries";<br> $keywords[3]="Durian";<br><br> return $self;<br> }<br><br> sub handle_keywords_left_up {<br> my ($self, $event) =@_;<br> my $ip=$self->GetInsertionPoint();<br> my ($col,$row)=$self->PositionToXY($ip);<br> $self->ReleaseMouse();<br> print("editing keyword #$row\n");<br> return unless $keywords[$row];<br> my $newtext=Wx::GetTextFromUser( "Edit keyword $keywords[$row]",<br> "Edit keyword $keywords[$row]", $keywords[$row],<br> $mainframe, 0, 0);<br> if ($newtext) {<br> $keywords[$row]=$newtext;<br> my $keyword_text='';<br> my $i=1;<br> foreach my $k ( @keywords) {<br> $keyword_text .= "$i.\t$k\n";<br> $i++;<br> }<br> $mainframe->{keywords_text}->SetValue( $keyword_text);<br> }<br><br> #$event->Skip(1);<br> }<br><br> 1;<br><br> <br> Peter Theobald wrote:<br> > Mark, your code doesn't work. Error: 'Can't call method 'SetTopWindow' on an <br> > undefined value line 15'<br> > I would very much like to see what you did to get my code working. Please post a <br> > fixed version.<br> > -Peter<br> > <br> > At 08:45 PM 8/14/2006, Mark Dootson wrote:<br> > <br> >> Hi Peter,<br> >><br> >> Code below works.<br> >> I'm afraid I don't know enough about Perl and Wx internals to explain<br> >> why your original doesn't work which is probably unsatisfactory - but at<br> >> least it means you have some working code! Its all in the way Wx::App is<br> >> instantiated, I think.<br> >><br> >> I also removed the variables declared as 'our' from the Test_ui package<br> >> as I'm sure they are not what you want. (but this was not cause of problem)<br> >><br> >> Regards<br> >><br> >> Mark<br> >><br> >> #!/usr/bin/perl -w --<br> >> my $app = DemoApp->new();<br> >> $app->MainLoop();<br> >><br> >> package DemoApp;;<br> >> use strict;<br> >> use Wx qw[:everything];<br> >> use base qw (Wx::App);<br> >><br> >> sub OnInit {<br> >> Wx::InitAllImageHandlers();<br> >> my $ui = Test_ui->new();<br> >> $app->SetTopWindow($ui);<br> >> $ui->Show(1);<br> >> }<br> >><br> >><br> >> package Test_ui;<br> >> use Wx qw[:everything :allclasses];<br> >> use Wx::Event qw(EVT_LEFT_UP);<br> >> use base qw(Wx::Frame);<br> >><br> >> sub new {<br> >> my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;<br> >> $parent = undef unless defined $parent;<br> >> $id = -1 unless defined $id;<br> >> $title = "" unless defined $title;<br> >> $pos = wxDefaultPosition unless defined $pos;<br> >> $size = wxDefaultSize unless defined $size;<br> >> $name = "" unless defined $name;<br> >> $style = wxDEFAULT_FRAME_STYLE unless defined $style;<br> >><br> >> $self = $self->SUPER::new( $parent, $id, $title, $pos, $size,<br> >> $style, $name );<br> >><br> >> my $main_sizer=Wx::BoxSizer->new(wxVERTICAL);<br> >><br> >> $self->{keywords_text} = Wx::TextCtrl->new($self, -1,<br> >> "1. Apples\n2. Bananas\n3. Cherries\n4. Durian",<br> >> wxDefaultPosition, wxDefaultSize,<br> >> wxTE_READONLY|wxTE_MULTILINE|wxTE_DONTWRAP);<br> >> $main_sizer->Add( $self->{keywords_text}, 1, wxEXPAND|wxALL, 2);<br> >><br> >> $self->SetAutoLayout(1);<br> >> $self->SetSizer($main_sizer);<br> >> $self->Layout();<br> >><br> >> EVT_LEFT_UP( $self->{keywords_text}, \&handle_keywords_left_up);<br> >><br> >> $self->{__wordlist} = ['Apples','Bananas','Cherries','Durian'];<br> >><br> >> $self->{ISFRAME} = 1;<br> >><br> >> return $self;<br> >> }<br> >><br> >> sub handle_keywords_left_up {<br> >> my ($control, $event) =@_;<br> >> my $self = $control->GetParent();<br> >> my $ip = $self->{keywords_text}->GetInsertionPoint();<br> >> my ($col,$row)=$self->{keywords_text}->PositionToXY($ip);<br> >> my @keywords = @{ $self->{__wordlist} };<br> >><br> >> print("editing keyword #$row\n");<br> >> return unless $keywords[$row];<br> >> my $newtext=Wx::GetTextFromUser( "Edit keyword $keywords[$row]",<br> >> "Edit keyword $keywords[$row]", $keywords[$row], $self,<br> >> 0, 0);<br> >> if ($newtext) {<br> >> $keywords[$row]=$newtext;<br> >> my $keyword_text='';<br> >> my $i=1;<br> >> foreach my $k ( @keywords) {<br> >> $keyword_text .= "$i.\t$k\n";<br> >> $i++;<br> >> }<br> >> $self->{keywords_text}->SetValue( $keyword_text);<br> >> }<br> >><br> >> $event->Skip(1);<br> >> }<br> >><br> >> 1;<br> >><br> >><br> >><br> >> Peter Theobald wrote:<br> >> > I have a TextCtrl with keywords in it. When the user clicks on a keyword I pop<br> >> > up a modal dialog to edit the keyword........<br> > <br> > <br> > --------------------<br> > Peter Theobald<br> > Turtle Cove Technology, Inc.<br> > PO Box 28, Greenlawn NY 11740-0028<br> > (631) 261-4507<br> > </blockquote> <x-sigsep><p></x-sigsep> __--=Peter Theobald=--__<br> <a href="http://www.petertheobald.com/" eudora="autourl">www.PeterTheobald.com<br> </a></font></body> </html> |