Home Software Hardware Misc About

GlobSizer

vs. 1.1 (19/09/2020)

GlobSizer is a wxPython sizer for your extremely dynamic user interfaces, should you need to add or remove widgets during execution. It is a class derived from wx.GridBagSizer but that also allows to insert and delete sizer rows and columns on the fly while managing spanned items.

Suppose your GUI has widgets layed out with a GlobSizer:

You can now, for example, do a GlobSizer.InsertCol(2):

It recalculates the span for affected items accordingly, and shifts widgets when needed. The same applies to row manipulation. If now you GlobSizer.InsertRow(3), the layout will change to this:

You can also delete rows or cols. For example, GlobSizer.DeleteCol(3) and GlobSizer.DeleteCol(4) will produce the following result:

GlobSizer can also delete unused rows and columns. Using DeleteEmptyRows and DeleteEmptyCols results in:

Click here to download the code containing the GlobSizer class.

Tested on wxPython 4.1.0 (gtk3) on Python 3.7.3 on Raspberry Pi OS and on wxPython 4.1.0 (gtk2) on Python 3.8.2 on Mint (Mate). GlobSizer is distributed under the BSD-3-Clause License.


Methods

All the GridBagSizer methods apply, plus the following ones:

InsertRow(row), InsertCol(col), DeleteRow(row), DeleteCol(col)

Insert/delete a row or col.

GetGrowableRows(), GetGrowableCols()

Returns a list of rows or cols previously defined as growable.

SetGap(gap)

Where gap is a tuple, this is the same as wx.GridBagSizer's SetVGap(gap[0]); SetHGap(gap[1]).

GetGap()

Returns a tuple; this is the same as GridBagSizer's (GetVGap(), GetHGap()).

GetItemPositions(*args, **kwargs)

Uses the same API for wx.GridBagSizer's GetItemPosition, but returns a list of all positions occupied by a spanned item, as GetItemPosition only returns its top-left position. If the item queried has a span of (1, 1), this method will return a list of one element.

FindUnspannedItemAtPosition(*args, **kwargs)

Uses the same API for wx.GridBagSizer's FindItemAtPosition, but while FindItemAtPosition will return a valid spanned item even if the position (r, c) is not its top-left position, this method will only return a valid item (spanned or not) if the position passed is the top-left. As for unspanned items, it will always return a valid item.