Question

I can't get the listctrl widget to expand.

example picture: http://img109.imageshack.us/img109/3171/22488459.jpg

This code simply creates a dialog box and creates a CheckListCtrlMixin which is a ListCtrl with check boxes.

import wx
import re, os, sys
from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin

class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        CheckListCtrlMixin.__init__(self)
        ListCtrlAutoWidthMixin.__init__(self)

class QueueDialog(wx.Dialog):

    def __init__(self, parent, title):
        super(QueueDialog, self).__init__(parent=parent, 
            title=title, size=(400, 500))


        panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)


        sb = wx.StaticBox(panel, label='Queue')
        sbs = wx.StaticBoxSizer(sb, orient=wx.VERTICAL)
        panel2 = wx.Panel(panel)
        hbox3 = wx.BoxSizer(wx.VERTICAL)
        hbox3.Add(panel2, proportion=1, flag=wx.EXPAND|wx.ALL)

        listB = CheckListCtrl(panel2)
        listB.InsertColumn(0, "Test", width=100)
        listB.InsertColumn(1, "Status", wx.LIST_FORMAT_RIGHT)

        dalist = ["heh", "ha", "hello"]
        for name in dalist[0:3]:
            index = listB.InsertStringItem(sys.maxint, name[0:-1])


        sbs.Add(hbox3, proportion=1,flag=wx.EXPAND|wx.ALL)

        panel.SetSizer(sbs)


        hbox2 = wx.BoxSizer(wx.HORIZONTAL)

        okButton = wx.Button(self, label='OK')
        closeButton = wx.Button(self, label='Cancel')
        hbox2.Add(okButton)
        hbox2.Add(closeButton, flag=wx.LEFT, border=5)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(panel, proportion=1, flag=wx.EXPAND|wx.ALL, border=10)
        vbox.Add(hbox2, flag= wx.ALIGN_CENTER|wx.BOTTOM, border=10)

        self.SetSizer(vbox)

    def OnClose(self, e):
        self.Destroy()


class window(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 400))

        e = QueueDialog(None, title='Queue')
        e.ShowModal()
        e.Destroy()

        self.Centre()
        self.Show(True)

app = wx.App(0)
window(None, -1, 'e')
app.MainLoop()
Was it helpful?

Solution

I don't know why you have the second panel, but it's really not needed and makes things more complex. Here's one version that works on my machine:

import wx
import re, os, sys
from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin

class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
        CheckListCtrlMixin.__init__(self)
        ListCtrlAutoWidthMixin.__init__(self)

class QueueDialog(wx.Dialog):

    def __init__(self, parent, title):
        super(QueueDialog, self).__init__(parent=parent, 
            title=title, size=(400, 500))


        panel = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)

        sb = wx.StaticBox(panel, label='Queue')
        sbs = wx.StaticBoxSizer(sb, orient=wx.VERTICAL)

        hbox3 = wx.BoxSizer(wx.VERTICAL)
        listB = CheckListCtrl(panel)
        listB.InsertColumn(0, "Test", width=100)
        listB.InsertColumn(1, "Status", wx.LIST_FORMAT_RIGHT)
        hbox3.Add(listB, 1, wx.EXPAND)

        dalist = ["heh", "ha", "hello"]
        for name in dalist[0:3]:
            index = listB.InsertStringItem(sys.maxint, name[0:-1])

        sbs.Add(hbox3, proportion=1,flag=wx.EXPAND|wx.ALL)
        panel.SetSizer(sbs)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)

        okButton = wx.Button(self, label='OK')
        closeButton = wx.Button(self, label='Cancel')
        hbox2.Add(okButton)
        hbox2.Add(closeButton, flag=wx.LEFT, border=5)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(panel, proportion=1, flag=wx.EXPAND|wx.ALL, border=10)
        vbox.Add(hbox2, flag= wx.ALIGN_CENTER|wx.BOTTOM, border=10)

        self.SetSizer(vbox)

    def OnClose(self, e):
        self.Destroy()


class window(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 400))

        e = QueueDialog(None, title='Queue')
        e.ShowModal()
        e.Destroy()

        self.Centre()
        self.Show(True)

app = wx.App(0)
window(None, -1, 'e')
app.MainLoop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top