frozen StaticBox

The StaticBox MUST be created before any of its siblings are created.

···

On Mon, Jun 2, 2008 at 10:31 AM, Mike Rooney mxr@qvii.com wrote:

Hello,

I am having an issue where I create a StaticBox, but the elements inside are unresponsive depending on the parenting of the StaticBox[Sizer]. Please see the attached runnable demo.

You will note it opens two (seemingly) identical frames. In the first one, the checkbox in the StaticBox does not work. In the second, it works fine. In either case, the bottom checkbox always works, so it is just the control in the StaticBox that is the issue.

I initially noticed this behavior on OSX (wx 2.8.4.0) but when making this test was able to duplicate it on XP as well (wx 2.8.7.1). Can anyone else confirm or deny the unresponsive checkbox in the “Frozen StaticBox”-titled frame within the StaticBox?

What am I doing wrong in making my custom control and how can I get it to work within that context? I spent a decent amount of time making this demo and reducing a custom control of hundreds of lines down to the tiny AccountListCtrl in the attached file, so I would really appreciate a response and some assistance.

Thanks!

Mike Rooney

import wx

class AccountListCtrl(wx.Panel):

def __init__(self, parent):

    wx.Panel.__init__(self, parent)

    self.staticBox = wx.StaticBox(self, label="Controls")

    self.Sizer = wx.StaticBoxSizer(self.staticBox, wx.VERTICAL)

    self.Sizer.Add(wx.CheckBox(self, label="CheckBox"), 0, wx.TOP, 10)

    self.Sizer.Layout()

class TestFrame1(wx.Frame):

def __init__(self, parent=None):

    wx.Frame.__init__(self, parent, title="Frozen StaticBox", pos=(100,100))

    panel = wx.Panel(self)



    panel.Sizer = wx.BoxSizer(wx.VERTICAL)

    panel.Sizer.Add(AccountListCtrl(self), 1, wx.EXPAND) #frozen?

    panel.Sizer.Add(wx.CheckBox(panel), 0, wx.ALIGN_CENTER) #works fine



    self.Sizer = wx.BoxSizer()

    self.Sizer.Add(panel, 1, wx.EXPAND)

    self.Sizer.Layout()

class TestFrame2(wx.Frame):

def __init__(self, parent=None):

    wx.Frame.__init__(self, parent, title="Working StaticBox", pos=(100,400))

    panel = wx.Panel(self)



    staticBox = wx.StaticBox(panel, label="Controls")

    sbSizer = wx.StaticBoxSizer(staticBox, wx.VERTICAL)

    sbSizer.Add(wx.CheckBox(panel, label="CheckBox"), 0, wx.TOP, 10)



    panel.Sizer = wx.BoxSizer(wx.VERTICAL)

    panel.Sizer.Add(sbSizer, 1, wx.EXPAND) #frozen?

    panel.Sizer.Add(wx.CheckBox(panel), 0, wx.ALIGN_CENTER) #works fine



    self.Sizer = wx.BoxSizer()

    self.Sizer.Add(panel, 1, wx.EXPAND)

    self.Sizer.Layout()

if name == “main”:

app = wx.App(False)

frame1 = TestFrame1().Show(True)

frame1 = TestFrame2().Show(True)

app.MainLoop()

__


Stand Fast,
tjg.

Timothy Grant wrote:

The StaticBox MUST be created before any of its siblings are created.

Interesting, I didn't see this in the documentation, even as I read it before posting, until I went back after reading this. It is there plain as day now :slight_smile: It turns out the issue in the demo was a silly one (a 'self' where it should have been 'panel'), but I think indeed you have hit on the cause of the OSX bug. In my full control I create it after all the siblings and I see what issue that is causing now.

I will give it a try, creating the SB first (no access to OSX now) and let you know, but I think you have divined my issue even from my broken example.

Thanks so much,
- Mike

Timothy Grant wrote:

Mike it bit me severely last week as I re-org'd some code. I KNEW I had read about a similar problem, but couldn't find what I had read about it. I got some help in the #wxwidgets channel on Freenode.

Glad I was able to help.

You sure did, thanks. After moving the StaticBox creation, it works flawlessly on OSX! I wonder if Windows and GTK "fix" the z-order for you, or if it is just the nature of the different implementations that causes it to work fine on XP/GTK and not OSX.

Thanks again,
Mike