holoviz / panel
1
"""
2
This module contains functionality to make any Panel component look
3
like it is loading and disabled.
4
"""
5

6 7
from ..config import config
7

8 7
LOADING_INDICATOR_CSS_CLASS = "pn-loading"
9

10 7
def _add_css_classes(item, css_classes):
11 0
    if not item.css_classes:
12 0
        item.css_classes = css_classes
13
    else:
14 0
        new_classes = [css_class for css_class in css_classes
15
                       if css_class not in item.css_classes]
16 0
        item.css_classes = item.css_classes + new_classes
17

18

19 7
def _remove_css_classes(item, css_classes):
20 7
    if not item.css_classes:
21 7
        return
22 7
    item.css_classes = [css_class for css_class in item.css_classes
23
                        if css_class not in css_classes]
24

25

26 7
def start_loading_spinner(*objects):
27
    """
28
    Changes the appearance of the specified panel objects to indicate
29
    that they are loading.
30

31
    This is done by
32

33
    * adding a small spinner on top
34
    * graying out the panel
35
    * disabling the panel
36
    * and changing the mouse cursor to a spinner when hovering over the panel
37

38
    Arguments
39
    ---------
40
    objects: tuple
41
        The panels to add the loading indicator to.
42
    """
43 0
    css_classes = [LOADING_INDICATOR_CSS_CLASS, config.loading_spinner]
44 0
    for item in objects:
45 0
        if hasattr(item, "css_classes"):
46 0
            _add_css_classes(item, css_classes)
47

48 7
def stop_loading_spinner(*objects):
49
    """
50
    Removes the loading indicating from the specified panel objects.
51

52
    Arguments
53
    ---------
54
    objects: tuple
55
        The panels to remove the loading indicator from.
56
    """
57 7
    css_classes = [LOADING_INDICATOR_CSS_CLASS, config.loading_spinner]
58 7
    for item in objects:
59 7
        if hasattr(item, "css_classes"):
60 7
            _remove_css_classes(item, css_classes)
61

Read our documentation on viewing source code .

Loading