I've been using wxPython for a few years and can generally figure
things out, but I'm really stumped by this one. I'm trying to use a
wx.ListCtrl for this first time, but the default sizing isn't what I
would like.
It appears that for a wxListCtrl the following
GetSize()
GetBestSize()
GetEffectiveMinSize()
always return (100, 80) regardless of the contents of the wxListCtrl.
I would like to set the size of the wxListCtrl so that it is big
enough to not need scroll bars. Is there an easy way to do this?
If it helps, I have an example below.
Jeff
#!/usr/bin/env python
import wx
import os
import string
import sys
import wx.lib.mixins.listctrl as listmix
···
##################################################################
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Test")
panel = BallotsPanel(self)
sizer = wx.BoxSizer()
sizer.Add(panel, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
sizer.Fit(self)
##################################################################
class BallotCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
def __init__(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize):
style=wx.LC_REPORT|wx.BORDER_NONE
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
listmix.ListCtrlAutoWidthMixin.__init__(self)
##################################################################
class BallotsPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
names = ["Condit, James", "Davis, Henrietta", "Decker, Marjorie",
"Dixon, Vince", "Gallucio, Anthony", "Hall, Robert", "Horowitz,
Jacob"]
self.ballotC = BallotCtrl(self)
self.ballotC.InsertColumn(0, "R", wx.LIST_FORMAT_RIGHT)
self.ballotC.InsertColumn(1, "Candidate")
for c, name in enumerate(names):
self.ballotC.InsertStringItem(c, "")
self.ballotC.SetStringItem(c, 1, name)
self.ballotC.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
self.ballotC.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
print self.ballotC.GetSize()
print self.ballotC.GetBestSize()
print self.ballotC.GetClientSize()
print self.ballotC.GetVirtualSize()
print self.ballotC.GetEffectiveMinSize()
# Sizers
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.ballotC, 1, wx.EXPAND)
self.SetSizer(sizer)
sizer.Fit(self)
##################################################################
class App(wx.App):
def OnInit(self):
self.frame = MyFrame(None)
self.frame.Show(True)
self.frame.Center()
self.SetTopWindow(self.frame)
return True
##################################################################
if __name__ == '__main__':
app = App(0)
app.MainLoop()