Hi Kevin,
Hi Kevin,
Hi Werner,
sized_controls doesn't seem to have provision for StaticBoxSizer.
I tried this:
sbPane = sc.SizedPanel(self.pane, -1)
sb = wx.StaticBox(sbPane, -1)
sbSizer = wx.StaticBoxSizer(sb)
sbPane.SetSizer(sbSizer)
sbCtrlsPane = sc.SizedPanel(sbPane, -1)
sbCtrlsPane.SetSizerType('grid', {'cols': 2,})
st1 = wx.StaticText(sbCtrlsPane, -1, 'static text ctrl')
tc1 = wx.TextCtrl(sbCtrlsPane, -1, 'something')
self.pane is a sc.SizedPanel and it looks as I like BUT it crashes when I close the dialog which contains all of this. As the crash doesn't give any traceback I am guessing that the SetSizer call is may be stepping on someone.
If I change sbPane to be a wx.Panel instead of a sized one then I don't see any crash but I manually need to handle the sizing of it, which means I loose the HIG spacing.
What is the correct way of using StaticBoxSizer with sized_controls so that everything still respects the HIG's?
The basic problem is that sized_controls assumes a natural parent / child hierarchy controls and automatically adds all controls to the parent's sizer, including wx.StaticBox and its siblings. See this thread, particularly the last message, for a workaround:
http://groups.google.com/group/wxpython-users/browse_thread/thread/b7bb7195f17e04b8/323419e1a9d58e62?lnk=gst&q=SizedControls#323419e1a9d58e62
In 2.9, I believe you can now actually make wx.StaticBox a parent and have its internal controls as children, which, if it works as it should, would make the workaround unnecessary.
Since I sent the email I came up with another work around.
- create a SizedStaticBoxPanel
class SizedStaticBoxPanel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self.sBox = wx.StaticBox(self, -1, "Static box")
bsizer = wx.StaticBoxSizer(self.sBox, wx.VERTICAL)
if wx.VERSION < (2,9):
self.mainPanel = SizedPanel(self, -1)
else:
self.mainPanel = SizedPanel(self.sBox, -1)
bsizer.Add(self.mainPanel, 1, wx.EXPAND)
self.SetSizer(bsizer)
def GetContentsPane(self):
return self.mainPanel
def GetStaticBox(self):
return self.sBox
Which I then basically use in the same way as a SizedPanel, e.g. my code shown above then becomes this:
sbBox = sc.SizedStaticBoxPanel(self.pane, wx.ID_ANY)
sbBox.SetSizerProps(expand=True, proportion=1)
sbBox.GetStaticBox().SetLabel("my static box")
sbPane = sbBox.GetContentsPane()
sbPane.SetSizerType('grid', {'cols': 2,})
st1 = wx.StaticText(sbPane, wx.ID_ANY, 'static text ctrl')
tc1 = wx.TextCtrl(sbPane, wx.ID_ANY, 'something')
tc1.SetSizerProps(expand=True, proportion=0)
I guess should expand it to support the "orient" parameter in some way.
Maybe one or the other idea or a merge of all this could make it into wxPython 2.9?
A clean up of my work around which supports changing of orientation, only tested (and not extensively) with wxPython 2.9.
class SizedStaticBoxPanel(wx.Panel):
def __init__(self, *args, **kwargs):
wx.Panel.__init__(self, *args, **kwargs)
self._sBox = wx.StaticBox(self, -1, "Static box")
self._bSizer = wx.StaticBoxSizer(self._sBox, wx.VERTICAL)
if wx.VERSION < (2,9):
self.mainPanel = SizedPanel(self, -1)
else:
self.mainPanel = SizedPanel(self._sBox, -1)
self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)
self.SetSizer(self._bSizer)
def GetContentsPane(self):
return self.mainPanel
def SetStaticBoxLabel(self, label):
self._sBox.SetLabel(label)
def SetStaticBoxSizer(self, orient=wx.VERTICAL):
"""Set the orientation of the StaticBoxSizer"""
self._bSizer.Detach(self._sBox)
self._bSizer.Detach(self.mainPanel)
self._bSizer = wx.StaticBoxSizer(self._sBox, orient)
self._bSizer.Add(self.mainPanel, 1, wx.EXPAND)
self.SetSizer(self._bSizer)
Or would the preferred approach be Brendan's approach.
Werner
···
On 09/13/2011 07:44 PM, werner wrote:
On 09/13/2011 05:24 PM, Kevin Ollivier wrote:
On Sep 13, 2011, at 6:45 AM, werner wrote: