Skip to content

API Reference

Epihaius edited this page Jan 12, 2021 · 3 revisions

class Sizer

__init__(prim_dir: str, prim_limit: int, gaps: int tuple)

Create a sizer whose objects will be added in the direction specified by prim_dir. Its value can be either "horizontal" or "vertical".
If prim_limit is bigger than zero, after adding that number of objects, the next object will be added to a new row (if prim_dir equals "horizontal") or column.
The amount (in arbitrary units) of horizontal and/or vertical space to be added between the columns and/or rows of this sizer is controlled with the gaps parameter. Default is (0, 0).

destroy()

This method will destroy all of the cells and their objects as well.
It is usually not necessary to call this method directly; it gets called automatically when removing this sizer's cell from the containing sizer using Sizer.remove_cell(cell, destroy=True).

clear(destroy_cells: bool)

Remove all cells from this sizer, optionally destroying them as well as the objects they contain.

add(obj: Primitive|Sizer|int tuple, proportions: float tuple, alignments: str tuple, borders: int tuple, index: int) → SizerCell

Append (if index is None) or insert either a Primitive or Sizer instance or a (width, height) tuple (empty space).
A SizerCell will be created to "contain" the given object. This cell will have the width of its column and the height of its row. To make that column and/or row take up a certain amount of the space available to this sizer, a horizontal and/or vertical proportion can be requested which will be associated with the cell. What proportions will ultimately be used for the column/row depends on those associated with other cells and those set explicitly for that column/row. The default value for proportions is (-1.0, -1.0), meaning that the local or global defaults will be considered instead.
With the alignments parameter, the given object can be set to expand so it takes up all of its cell's width and/or height, or it can be aligned to the cell in several ways. The possible values (for both the horizontal and the vertical direction) are:

  • "expand" (the default)
  • "min" (left-aligned for horizontal sizers, top-aligned for vertical sizers)
  • "max" (right-aligned for horizontal sizers, bottom-aligned for vertical sizers)
  • "center"

The given object can also be given different borders; these are the offsets (in arbitrary units) from the left, right, bottom and top sides of its cell.

add_cell(cell: SizerCell, index: int)

Append (if index is None) or insert a cell that does not currently belong to any sizer.

remove_cell(cell: SizerCell, destroy: bool)

Remove the given cell from this sizer, optionally destroying it and the object it contains.

get_primitives(include_attached: bool) → list

Return a list of all the Primitive instances (and their "descendant" primitives if include_attached is True) whose layout is controlled by this sizer.

set_min_size_stale(stale: bool)

This method can be called to force or prevent a recalculation of the minimum size of this sizer when update_min_size is called.
Use with caution.

update_min_size() → int tuple

Recalculate the minimum size of this sizer.
This method should usually not be called by application code, as this is the task of the containing sizer.

static get_global_default_proportions() → float tuple

Return the proportions to be applied to any sizer's columns and rows when there is no explicitly set proportion and no proportions associated with any cells for those columns and/or rows.

static set_global_default_proportions(column_proportion: float, row_proportion: float)

Set the proportions to be applied to any sizer's columns and rows when there is no explicitly set proportion and no proportions associated with any cells for those columns and/or rows. The default value for both parameters is 0.0.

get_default_proportions() → float tuple

Return the proportions to be applied to this sizer's columns and rows when there is no explicitly set proportion and no proportions associated with any cells for those columns and/or rows.

set_default_proportions(column_proportion: float, row_proportion: float)

Set the proportions to be applied to this sizer's columns and rows when there is no explicitly set proportion and no proportions associated with any cells for those columns and/or rows. The default value for both parameters is -1.0, meaning that the global defaults will be used instead.

has_row_proportion(index: int) → bool

Check whether a vertical proportion has been explicitly set for the row with the given index.

get_row_proportion(index: int) → float

Return the vertical proportion that has been explicitly set for the row with the given index.
It is an error to call this if has_row_proportion(index) returns False.

set_row_proportion(index: int, proportion: float)

Explicitly set a vertical proportion for the row with the given index. It will override the vertical proportions associated with any cell added to that row.

clear_row_proportion(index: int)

Remove the vertical proportion that has been explicitly set for the row with the given index.
This undoes the effect of a previous call to set_row_proportion for that row; its new vertical proportion will be the largest one of those associated with its cells (or the local or global default value if there are no proportions associated with any cells).

clear_row_proportions()

Remove the vertical proportions that were explicitly set for any of the rows of this sizer.
See clear_row_proportion.

has_column_proportion(index: int) → bool

Check whether a horizontal proportion has been explicitly set for the column with the given index.

get_column_proportion(index: int) → float

Return the horizontal proportion that has been explicitly set for the column with the given index.
It is an error to call this if has_column_proportion(index) returns False.

set_column_proportion(index: int, proportion: float)

