GridBagSizer, EXPAND, and HtmlListBox

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?

Refactoring the app a bit sorted out what was going on, and getting rid
of the EXPAND flags

got rid of most of the problems. The rest I think you can take care of.

Ray

Adam Endicott wrote:

GBS.PY (1.36 KB)

···

wxPython-users-unsubscribe@lists.wxwidgets.org
wxPython-users-help@lists.wxwidgets.org

Thank you for the response, but unfortunately this doesn't solve my problem. I need the EXPAND flags (and the growable row and column) so that the application resizes appropriately. If you replace the HtmlListBox with a regular ListBox in my code, you can see how I would like the resizing to work.

I'm just trying to figure out if there's a reason the HtmlListBox (or wx.Panel or wx.Window) is misbehaving so badly. It clearly can't be the right behavior, so I want to know if its something I'm doing wrong, or if its a bug in wxWindows somewhere (and if so, if anyone has a suggested workaround).

Ray Pasco wrote:

···

Refactoring the app a bit sorted out what was going on, and getting rid of the EXPAND flags
got rid of most of the problems. The rest I think you can take care of.

Ray

Adam Endicott wrote:

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?

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Adam Endicott wrote:

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.

This sounds like a bug that was fixed in 2.6.0.1. (Look for "default DoGetBestSize" in the CHANGES doc. Which 2.6 are you using? If you can't upgrade for some reason then you can call the htmlListBox's SetMinSize method to give it a reasonable minimum size, and then the sizer will use that instead of its current size.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Awesome, thank you so much. I was using 2.6.0.0, I guess I should have checked for an update. 2.6.1.0 fixes it. Whew, I've been pulling my hair out about this one for a couple of days, thank you!

Robin Dunn wrote:

···

Adam Endicott wrote:

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.

This sounds like a bug that was fixed in 2.6.0.1. (Look for "default DoGetBestSize" in the CHANGES doc. Which 2.6 are you using? If you can't upgrade for some reason then you can call the htmlListBox's SetMinSize method to give it a reasonable minimum size, and then the sizer will use that instead of its current size.