wxPython: GridBagSizer, EXPAND, and HtmlListBox

A

Adam Endicott

I'm having some trouble using an HtmlListBox with a GridBagSizer. I'm
not sure how best to explain what's happening, but it seems that every
time my frame gets resized, the HtmlListBox grows taller, even when the
resize is only horizontal, or makes the frame smaller. I'm pretty new
to GUI layout and wxPython, so hopefully I'm doing something obviously
wrong. Here's a short runnable code sample showing my basic layout (I'm
using python 2.3.3 and wxPython 2.6 running on windows XP pro):

-----Start Code-----

import wx

class TestFrame(wx.Frame):
def __init__(self):
app = wx.PySimpleApp()
wx.Frame.__init__(self, None, -1)
p = wx.Panel(self, -1)
gbs = wx.GridBagSizer(5, 5)
gbs.Add(wx.Button(p, -1), (0, 0), span=(1, 2), flag=wx.EXPAND)
hlb = wx.HtmlListBox(p, -1)
gbs.Add(hlb, (1, 0), span=(4, 1), flag=wx.EXPAND)
gbs.Add(wx.Button(p, -1), (1, 1), flag=wx.EXPAND)
gbs.Add(wx.Button(p, -1), (2, 1), flag=wx.EXPAND)
gbs.Add(wx.Button(p, -1), (3, 1), flag=wx.EXPAND)
gbs.Add(wx.Button(p, -1), (4, 1), flag=wx.EXPAND)
gbs.AddGrowableRow(2)
gbs.AddGrowableCol(1)
p.SetSizerAndFit(gbs)
self.SetClientSize(p.GetSize())
self.Show(True)
wx.EVT_SIZE(hlb, self.onSize)
app.MainLoop()

def onSize(self, event):
print event.GetSize()

if __name__ == '__main__':
TestFrame()

-----End Code-----

If you run that and try to resize the window by dragging an edge, the
HtmlListBox just goes crazy and keeps getting bigger (try dragging the
right edge back and forth).

It does the same thing if I replace the HtmlListBox with a wx.Panel or
even a wx.Window, but not with a wx.ListBox, or wx.Button. The effect
I'm trying to accomplish is basically what you get if you sub in a
wx.ListBox, (but I need the HtmlListBox because I want to put a small
image next to the strings in the list).

Removing the wx.EXPAND flag on the HtmlListBox (at line 11) solves the
weird resizing, except that now the HtmlListBox doesn't fill the space
it needs to.

Does anyone know what's going on here, or how I can get this to work?
 
A

Adam Endicott

Just an update if anyone runs across this through google. It appears
this was an issue fixed in 2.6.0.1 (or 2.6.1.0, I forget which
exactly). I was using 2.6.0.0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,184
Latest member
ZNOChrista

Latest Threads

Top