/
loading.py
61 lines (48 loc) · 1.7 KB
/
loading.py
1
2
3
4
5
6
7
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
"""
This module contains functionality to make any Panel component look
like it is loading and disabled.
"""
from ..config import config
LOADING_INDICATOR_CSS_CLASS = "pn-loading"
def _add_css_classes(item, css_classes):
if not item.css_classes:
item.css_classes = css_classes
else:
new_classes = [css_class for css_class in css_classes
if css_class not in item.css_classes]
item.css_classes = item.css_classes + new_classes
def _remove_css_classes(item, css_classes):
if not item.css_classes:
return
item.css_classes = [css_class for css_class in item.css_classes
if css_class not in css_classes]
def start_loading_spinner(*objects):
"""
Changes the appearance of the specified panel objects to indicate
that they are loading.
This is done by
* adding a small spinner on top
* graying out the panel
* disabling the panel
* and changing the mouse cursor to a spinner when hovering over the panel
Arguments
---------
objects: tuple
The panels to add the loading indicator to.
"""
css_classes = [LOADING_INDICATOR_CSS_CLASS, config.loading_spinner]
for item in objects:
if hasattr(item, "css_classes"):
_add_css_classes(item, css_classes)
def stop_loading_spinner(*objects):
"""
Removes the loading indicating from the specified panel objects.
Arguments
---------
objects: tuple
The panels to remove the loading indicator from.
"""
css_classes = [LOADING_INDICATOR_CSS_CLASS, config.loading_spinner]
for item in objects:
if hasattr(item, "css_classes"):
_remove_css_classes(item, css_classes)