Cell Size

A Size object is used to represent the width and height of a Cell. The width is the number of spanned columns and the height is the number of spanned rows. The default cell size is (1, 1).

This module defines the Size tuple and give some classic use cases.

class benker.size.Size(width, height)

Bases: benker.size.SizeTuple

Size of a cell: width is the number of columns and height is the number of row.

Usage:

>>> from benker.size import Size
>>> size = Size(2, 1)
>>> size
Size(width=2, height=1)
>>> size.width
2
>>> size.height
1
>>> str(size)
'(2 x 1)'

You can use the “+” or “-” operators to increase or decrease the size:

>>> Size(2, 1) + Size(3, 3)
Size(width=5, height=4)
>>> Size(5, 4) - Size(3, 3)
Size(width=2, height=1)

You can expand the width and height to a given factor using the “*” operator:

>>> Size(2, 1) * 2
Size(width=4, height=2)

You can have negative or positive sizes using the unary operators “-” and “+”:

>>> +Size(3, 2)
Size(width=3, height=2)
>>> -Size(3, 2)
Size(width=-3, height=-2)

Note

A Cell object cannot have a negative or nul sizes, but you can need this values for calculation, for instance when you want to reduce the cell size.

classmethod from_value(value)

Convert a value of type tuple to a Size tuple.

Parameters

value – tuple of two integers or Size tuple.

Returns

Newly created object.

Raises

TypeError – if the value is not a tuple of integers nor a Size tuple.

class benker.size.SizeTuple(width, height)

Bases: tuple

height

Alias for field number 1

width

Alias for field number 0