Skip to content

enums

This module provides commonly used enumerations for the library. It also has a class implementing Enum-s with default values. All Enums below subclass it, meaning you can use their get_default() methods to get the globally set default value.

To modify defaults, use the defaults dictionary.

CenteringPolicy

Bases: DefaultEnum

Policies to center Container according to.

Source code in pytermgui/enums.py
59
60
61
62
63
64
class CenteringPolicy(DefaultEnum):
    """Policies to center `Container` according to."""

    ALL = _auto()
    VERTICAL = _auto()
    HORIZONTAL = _auto()

DefaultEnum

Bases: IntEnum

An Enum class that can return its default value.

Source code in pytermgui/enums.py
35
36
37
38
39
40
41
42
class DefaultEnum(IntEnum):
    """An Enum class that can return its default value."""

    @classmethod
    def get_default(cls) -> IntEnum | None:
        """Get default value"""

        return defaults.get(cls)

get_default() classmethod

Get default value

Source code in pytermgui/enums.py
38
39
40
41
42
@classmethod
def get_default(cls) -> IntEnum | None:
    """Get default value"""

    return defaults.get(cls)

HorizontalAlignment

Bases: DefaultEnum

Policies to align widgets by.

These are applied by the parent object, and are relative to them.

Source code in pytermgui/enums.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class HorizontalAlignment(DefaultEnum):
    """Policies to align widgets by.

    These are applied by the parent object, and are
    relative to them."""

    LEFT = 0
    """Align widget to the left edge."""

    CENTER = 1
    """Center widget in the available width."""

    RIGHT = 2
    """Align widget to the right edge."""

CENTER = 1 class-attribute instance-attribute

Center widget in the available width.

LEFT = 0 class-attribute instance-attribute

Align widget to the left edge.

RIGHT = 2 class-attribute instance-attribute

Align widget to the right edge.

Overflow

Bases: DefaultEnum

Overflow policies implemented by Container.

Source code in pytermgui/enums.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class Overflow(DefaultEnum):
    """Overflow policies implemented by Container."""

    HIDE = 0
    """Stop gathering lines once there is no room left."""

    SCROLL = 1
    """Allow scrolling when there is too many lines."""

    RESIZE = 2
    """Resize parent to fit with the new lines.

    Note:
        When applied to a window, this prevents resizing its height
        using the bottom border.
    """

    # TODO: Implement Overflow.AUTO
    AUTO = 9999
    """NotImplemented"""

AUTO = 9999 class-attribute instance-attribute

NotImplemented

HIDE = 0 class-attribute instance-attribute

Stop gathering lines once there is no room left.

RESIZE = 2 class-attribute instance-attribute

Resize parent to fit with the new lines.

Note

When applied to a window, this prevents resizing its height using the bottom border.

SCROLL = 1 class-attribute instance-attribute

Allow scrolling when there is too many lines.

SizePolicy

Bases: DefaultEnum

Values according to which Widget sizes are assigned.

Source code in pytermgui/enums.py
45
46
47
48
49
50
51
52
53
54
55
56
class SizePolicy(DefaultEnum):
    """Values according to which Widget sizes are assigned."""

    FILL = 0
    """Inner widget will take up as much width as possible."""

    STATIC = 1
    """Inner widget will take up an exact amount of width."""

    RELATIVE = 2
    """Inner widget will take up widget.relative_width * available
    space."""

FILL = 0 class-attribute instance-attribute

Inner widget will take up as much width as possible.

RELATIVE = 2 class-attribute instance-attribute

Inner widget will take up widget.relative_width * available space.

STATIC = 1 class-attribute instance-attribute

Inner widget will take up an exact amount of width.

VerticalAlignment

Bases: DefaultEnum

Vertical alignment options for widgets.

Source code in pytermgui/enums.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class VerticalAlignment(DefaultEnum):
    """Vertical alignment options for widgets."""

    TOP = 0
    """Align widgets to the top"""

    CENTER = 1
    """Align widgets in the center, with equal* padding on the top and bottom.

    Note:
        When the available height is not divisible by 2, the extra line of padding
        is added to the bottom.
    """

    BOTTOM = 2
    """Align widgets to the bottom."""

BOTTOM = 2 class-attribute instance-attribute

Align widgets to the bottom.

CENTER = 1 class-attribute instance-attribute

Align widgets in the center, with equal* padding on the top and bottom.

Note

When the available height is not divisible by 2, the extra line of padding is added to the bottom.

TOP = 0 class-attribute instance-attribute

Align widgets to the top

WidgetChange

Bases: Enum

The type of change that happened within a widget.

Source code in pytermgui/enums.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class WidgetChange(Enum):
    """The type of change that happened within a widget."""

    LINES = _auto()
    """The result of `get_lines` has changed, but size changes didn't happen."""

    SIZE = _auto()
    """Both WIDTH and HEIGHT has changed."""

    WIDTH = _auto()
    """The width of the widget changed, possibly involving LINES type changes."""

    HEIGHT = _auto()
    """The height of the widget changed, possibly involving LINES type changes."""

HEIGHT = _auto() class-attribute instance-attribute

The height of the widget changed, possibly involving LINES type changes.

LINES = _auto() class-attribute instance-attribute

The result of get_lines has changed, but size changes didn't happen.

SIZE = _auto() class-attribute instance-attribute

Both WIDTH and HEIGHT has changed.

WIDTH = _auto() class-attribute instance-attribute

The width of the widget changed, possibly involving LINES type changes.