Container for sizer items flags providing readable names for them.
Normally, when you add an item to a sizer via wx.Sizer.Add
, you have to specify a lot of flags and parameters which can be unwieldy. This is where wx.SizerFlags comes in: it allows you to specify all parameters using the named methods instead. For example, instead of
sizer.Add(ctrl, 0, wx.EXPAND | wx.ALL, 10)
you can now write
sizer.Add(ctrl, wx.SizerFlags().Expand().Border(wx.ALL, 10))
This is more readable and also allows you to create wx.SizerFlags objects which can be reused for several sizer items.
flagsExpand = wx.SizerFlags(1)
flagsExpand.Expand().Border(wx.ALL, 10)
sizer.Add(ctrl1, flagsExpand)
sizer.Add(ctrl2, flagsExpand)
Note that by specification, all methods of wx.SizerFlags return the wx.SizerFlags object itself to allowing chaining multiple methods calls like in the examples above.
See also
Creates the wx.Sizer with the proportion specified by proportion. |
|
Sets the alignment of this wx.SizerFlags to align. |
|
Sets the wx.SizerFlags to have a border of a number of pixels specified by borderinpixels with the directions specified by direction. |
|
Aligns the object to the bottom, similar for |
|
Sets the object of the wx.SizerFlags to center itself in the area it is given. |
|
Same as |
|
Same as |
|
|
|
Center an item only in horizontal direction. |
|
Center an item only in vertical direction. |
|
Globally disable checks for sizer flag consistency in debug builds. |
|
Sets the border in the given direction having twice the default border size. |
|
Sets the border in left and right directions having twice the default border size. |
|
Sets the object of the wx.SizerFlags to expand to fill as much area as it can. |
|
Set the |
|
Returns the border used by default in wx.Border method. |
|
Returns the border used by default, with fractional precision. |
|
Sets the border in left and right directions having the default border size. |
|
Aligns the object to the left, similar for |
|
Sets the proportion of this wx.SizerFlags to proportion. |
|
Set the |
|
Aligns the object to the right, similar for |
|
Set the |
|
Aligns the object to the top, similar for |
|
Sets the border in the given direction having thrice the default border size. |
wx.
SizerFlags
(object)¶Possible constructors:
SizerFlags(proportion=0)
Container for sizer items flags providing readable names for them.
__init__
(self, proportion=0)¶Creates the wx.Sizer with the proportion specified by proportion.
proportion (int) –
Align
(self, alignment)¶Sets the alignment of this wx.SizerFlags to align.
This method replaces the previously set alignment with the specified one.
alignment (int) – Combination of ALIGN_XXX
bit masks.
See also
wx.Top
, wx.Left
, wx.Right
, wx.Bottom
, wx.Centre
Border
(self, *args, **kw)¶Border (self, direction, borderinpixels)
Sets the wx.SizerFlags to have a border of a number of pixels specified by borderinpixels with the directions specified by direction.
Prefer to use the overload below or DoubleBorder
or TripleBorder
versions instead of hard-coding the border value in pixels to avoid too small borders on devices with high DPI
displays.
direction (int) –
borderinpixels (int) –
Border (self, direction=ALL)
Sets the wx.SizerFlags to have a border with size as returned by GetDefaultBorder
.
direction (int) – Direction(s) to apply the border in.
Bottom
(self)¶Aligns the object to the bottom, similar for Align(wxALIGN_BOTTOM)
.
Unlike Align
, this method doesn’t change the horizontal alignment of the item.
Center
(self)¶Sets the object of the wx.SizerFlags to center itself in the area it is given.
CenterHorizontal
(self)¶Same as CentreHorizontal
.
New in version 4.1/wxWidgets-3.1.0.
CenterVertical
(self)¶Same as CentreVertical
.
New in version 4.1/wxWidgets-3.1.0.
Centre
(self)¶wx.Center
for people with the other dialect of English.
CentreHorizontal
(self)¶Center an item only in horizontal direction.
This is mostly useful for 2D
sizers as for the 1D
ones it is shorter to just use wx.Centre
as the alignment is only used in one direction with them anyhow. For 2D
sizers, centering an item in one direction is quite different from centering it in both directions however.
Note that, unlike Align
, this method doesn’t change the vertical alignment.
New in version 4.1/wxWidgets-3.1.0.
See also
CentreVertical
(self)¶Center an item only in vertical direction.
The remarks in CentreHorizontal
documentation also apply to this function.
Note that, unlike Align
, this method doesn’t change the horizontal alignment.
New in version 4.1/wxWidgets-3.1.0.
DisableConsistencyChecks
()¶Globally disable checks for sizer flag consistency in debug builds.
By default, sizer classes such as wx.BoxSizer and wx.FlexGridSizer assert when passed invalid flags, even though doing this usually doesn’t result in any catastrophic consequences and the invalid flags are simply ignored later. Due to this, and the fact that these checks were only added in wxWidgets 3.1, existing code may run into multiple asserts warning about incorrect sizer flags use. Using this function provides a temporary solution for avoiding such asserts when upgrading to wxWidgets 3.1 from a previous version and will prevent such checks from being done.
Please do note that correcting the code by removing the invalid flags remains a much better solution as these asserts may be very helpful to understand why some code using sizer flags doesn’t work as expected, so using this function, especially permanently, rather than a temporary workaround, is not recommended.
Notice that the same effect as calling this function can be achieved by setting the environment variable WXSUPPRESS_SIZER_FLAGS_CHECK
to any value.
New in version 4.1/wxWidgets-3.1.6.
DoubleBorder
(self, direction=ALL)¶Sets the border in the given direction having twice the default border size.
direction (int) –
DoubleHorzBorder
(self)¶Sets the border in left and right directions having twice the default border size.
Expand
(self)¶Sets the object of the wx.SizerFlags to expand to fill as much area as it can.
FixedMinSize
(self)¶Set the FIXED_MINSIZE
flag which indicates that the initial size of the window should be also set as its minimal size.
GetDefaultBorder
()¶Returns the border used by default in wx.Border method.
This value is scaled appropriately for the current DPI
on the systems where physical pixel values are used for the control positions and sizes, i.e. not with wxGTK or wxOSX.
int
See also
GetDefaultBorderFractional
()¶Returns the border used by default, with fractional precision.
For example when the border is scaled to a non-integer DPI
.
float
New in version 4.1/wxWidgets-3.1.4.
See also
HorzBorder
(self)¶Sets the border in left and right directions having the default border size.
Left
(self)¶Aligns the object to the left, similar for Align(wxALIGN_LEFT)
.
Unlike Align
, this method doesn’t change the vertical alignment of the item.
Proportion
(self, proportion)¶Sets the proportion of this wx.SizerFlags to proportion.
proportion (int) –
ReserveSpaceEvenIfHidden
(self)¶Set the RESERVE_SPACE_EVEN_IF_HIDDEN
flag.
Normally Sizers don’t allocate space for hidden windows or other items. This flag overrides this behaviour so that sufficient space is allocated for the window even if it isn’t visible. This makes it possible to dynamically show and hide controls without resizing parent dialog, for example.
New in version 2.8.8.
Right
(self)¶Aligns the object to the right, similar for Align(wxALIGN_RIGHT)
.
Unlike Align
, this method doesn’t change the vertical alignment of the item.
Shaped
(self)¶Set the _SHAPED
flag which indicates that the elements should always keep the fixed width to height ratio equal to its original value.
Top
(self)¶Aligns the object to the top, similar for Align(wxALIGN_TOP)
.
Unlike Align
, this method doesn’t change the horizontal alignment of the item.
TripleBorder
(self, direction=ALL)¶Sets the border in the given direction having thrice the default border size.
direction (int) –