views:

96

answers:

1

This may be obvious, but I'm missing it. I'm working in wxpython.

I have a wxStatusBar with several fields (these fields have text as well as other widgets). I need to be able to add and remove these fields throughout the app session. Is there a way to remove fields from a statusbar, or do I just have to redraw it? I think to do the latter I could use the SetFields() function, but I'm not quite sure what type of list to give SetFields()...the only example I've seen gives it a list of strings, but I have more than strings to pass it.

Thanks in advance!

A: 

You can reduce the number of fields by calling mystatusbar.SetFieldsCount(numfields). Rescale them if desired with .SetStatusWidths([list]). Change text at individual positions using .SetStatusText('string', position). If you have some control (e.g. a checkbox) hiding in a status bar section, you can move it to the spot given by .GetFieldRect(position). Call this on wx.EVT_SIZE or whenever you remove/eliminate stuff.

If you remove fields from somewhere other than the end (highest index), you'll have to manually shift your data first. You mentioned you were using .SetFields(), just take the list you passed earlier and .pop() out the one you don't want.

Some repositioning code from wxPython demo:

# reposition the checkbox
def Reposition(self):
    rect = self.GetFieldRect(1) # the checkbox lives in the 2nd (index 1) slot
    self.cb.SetPosition((rect.x+2, rect.y+2))
    self.cb.SetSize((rect.width-4, rect.height-4))
    self.sizeChanged = False

Look in the wxPython Demo app for some example code you can quickly hack up and run from within it.

Nick T