From 409e9860038421eaefbf4e383ddf1fde1a357069 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Aug 2018 21:11:07 -0700 Subject: [PATCH 1/4] pad the layout a bit --- demo/StaticBox.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demo/StaticBox.py b/demo/StaticBox.py index 12c74de3..f0385ceb 100644 --- a/demo/StaticBox.py +++ b/demo/StaticBox.py @@ -10,7 +10,8 @@ class TestPanel(wx.Panel): wx.Panel.__init__(self, parent, -1) box1 = wx.StaticBox(self, -1, "This is a wx.StaticBox") - bsizer1 = wx.BoxSizer() + bsizer1 = wx.BoxSizer(wx.VERTICAL) + bsizer1.AddSpacer(20) 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) From 1d7bb401ffa25122e50e5edd125fe922c546def3 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Aug 2018 21:51:29 -0700 Subject: [PATCH 2/4] Expose wx.StaticBox.GetBordersForSizer --- etg/statbox.py | 11 +++++++++++ unittests/test_statbox.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/etg/statbox.py b/etg/statbox.py index fb4472a3..2fdcb0bf 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" @@ -37,6 +39,15 @@ def run(): c.find('Create.label').default = 'wxEmptyString' tools.fixWindowClass(c) + # 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 #--------------------------------------------------------------------------- From defbd9294c8f02c04e333006cbd46381e95e94e1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Aug 2018 21:55:15 -0700 Subject: [PATCH 3/4] Use GetBordersForSizer to assist with layout --- demo/StaticBox.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/demo/StaticBox.py b/demo/StaticBox.py index f0385ceb..af391417 100644 --- a/demo/StaticBox.py +++ b/demo/StaticBox.py @@ -10,11 +10,12 @@ class TestPanel(wx.Panel): wx.Panel.__init__(self, parent, -1) box1 = wx.StaticBox(self, -1, "This is a wx.StaticBox") + topBorder, otherBorder = box1.GetBordersForSizer() bsizer1 = wx.BoxSizer(wx.VERTICAL) - bsizer1.AddSpacer(20) + 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) box2 = wx.StaticBox(self, -1, "This is a wx.StaticBox using wx.StaticBoxSizer") From e97e62744483799f216f4b91612a6c57113869e3 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 29 Aug 2018 22:19:27 -0700 Subject: [PATCH 4/4] Add comment about GetBordersForSizer --- CHANGES.rst | 4 ++++ demo/StaticBox.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 729df9c4..a3d206fe 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -70,6 +70,10 @@ Changes in this release include the following: * Fix type error that would occur using pycolourchooser. (#957) +* Add wrapper for wx.StaticBox.GetBordersForSizer and use it in the demo to do + platform-specific layout of the items in the StaticBox. (#974) + + 4.0.3 "The show must go on. (Die show-stoppers! Die!)" diff --git a/demo/StaticBox.py b/demo/StaticBox.py index af391417..dd86e5be 100644 --- a/demo/StaticBox.py +++ b/demo/StaticBox.py @@ -10,6 +10,9 @@ class TestPanel(wx.Panel): wx.Panel.__init__(self, parent, -1) box1 = wx.StaticBox(self, -1, "This is a wx.StaticBox") + + # 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) @@ -18,12 +21,14 @@ class TestPanel(wx.Panel): 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)