# taken from: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-SetItemTextColor-SetItemFont-td2348263.html (main.py)
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 400))
# Now create the Panel to put the other controls on.
panel = wx.Panel(self)
btnBold = wx.Button(panel, -1, "Bold")
btnRed = wx.Button(panel, -1, "Red")
self.Bind(wx.EVT_BUTTON, self.OnBold, btnBold)
self.Bind(wx.EVT_BUTTON, self.OnRed, btnRed)
# create a list control
self.listControl = wx.ListCtrl(panel, style=wx.LC_REPORT, size=(200,100))
self.listControl.InsertColumn(0, "Col1")
self.listControl.InsertColumn(1, "Col2")
self.listControl.InsertStringItem(0, "Data 1")
self.listControl.SetStringItem(0,1, "Data 2")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.listControl, 0, wx.ALL, 10)
sizer.Add(btnBold, 0, wx.ALL, 10)
sizer.Add(btnRed, 0, wx.ALL, 10)
panel.SetSizer(sizer)
panel.Layout()
def OnBold(self, evt):
f = self.listControl.GetItemFont(0)
f.SetWeight(wx.BOLD)
self.listControl.SetItemFont(0, f)
def OnRed(self, evt):
self.listControl.SetItemTextColour(0, wx.RED)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, "Demonstrate listctrl")
self.SetTopWindow(frame)
frame.Show(True)
return True
app = MyApp(redirect=True)
app.MainLoop()
####
# taken from: http://wxpython-users.1045709.n5.nabble.com/ListCtrl-SetItemTextColor-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
);
# wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 400)) (Python)
my $panel = Wx::Panel->new($self);
my $btnBold = Wx::Button->new($panel, -1, 'Bold', wxDefaultPosition, wxDefaultSize);
my $btnRed = Wx::Button->new($panel, -1, 'Red', wxDefaultPosition, wxDefaultSize);
EVT_BUTTON ($self, $btnBold, sub { $self->{listControl}->MyFrame::OnBold });
# self.Bind(wx.EVT_BUTTON, self.OnBold, btnBold) (Python)
EVT_BUTTON ($self, $btnRed, sub { $self->{listControl}->MyFrame::OnRed });
# self.Bind(wx.EVT_BUTTON, self.OnRed, btnRed) (Python)
# create a list control
$self->{listControl} = Wx::ListCtrl->new($panel, -1, wxDefaultPosition, [300,100], wxLC_REPORT);
$self->{listControl}->InsertColumn(0, 'Col1', wxLIST_FORMAT_LEFT, 150);
$self->{listControl}->InsertColumn(1, 'Col2', wxLIST_FORMAT_LEFT, 150);
$self->{listControl}->InsertStringItem( 0, 'dummy' );
$self->{listControl}->SetItemText( 0, 'Data 1');
$self->{listControl}->SetItem( 0, 1, 'Data 3');
$self->{listControl}->InsertStringItem( 1, 'dummy' );
$self->{listControl}->SetItemText(1, 'Data 2');
$self->{listControl}->SetItem( 0, 1, 'Data 3');
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($self->{listControl}, 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 $f = $this->GetItemFont(0);
my $f = Wx::Font->new(12, -1, wxNORMAL, wxBOLD, 0, 'arial');
$f->SetWeight(wxBOLD);
$this->Wx::ListCtrl->SetItemFont(0, $f);
} #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::
# class MyApp(Wx::App): (Python)
# def OnInit(self): (Python)
my $frame = MyFrame->new(undef, 'Demonstrate listctrl');
# Wx::SetTopWindow($frame);
$frame->Show(1);
# return True (Python)
my $app = Wx::SimpleApp->new;
$app->MainLoop;
1;
##
##
Error while autoloading 'Wx::ListCtrl' at F:/Win7programs/Dwimperl/perl/site/lib/Wx.pm line 48
Wx::AUTOLOAD('Wx::ListCtrl=HASH(0x26f6454)') called at Set item font post.pl line 60
MyFrame::OnBold('Wx::ListCtrl=HASH(0x26f6454)') called at Set item font post.pl line 31
MyFrame::__ANON__('MyFrame=HASH(0x2712734)', 'Wx::CommandEvent=SCALAR(0x2b9f3bc)') called at Set item font post.pl line 76
eval {...} called at F:/Win7programs/Dwimperl/perl/site/lib/Wx.pm line 48