I’ve been creating an app using wxPython. I’d like to display some data using ListCtrl and I’d like the colums occuping maximum space. This is: the maximum size available is divided between the rows I have. I’ve tried this but it doesn’t work (this is the panel where listctrl is):
class VirtualListPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
width = self.GetParent().GetClientSize().width/5
coches = vehiculos()
gris = wx.Color(220,220,220)
self.lista = wx.ListCtrl(self, style=wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES)
self.lista.InsertColumn(0, "Matricula", width=width)
self.lista.InsertColumn(1, "Tipo", width=width)
self.lista.InsertColumn(2, "Matriculacion", width=width)
self.lista.InsertColumn(3, "Ult. ITV", width=width)
self.lista.InsertColumn(4, "Prox. ITV", width=width)
i = 0
for data in coches:
index = self.lista.InsertStringItem(i, data[0])
self.lista.SetStringItem(index, 1, str(data[1]))
self.lista.SetStringItem(index, 2, str(data[2]))
self.lista.SetStringItem(index, 3, str(data[3]))
self.lista.SetStringItem(index, 4, str(prox(data[1],data[2],data[3])))
if((index+1) % 2 == 0):
self.lista.SetItemBackgroundColour(index,gris)
i += 1
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.lista, 1, wx.EXPAND|wx.ALL)
self.SetSizer(self.sizer)
self.Bind(wx.EVT_SIZE, self.OnResize)
def OnResize(self, event):
width = self.GetParent().GetClientSize().width/5
self.lista.SetColumnWidth(0, width)
self.lista.SetColumnWidth(1, width)
self.lista.SetColumnWidth(2, width)
self.lista.SetColumnWidth(3, width)
self.lista.SetColumnWidth(4, width)
Now, it doesn’t even occupy full window, it only shows a small square on top left corner. If I comment “self.Bind(wx.EVT_SIZE…” line, it shows full screen, but columns are small.
Thank you in advance!!!
What you are missing is
event.Skip()call in theOnResizefunction. Some details about event propagation can be found here http://wiki.wxpython.org/EventPropagation. Alternatively you could useself.Layout().