http://www.perlmonks.org?node_id=1025333


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

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?

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

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

    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]) +}

        AnonymousMonk: Thank you. Using your post, and the info in this: http://wxpython-users.1045709.n5.nabble.com/column-header-doesn-t-change-td2341548.html (showing that this:

        $this->SetItem($item);
        is necessary), I succeeded in changing an item's font in Wx::ListCtrl.
        Here is the font-changing sub:

        sub OnBold { my $this = shift; my $item = $this->GetItem(1); my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'times new roman +'); say "In OnBold, \$this= $this, \$item = $item, \$f= $f"; $item->SetFont($f); $this->SetItem($item); } #1 end sub OnBold

        and the entire program (tested):

        Stefan, hdb and James: the object pointers were fine originally (as you can see).

        My next problem: how do you set/change size and font of ListCtrl column headers. (As usual, no documentation). I'll start a new post for that: http://www.perlmonks.org/?node_id=1025489

        Many thanks to all the responders, who spent time on this thread. - Helen

Re^3: wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions
by stefbv (Curate) on Mar 25, 2013 at 17:45 UTC

    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