views:

202

answers:

1

Hello,

I am having an issue with wxPython toolkit. I am using a wx.GridSizer object to place a grid displaying some status info. I need to update this grid, and so I came up with a few different ways of doing it. The one I prefer is to simply refresh/update the text that needs the updating, so I could try detaching the wxStaticText object from the sizer, overwriting it with a new wxStaticText object, and inserting the object back into the sizer at its previous index.

The better way, is to use the parent class of wxGridSizer,wxSizer, which has a method called 'Replace' which will allow me to replace the item in the widget without taking it out, and inserting it back in. Much more slick no? Well I get a very odd error when attempting to use this method. Here is code followed by error:

    self.info_sizer.Replace(self.project_value, wx.StaticText(self, wx.ID_ANY, project))

    self.info_sizer.Replace(self.project_value, wx.StaticText(self, wx.ID_ANY, project))
AttributeError: 'GridSizer' object has no attribute 'Replace'

So suddenly Replace is not an option. Bear in mind that the Insert method I refered to earlier is a method of the sizer's parent class wxSizer. So there proves that the sizer im using, wxGridSizer, can successfully call its parent class's method (inherited, subclassed) Insert.

So why cant I call in a similar way the method Replace?

+1  A: 

Any reason you can't use wx.StaticText.SetLabel("New label") to update the text?

Frank Niessink
I thought I had looked over that class for a solution. I must have missed that method. Ive been on overload with this lately.Well, thank you!
Matt1776
This is a great solution, but it would still be nice to know wny I couldnt access a parent class method .. I can use one, but not the other. Mysterious, unless I was doing something very obviously wrong, it was very late for me.
Matt1776
Did you subclass wx.GridSizer? There's this comment in http://www.wxpython.org/docs/api/wx.Sizer-class.html that says: "If you wish to create a custom sizer class in wxPython you should derive the class from wx.PySizer in order to get Python-aware capabilities for the various virtual methods."
Frank Niessink