in reply to wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions

Try to replace

$this->Wx::ListCtrl->SetItemFont(0, $f);

in sub OnBold, line 60 with

$this->{listControl}->SetItemFont(0, $f);

or

$this->SetItemFont(0, $f);

Untested, as I do not have wx but these two look more logical than yours.

  • Comment on Re: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by HelenCr (Monk) on Mar 25, 2013 at 16:19 UTC

    hdb: I tried, (in fact, that's what I started off with), here is the modified sub:

    sub OnBold { # def OnBold(self, evt): (Py +thon) my $this = shift; my $f = $this->GetItemFont(0); # my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'aria +l'); $f->SetWeight(wxBOLD); $this->SetItemFont(0, $f); } #1 end sub OnBold

    you get a slightly different error:

    Can't locate object method "GetItemFont" via package "Wx::ListCtrl" at + Set item font post.pl line 57 MyFrame::OnBold('Wx::ListCtrl=HASH(0x23d6454)') called at Set +item font post.pl line 31 MyFrame::__ANON__('MyFrame=HASH(0x23f2734)', 'Wx::CommandEvent +=SCALAR(0 x287f36c)') called at Set item font post.pl line 76 eval {...} called at Set item font post.pl line 76

    So it seems that the Perl interpreter has correctly identified that the object belongs to the Wx::ListCtrl class; but it can't find the GetItemFont method. Why?

      Probably because is not implemented. Using a trick I learned here recently (Re: How to use wxHtmlEasyPrinting), does not show any font related methods:

      perl -MWx=:allclasses -le " print for grep/set/i, keys %Wx::ListCtrl:: + "

      Stefan.

      Update: It is now fixed with the new release of Wx, see Wx 0.9918 Released, thanks to Mark Dootson.

        Probably because is not implemented.

        :) listctrl->GetItem()->SetFont() is implemented

        $ perl -MWx -le " print for grep/font/i, keys %Wx::ListItem:: " SetFont GetFont

        Although, its really not that hard to implement :) the hard part is figuring out which version of wxWidgets API it was added in

        sub Wx::ListCtrl::GetItemFont { $_[0]->GetItem($_[1])->GetFont } sub Wx::ListCtrl::SetItemFont { $_[0]->GetItem($_[1])->SetFont($_[2]) +}

      Yes, hdb has a point about the OnRed method using:

      $this->{listCtrl}->SetItemTextColour( 0, wxRED );

      But also the event handler method is has to be written like this:

      EVT_BUTTON( $self, $btnBold, sub { $self->OnBold } );

      The OnBold method is in the current package.

      Another remark is that you can skip all the use.+ stuff until the first package declaration in your code examples, they are not needed and is recommended to keep the posts as short as possible. It is also better for debugging, to not load unused modules.

      Regards, Stefan.

        Stefan: when I change, according to yours and hdb's suggestion, the event-binding calls to:

        EVT_BUTTON ($self, $btnBold, sub { $self->OnBold }); EVT_BUTTON ($self, $btnRed, sub { $self->OnRed });

        and the methods to:

        sub OnBold { my $this = shift; my $f = $this->{listControl}->GetItemFont(0); $f->SetWeight(wxBOLD); $this->SetItemFont(0, $f); } #1 end sub OnBold sub OnRed { my $this = shift; $this->{listControl}->SetItemTextColour(0, wxRED); } #1 end sub OnRed

        You still get the same error message:

        Can't locate object method "GetItemFont" via package "Wx::ListCtrl" at + Set item font post.pl line 59 MyFrame::OnBold('MyFrame=HASH(0x2662734)') called at Set item font +post.pl line 31 MyFrame::__ANON__('MyFrame=HASH(0x2662734)', 'Wx::CommandEvent=SCAL +AR(0x2aef33c)') called at Set item font post.pl line 78 eval {...} called at Set item font post.pl line 78

        So it seems that many list control classes are not implemented in wxPerl.
        Very frustrating and disappointing. I don't know how to proceed.

        Helen