Tengo tres columnas en mi wx.ListCtrl(size=(-1,200))
. Me gustaría que las columnas llenen el ancho de ListCtrl después de su creación. Idealmente, la primera columna se puede expandir para llenar el espacio adicional disponible. Las columnas segunda y tercera no necesitan expandirse, y preferiblemente no cambiarán de ancho (formato de ocd).Hacer ancho de columna ocupar espacio disponible en wxPython ListCtrl
Actualmente, cada columna ListCtrl se configura utilizando (width=-1)
.
Tengo la sensación de que puedo utilizar esta sección del código a mi favor ...
# Expand first column to fit longest entry item
list_ctrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
Pseudo-código (tal vez):
# After wx.ListCtrl creation
Get width of ListCtrl control
Get width of each ListCtrl column
Calculate unused width of ListCtrl
Set first column width to original width + unused width
Agregado:
Dada el siguiente ejemplo, no entiendo cómo iniciar la mezcla automática de ancho de banda. Actualmente, estoy tratando de poner el listctrl dentro de un foldpanel. El foldpanel es una clase y una función dentro de la clase crea el listctrl. ¡Ni siquiera estoy seguro de que esto se pueda hacer dada la estructura de mi código en este momento!
class MyPanel(wx.Panel):
def __init__(self, parent, dictionary):
self.dictionary = dictionary
"""Constructor"""
wx.Panel.__init__(self, parent)
# Layout helpers (sizers) and content creation (setPanel)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.mainSizer)
list_ctrl = self.setPanel()
self.mainSizer.Add(list_ctrl, 0, wx.ALL | wx.EXPAND, 5)
self.GetSizer().SetSizeHints(self)
def setPanel(self):
index = 0
list_ctrl = wx.ListCtrl(self, size=(-1, 200),
style=wx.LC_REPORT | wx.BORDER_SUNKEN)
list_ctrl.InsertColumn(0, "Variable", format=wx.LIST_FORMAT_LEFT, width=-1)
list_ctrl.InsertColumn(1, "x", format=wx.LIST_FORMAT_RIGHT, width=-1)
list_ctrl.InsertColumn(2, u"\u03D0", format=wx.LIST_FORMAT_RIGHT, width=-1)
for key, value in self.dictionary.iteritems():
list_ctrl.InsertStringItem(index, str(key))
list_ctrl.SetStringItem(index, 1, ("%.2f" % value[0]))
list_ctrl.SetStringItem(index, 2, ("%.8f" % value[1]))
index += 1
list_ctrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
list_ctrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
list_ctrl.SetColumnWidth(2, wx.LIST_AUTOSIZE)
return list_ctrl
Se agregó algo de información adicional y fragmento de código. No puedo entender cómo usar la clase mixin dado el diseño de mi código atm. –