Skip to content

API Reference

Epihaius edited this page Jan 18, 2021 · 4 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 pixels) 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: Widget|Sizer|int tuple, proportions: float tuple, alignments: str tuple, borders: int tuple, index: int) → SizerCell

Append (if index is None) or insert either a Widget 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 (0.0, 0.0).
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 pixels) 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_widgets(include_children: bool) → list

Return a list of all the Widget instances (and their descendant widgets if include_children 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() → int tuple

Return the current coordinates of this 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 associated with the window, whenever this window is resized.

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|Widget: the object that this sizer belongs to (either it's a sub-sizer or it's assigned to a widget).
owner_widgetWidget: the widget 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: Widget|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.

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.

get_size() → int tuple

Return the width and height of this cell.

Public attributes

type → str: the type of the object in this cell ("widget", "sizer" or "size").
objectWidget|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 Widget

__init__(dgui_obj: DirectGuiWidget)

Create a widget to connect the given DirectGuiWidget dgui_obj to the layout system.

destroy()

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

set_size(size: int tuple) → int tuple

Set the width and height of this widget.
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 widget.

set_pos(pos: int tuple)

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

get_pos() → int tuple

Return the current coordinates of this widget.

reset_frame_size()

Calculate the new minimum size of this widget and call resetFrameSize() on the DirectGuiWidget it is associated with.

Public attributes

type → str: "widget".
sizerSizer: the sizer assigned to this widget.
sizer_cellSizerCell: the sizer cell that this widget is contained in.
min_size → int tuple: the minimum size of this widget.

class ScrolledListWidget(Widget)

__init__(dgui_obj: DirectScrolledList, scrollbtn_proportion: float, scrollbtn_borders: int tuple, itemframe_borders: int tuple, margins: int tuple)

Create a widget to connect the given DirectScrolledList dgui_obj to the layout system.
The margins specify the left and right borders around the items in the frame.

add_item(item: DirectGuiWidget, refresh: bool, expand: bool)

Add the DirectGuiWidget item to this list.
The refresh parameter (default False) is passed to the DirectScrolledList.addItem method.
If expand is True (the default), the item will take up the available width of the frame.

remove_item(item: DirectGuiWidget, refresh: bool)

Remove the DirectGuiWidget item from this list.
The refresh parameter (default False) is passed to the DirectScrolledList.removeItem method.

class ScrolledFrameWidget(Widget)

__init__(dgui_obj: DirectScrolledFrame, scroll_dir: str)

Create a widget to connect the given DirectScrolledFrame dgui_obj to the layout system.

Clone this wiki locally