Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: wxPerl: is wxListCtrl Get/SetItemFont implemented? ( Wx::ListCtrl::GetItemFont, Wx::ListCtrl::SetItemFont )

by HelenCr (Monk)
on Mar 26, 2013 at 08:48 UTC ( #1025465=note: print w/ replies, xml ) Need Help??


in reply to Re^4: wxPerl: is wxListCtrl Get/SetItemFont implemented? ( Wx::ListCtrl::GetItemFont, Wx::ListCtrl::SetItemFont )
in thread wxPerl: is wxListCtrl Get/SetItemFont implemented? and further important questions

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):

# taken from: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-Set +ItemTextColor-SetItemFont-td2348263.html (main.py) # ported 23 3 2013 v 0-1 use strict; use warnings; use Wx; use 5.014; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; use Win32::Console; package MyFrame; use Wx ':everything'; use Wx ':listctrl'; use Wx::Event 'EVT_BUTTON'; use parent -norequire, 'Wx::Frame'; sub new { #1 MyFrame:: my ($class, $parent, $title) = @_; my $self = $class->SUPER::new( $parent, -1, # parent window; ID -1 means any $title, # title [150, 150 ], # position [ 350, 400 ], # size ); my $panel = Wx::Panel->new($self); my $btnBold = Wx::Button->new($panel, -1, 'Bold', wxDefaultPos +ition, wxDefaultSize); my $btnRed = Wx::Button->new($panel, -1, 'Red', wxDefaultPosit +ion, wxDefaultSize); EVT_BUTTON ($self, $btnBold, sub { $self->{list_control}->MyF +rame::OnBold }); EVT_BUTTON ($self, $btnRed, sub { $self->{list_control}->MyFra +me::OnRed }); # create a list control $self->{list_control} = Wx::ListCtrl->new($panel, -1, wxDefaul +tPosition, [300,100], wxLC_REPORT); $self->{list_control}->InsertColumn(0, 'Col1', wxLIST_FORMAT_L +EFT, 150); $self->{list_control}->InsertColumn(1, 'Col2', wxLIST_FORMAT_L +EFT, 150); $self->{list_control}->InsertStringItem( 0, 'Data 1' ); $self->{list_control}->SetItem( 0, 1, 'Data 3'); $self->{list_control}->InsertStringItem( 1, 'Data 2' ); $self->{list_control}->SetItem( 1, 1, 'Data 4'); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add($self->{list_control}, 0, wxALL, 10); $sizer->Add($btnBold, 0, wxALL, 10); $sizer->Add($btnRed, 0, wxALL, 10); $panel->SetSizer($sizer); $panel->Layout(); return $self; } #1 end sub new MyFrame:: sub OnBold { # def OnBold(self, evt) +: (Python) 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 sub OnRed { # def OnRed(self, evt): + (Python) my $this = shift; $this->SetItemTextColour(0, wxRED); } #1 end sub OnRed # end class MyFrame:: my $frame = MyFrame->new(undef, 'Demonstrate listctrl'); # Wx::SetTopWindow($frame); $frame->Show(1); my $app = Wx::SimpleApp->new; $app->MainLoop; 1;

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


Comment on Re^5: wxPerl: is wxListCtrl Get/SetItemFont implemented? ( Wx::ListCtrl::GetItemFont, Wx::ListCtrl::SetItemFont )
Select or Download Code
Re^6: wxPerl: is wxListCtrl Get/SetItemFont implemented? ( Wx::ListCtrl::GetItemFont, Wx::ListCtrl::SetItemFont )
by Anonymous Monk on Mar 26, 2013 at 09:33 UTC

    (As usual, no documentation)

    Can you please tell me what you mean by this?

      Anonymous Monk: I mean that I can't find documentation explaining how to change (or set) text, font and size (width and height) of Wx::ListCtrl column headings.

      (see: http://www.perlmonks.org/?node_id=1025489)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025465]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-08-23 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls