Resize ListBook Panel

Hi,

I am trying to create multiple frames with wxPython which each contain
a Listbook organizer panel of the same widths. I am using wxPython
version 2.8.11.0 (gtk2-unicode) with Python 2.7.2 in Ubuntu 11.10.

When I create multiple frames, each panel width is currently set by
the width of the text in that panel. I would like to be able to have
all frames use the same (fixed) panel width. A short code that
illustrates what I am trying to do is included below.

I have tried passing the "size" argument to the Listbook constructor
and using SetSize and SetMinSize on the Listbook and its children to
no avail. Any help would be greatly appreciated!

Thanks,
Tyler

# Based on the example from http://wiki.wxpython.org/Listbook
import wx
import wx.lib.inspection

···

#-----------------------------------------------------
class MyListBook(wx.Listbook):
    def __init__(self, parent, labelText):
        wx.Listbook.__init__(self, parent, wx.ID_ANY,
                             style=wx.BK_DEFAULT,
                             size=(300,-1))

        pages = [(wx.Panel(self), labelText),
                 (wx.Panel(self), "Normal Label"),
                 (wx.Panel(self), "Normal Label")]

        for page, label in pages:
            self.AddPage(page, label)

#-----------------------------------------------------
class DemoFrame(wx.Frame):
    def __init__(self, labelText):
        wx.Frame.__init__(self, None, wx.ID_ANY,
                          "Listbook Example",
                          size=(400,400))

        panel = wx.Panel(self)
        notebook = MyListBook(panel, labelText)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 10)
        panel.SetSizer(sizer)
        self.Layout()
        self.Show()

#-----------------------------------------------------
# I want both frames to have Listbook panels that are the same width
# but in this example, the wide label frame has a wider panel

app = wx.PySimpleApp()
frame1 = DemoFrame("Normal Label")
frame2 = DemoFrame("Really Really Wide Label")
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()

Unfortunately we do not have control over the size of the wx.ListCtrl using in the wx.Listbook class. You may want to take a look at the LabelBook class in wx.lib.agw.labelbook instead. IMO it looks better and you can have more control over how things are sized, how they are drawn, etc. And if all else fails it is written in Python so you can easily override behaviors in a derived class if needed.

···

On 10/28/11 7:47 PM, Tyler wrote:

Hi,

I am trying to create multiple frames with wxPython which each contain
a Listbook organizer panel of the same widths. I am using wxPython
version 2.8.11.0 (gtk2-unicode) with Python 2.7.2 in Ubuntu 11.10.

When I create multiple frames, each panel width is currently set by
the width of the text in that panel. I would like to be able to have
all frames use the same (fixed) panel width. A short code that
illustrates what I am trying to do is included below.

I have tried passing the "size" argument to the Listbook constructor
and using SetSize and SetMinSize on the Listbook and its children to
no avail. Any help would be greatly appreciated!

--
Robin Dunn
Software Craftsman

Thanks for the tip. LabelBook does exactly what I need!

-Tyler

···

On Oct 29, 1:45 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 10/28/11 7:47 PM, Tyler wrote:

> Hi,

> I am trying to create multiple frames with wxPython which each contain
> a Listbook organizer panel of the same widths. I am using wxPython
> version 2.8.11.0 (gtk2-unicode) with Python 2.7.2 in Ubuntu 11.10.

> When I create multiple frames, each panel width is currently set by
> the width of the text in that panel. I would like to be able to have
> all frames use the same (fixed) panel width. A short code that
> illustrates what I am trying to do is included below.

> I have tried passing the "size" argument to the Listbook constructor
> and using SetSize and SetMinSize on the Listbook and its children to
> no avail. Any help would be greatly appreciated!

Unfortunately we do not have control over the size of the wx.ListCtrl
using in the wx.Listbook class. You may want to take a look at the
LabelBook class in wx.lib.agw.labelbook instead. IMO it looks better
and you can have more control over how things are sized, how they are
drawn, etc. And if all else fails it is written in Python so you can
easily override behaviors in a derived class if needed.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org