mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 01:30:07 +01:00
Merge pull request #980 from RobinD42/fix-issue974
Add wx.StaticBox.GetBordersForSizer
This commit is contained in:
@@ -72,6 +72,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)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user