From 10c34f20e7bec77425c77d6f3fb5b747061b8b2c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Aug 2018 23:11:32 -0700 Subject: [PATCH] Merge pull request #980 from RobinD42/fix-issue974 Add wx.StaticBox.GetBordersForSizer (cherry picked from commit 49d0592e4a1d92cc02f1f89eaff8ae270b1cffc4) --- CHANGES.rst | 2 ++ demo/StaticBox.py | 11 +++++++++-- etg/statbox.py | 11 ++++++++++- unittests/test_statbox.py | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1df6afa7..9ef8c242 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -101,6 +101,8 @@ Changes in this release include the following: * Optimize line drawing in HyperTreeList. (#973) +* Add wrapper for wx.StaticBox.GetBordersForSizer and use it in the demo to do + platform-specific layout of the items in the StaticBox. (#974) diff --git a/demo/StaticBox.py b/demo/StaticBox.py index 12c74de3..dd86e5be 100644 --- a/demo/StaticBox.py +++ b/demo/StaticBox.py @@ -10,18 +10,25 @@ class TestPanel(wx.Panel): wx.Panel.__init__(self, parent, -1) box1 = wx.StaticBox(self, -1, "This is a wx.StaticBox") - bsizer1 = wx.BoxSizer() + + # This gets the recommended amount of border space to use for items + # within in the static box for the current platform. + topBorder, otherBorder = box1.GetBordersForSizer() + bsizer1 = wx.BoxSizer(wx.VERTICAL) + bsizer1.AddSpacer(topBorder) t1 = wx.StaticText(box1, -1, "As of wxPython 2.9, wx.StaticBox can now be used as a parent like most other wx widgets. This is now the recommended way of using wx.StaticBox.") - bsizer1.Add(t1, 1, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, 10) + bsizer1.Add(t1, 1, wx.EXPAND|wx.BOTTOM|wx.LEFT|wx.RIGHT, otherBorder+10) box1.SetSizer(bsizer1) + ## The OLD way. box2 = wx.StaticBox(self, -1, "This is a wx.StaticBox using wx.StaticBoxSizer") bsizer2 = wx.StaticBoxSizer(box2, wx.VERTICAL) t = wx.StaticText(self, -1, "Controls placed \"inside\" the box are really its siblings. This method of using wx.StaticBox is deprecated since wxPython 2.9, and can cause issues on some platforms.") bsizer2.Add(t, 1, wx.EXPAND|wx.TOP|wx.LEFT, 10) + border = wx.BoxSizer(wx.VERTICAL) border.Add(box1, 1, wx.EXPAND|wx.ALL, 25) border.Add(bsizer2, 1, wx.EXPAND|wx.ALL, 25) diff --git a/etg/statbox.py b/etg/statbox.py index cc4978a5..ce8b14b5 100644 --- a/etg/statbox.py +++ b/etg/statbox.py @@ -9,6 +9,8 @@ import etgtools import etgtools.tweaker_tools as tools +from etgtools import MethodDef, ParamDef + PACKAGE = "wx" MODULE = "_core" @@ -50,7 +52,14 @@ def run(): # m.find('id').default = '' - + # This is intentionally not documented, but I think it would be handy to + # use from wxPython. + meth = MethodDef(name='GetBordersForSizer', isVirtual=True, type='void', protection='public', + briefDoc="Returns extra space that may be needed for borders within a StaticBox.", + items=[ParamDef(name='borderTop', type='int*', out=True), + ParamDef(name='borderOther', type='int*', out=True), + ]) + c.addItem(meth) module.addGlobalStr('wxStaticBoxNameStr', c) diff --git a/unittests/test_statbox.py b/unittests/test_statbox.py index bc02406a..fb4fa96c 100644 --- a/unittests/test_statbox.py +++ b/unittests/test_statbox.py @@ -13,6 +13,13 @@ class statbox_Tests(wtc.WidgetTestCase): s = wx.StaticBox() s.Create(self.frame, label='StaticBox') + def test_statboxGetBordersForSizer(self): + s = wx.StaticBox(self.frame, label='StaticBox') + topBorder, otherBorder = s.GetBordersForSizer() + assert isinstance(topBorder, int) + assert isinstance(otherBorder, int) + assert topBorder >= 0 + assert otherBorder >= 0 #---------------------------------------------------------------------------