Skip to content

ActivityIndicator

Usage

On most platforms, an ActivityIndicator is usually rendered as a "spinner".

import toga

indicator = toga.ActivityIndicator()

# Start the animation
indicator.start()

# Stop the animation
indicator.stop()

Notes

  • The ActivityIndicator will always take up a fixed amount of physical space in a layout. However, the widget will not be visible when it is in a "stopped" state.

Reference

Bases: Widget

Source code in core/src/toga/widgets/activityindicator.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class ActivityIndicator(Widget):
    def __init__(
        self,
        id: str | None = None,
        style: StyleT | None = None,
        running: bool = False,
        **kwargs,
    ):
        """Create a new ActivityIndicator widget.

        :param id: The ID for the widget.
        :param style: A style object. If no style is provided, a default style
            will be applied to the widget.
        :param running: Describes whether the indicator is running at the
            time it is created.
        :param kwargs: Initial style properties.
        """
        super().__init__(id, style, **kwargs)

        if running:
            self.start()

    def _create(self) -> Any:
        return self.factory.ActivityIndicator(interface=self)

    @property
    def enabled(self) -> Literal[True]:
        """Is the widget currently enabled? i.e., can the user interact with the widget?

        ActivityIndicator widgets cannot be disabled; this property will always return
        True; any attempt to modify it will be ignored.
        """
        return True

    @enabled.setter
    def enabled(self, value: bool) -> None:
        pass

    def focus(self) -> None:
        """No-op; ActivityIndicator cannot accept input focus."""
        pass

    @property
    def is_running(self) -> bool:
        """Determine if the activity indicator is currently running.

        Use `start()` and `stop()` to change the running state.

        True if this activity indicator is running; False otherwise.
        """
        return self._impl.is_running()

    def start(self) -> None:
        """Start the activity indicator.

        If the activity indicator is already started, this is a no-op.
        """
        if not self.is_running:
            self._impl.start()

    def stop(self) -> None:
        """Stop the activity indicator.

        If the activity indicator is already stopped, this is a no-op.
        """
        if self.is_running:
            self._impl.stop()

enabled property writable

Is the widget currently enabled? i.e., can the user interact with the widget?

ActivityIndicator widgets cannot be disabled; this property will always return True; any attempt to modify it will be ignored.

is_running property

Determine if the activity indicator is currently running.

Use start() and stop() to change the running state.

True if this activity indicator is running; False otherwise.

__init__(id=None, style=None, running=False, **kwargs)

Create a new ActivityIndicator widget.

:param id: The ID for the widget. :param style: A style object. If no style is provided, a default style will be applied to the widget. :param running: Describes whether the indicator is running at the time it is created. :param kwargs: Initial style properties.

Source code in core/src/toga/widgets/activityindicator.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def __init__(
    self,
    id: str | None = None,
    style: StyleT | None = None,
    running: bool = False,
    **kwargs,
):
    """Create a new ActivityIndicator widget.

    :param id: The ID for the widget.
    :param style: A style object. If no style is provided, a default style
        will be applied to the widget.
    :param running: Describes whether the indicator is running at the
        time it is created.
    :param kwargs: Initial style properties.
    """
    super().__init__(id, style, **kwargs)

    if running:
        self.start()

focus()

No-op; ActivityIndicator cannot accept input focus.

Source code in core/src/toga/widgets/activityindicator.py
46
47
48
def focus(self) -> None:
    """No-op; ActivityIndicator cannot accept input focus."""
    pass

start()

Start the activity indicator.

If the activity indicator is already started, this is a no-op.

Source code in core/src/toga/widgets/activityindicator.py
60
61
62
63
64
65
66
def start(self) -> None:
    """Start the activity indicator.

    If the activity indicator is already started, this is a no-op.
    """
    if not self.is_running:
        self._impl.start()

stop()

Stop the activity indicator.

If the activity indicator is already stopped, this is a no-op.

Source code in core/src/toga/widgets/activityindicator.py
68
69
70
71
72
73
74
def stop(self) -> None:
    """Stop the activity indicator.

    If the activity indicator is already stopped, this is a no-op.
    """
    if self.is_running:
        self._impl.stop()