Explicitly set a horizontal proportion for the column with the given index. It will override the horizontal proportions associated with any cell added to that column.

clear_column_proportion(index: int)

Remove the horizontal proportion that has been explicitly set for the column with the given index.
This undoes the effect of a previous call to set_column_proportion for that column; its new horizontal proportion will be the largest one of those associated with its cells (or the local or global default value if there are no proportions associated with any cells).

clear_column_proportions()

Remove the horizontal proportions that were explicitly set for any of the columns of this sizer.
See clear_column_proportion.

clear_proportions()

Remove the proportions that were explicitly set for any of the rows and columns of this sizer.
See clear_row_proportion and clear_column_proportion.

get_size() → int tuple

Return the width and height of this sizer.

set_size(size: int tuple, force: bool)

Set the width and height of this sizer and all of the objects controlled by it.
This method should usually not be called by application code, as this is the task of the containing sizer.

get_pos(net: bool) → int tuple

Return the current coordinates of this sizer. The position is relative to the layout origin if net is True, otherwise it is relative to the outermost containing sizer's origin (if this is a sub-sizer).

set_pos(pos: int tuple)

Set the new coordinates of this sizer.
This method should usually not be called by application code, as this is the task of the containing sizer.

update_positions()

Update the coordinates of this sizer and all of the objects controlled by it.
This method should usually not be called by application code, as this is the task of the containing sizer.

update(size: int tuple)

Update the minimum size, the actual size and the coordinates of this sizer and all of the objects controlled by it.
This method should usually be called on the "main" sizer, whenever the available size is changed.

Public attributes

type → str: "sizer".
prim_dir → str: the primary direction in which objects are added to this sizer.
prim_limit → int: the maximum number of objects that can be added along the primary direction of this sizer.
gaps → int tuple: the horizontal and vertical space between the columns and rows of this sizer.
ownerSizer|Primitive: the object that this sizer belongs to (either it's a sub-sizer or it's assigned to a primitive).
owner_primitivePrimitive: the primitive that this sizer ultimately belongs to (directly assigned to or as a sub-sizer).
sizer_cellSizerCell: the cell that this sizer is contained in (if it's a sub-sizer).
default_size → int tuple: the minimum size of this sizer without any cells.
min_size → int tuple: the minimum size of this sizer needed to accommodate all of its cells.
cells → list: the cells in this sizer.

class SizerCell

__init__(sizer: Sizer, obj: Primitive|Sizer|int tuple, obj_type: str, proportions: float tuple, alignments: str tuple, borders: int tuple)

Create a cell to contain the given object obj.
SizerCell instances should never be created by application code, as they are automatically created when adding objects to a sizer.

destroy()

Destroy this cell and the object it contains.

update_min_size() → int tuple

Recalculate the minimum size of this cell.
This method should usually not be called by application code, as this is the task of the containing sizer.

get_size() → int tuple

Return the width and height of this cell.

set_size(size: int tuple)

Set the width and height of this cell.
This method should usually not be called by application code, as this is the task of the containing sizer.

Public attributes

type → str: the type of the object in this cell ("primitive", "sizer" or "size").
objectPrimitive|Sizer|int tuple: the object in this cell.
sizerSizer: the sizer that this cell belongs to.
proportions → float tuple: the proportions associated with this cell.
alignments → str tuple: the sides of this cell that its object is aligned to.
borders → int tuple: the offsets of this cell's object from the sides of the cell.
object_offset → int tuple: the left and top offsets of this cell's object.
min_size → int tuple: the minimum size of this cell needed to accommodate its object and the borders around it.

class Primitive

__init__(size: int tuple, sizer_borders: int tuple)

Create a primitive with a certain width and height to connect to the layout system.
The given sizer_borders define the offsets of the sizer assigned to this primitive from the left, right, bottom and top sides of the primitive.

destroy()

Destroy this primitive.
It is usually not necessary to call this method directly; it gets called automatically when destroying the sizer cell it is contained in.

get_size() → int tuple

Return the width and height of this primitive.

set_size(size: int tuple) → int tuple

Set the width and height of this primitive.
This method should usually not be called by application code, as this is the task of the containing sizer.

get_pos(net: bool) → int tuple

Return the current coordinates of this primitive. The position is relative to the layout origin if net is True, otherwise it is relative to the outermost containing sizer's origin (the former needs to be implemented in derived classes).

set_pos(pos: int tuple)

Set the new coordinates of this primitive.
This method should usually not be called by application code, as this is the task of the containing sizer.

Public attributes

type → str: "primitive".
sizerSizer: the sizer assigned to this primitive.
sizer_cellSizerCell: the sizer cell that this primitive is contained in.
min_size → int tuple: the minimum size of this primitive.
on_destroy, on_resize, on_reposition: optional handlers to be called when destroy, set_size or set_pos is called, respectively.

Clone this wiki locally