listctrl header not changing

Hello,
I am trying to change the text of a column header in a ListCtrl widget
without success. The following code tries to rewrite the header every
2 seconds. The SetText seems to be successful because the string just
written can be read with GetText, but the string displayed by the
header never changes. What I am missing? Thank you in advance for any
help.

#!/usr/bin/python

import wx

class MyApp(wx.App):
  def OnInit(self):
    frame = wx.Frame(None,-1,"TEST")
    id=wx.NewId()
    self.list=wx.ListCtrl(frame,id,style=wx.LC_REPORT)
    self.list.InsertColumn(0,"HEADER 0")
    self.list.InsertStringItem(0,"ITEM 0")
    frame.Show(True)
    # start a wx timer calling back toggle header every 2 seconds."
    self.timer1 = wx.Timer(frame,wx.NewId())
    frame.Bind(wx.EVT_TIMER,self.toggle_header,self.timer1)
    self.timer1.Start(2000,oneShot=False)
    return True

  def toggle_header(self,event):
    column = self.list.GetColumn(0)
    print column.GetText()
    if column.GetText() == 'HEADER 0':
      column.SetText('HEADER 0 TOGGLED')
    else:
      column.SetText('HEADER 0')
    print column.GetText()

app = MyApp(0)
app.MainLoop()

Fabrizio Pollastri

Try this

def toggle_header(self,event):

    column = self.list.GetColumn(0)
    #print 'current value: %s' % column.GetText()

    if column.GetText() == 'HEADER 0':
      column.SetText('HEADER 0 TOGGLED')
      self.list.SetColumn(0, column)
      self.list.RefreshItem(0)

    else:
      column.SetText('HEADER 0')
      self.list.SetColumn(0, column)
      self.list.RefreshItem(0)

    #print "new value: %s"% column.GetText()

I've add
self.list.SetColumn(0, column)
and
self.list.RefreshItem(0)
On my Debian Lenny it works.

ciao
Beppe

···

On Dec 3, 3:42 pm, Fabrizio Pollastri <area...@gmail.com> wrote:

Hello,
I am trying to change the text of a column header in a ListCtrl widget
without success. The following code tries to rewrite the header every
2 seconds. The SetText seems to be successful because the string just
written can be read with GetText, but the string displayed by the
header never changes. What I am missing? Thank you in advance for any
help.

#!/usr/bin/python

import wx

class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(None,-1,"TEST")
id=wx.NewId()
self.list=wx.ListCtrl(frame,id,style=wx.LC_REPORT)
self.list.InsertColumn(0,"HEADER 0")
self.list.InsertStringItem(0,"ITEM 0")
frame.Show(True)
# start a wx timer calling back toggle header every 2 seconds."
self.timer1 = wx.Timer(frame,wx.NewId())
frame.Bind(wx.EVT_TIMER,self.toggle_header,self.timer1)
self.timer1.Start(2000,oneShot=False)
return True

def toggle_header(self,event):
column = self.list.GetColumn(0)
print column.GetText()
if column.GetText() == 'HEADER 0':
column.SetText('HEADER 0 TOGGLED')
else:
column.SetText('HEADER 0')
print column.GetText()

app = MyApp(0)
app.MainLoop()

Fabrizio Pollastri