MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / put_loading

Function put_loading

pywebio/output.py:1052–1103  ·  view source on GitHub ↗

Output loading prompt :param str shape: The shape of loading prompt. The available values are: `'border'` (default)、 `'grow'` :param str color: The color of loading prompt. The available values are: `'primary'` 、 `'secondary'` 、 `'success'` 、 `'danger'` 、 `'warning'` 、`'info'` 、`'l

(shape: str = 'border', color: str = 'dark', scope: str = None,
                position: int = OutputPosition.BOTTOM)

Source from the content-addressed store, hash-verified

1050
1051
1052def put_loading(shape: str = 'border', color: str = 'dark', scope: str = None,
1053 position: int = OutputPosition.BOTTOM) -> Output:
1054 """Output loading prompt
1055
1056 :param str shape: The shape of loading prompt. The available values are: `'border'` (default)、 `'grow'`
1057 :param str color: The color of loading prompt. The available values are: `'primary'` 、 `'secondary'` 、
1058 `'success'` 、 `'danger'` 、 `'warning'` 、`'info'` 、`'light'` 、 `'dark'` (default)
1059 :param int scope, position: Those arguments have the same meaning as for `put_text()`
1060
1061 `put_loading()` can be used in 2 ways: direct call and context manager:
1062
1063 .. exportable-codeblock::
1064 :name: put_loading
1065 :summary: `put_loading()` usage
1066
1067 for shape in ('border', 'grow'):
1068 for color in ('primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'):
1069 put_text(shape, color)
1070 put_loading(shape=shape, color=color)
1071
1072 ## ----
1073 import time # ..demo-only
1074 # The loading prompt and the output inside the context will disappear
1075 # automatically when the context block exits.
1076 with put_loading():
1077 put_text("Start waiting...")
1078 time.sleep(3) # Some time-consuming operations
1079 put_text("The answer of the universe is 42")
1080
1081 ## ----
1082 # using style() to set the size of the loading prompt
1083 put_loading().style('width:4rem; height:4rem')
1084
1085 .. versionchanged:: 1.8
1086 when use `put_loading()` as context manager, the output inside the context will also been removed
1087 after the context block exits.
1088 """
1089 assert shape in ('border', 'grow'), "shape must in ('border', 'grow')"
1090 assert color in {'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'}
1091
1092 html = """<div><div class="spinner-{shape} text-{color}" role="status">
1093 <span class="sr-only">Loading...</span>
1094 </div></div>""".format(shape=shape, color=color)
1095
1096 scope_name = random_str(10)
1097
1098 def after_exit():
1099 remove(scope_name)
1100 return False # Propagate Exception
1101
1102 return put_html(html, sanitize=False, scope=scope, position=position). \
1103 enable_context_manager(container_dom_id=scope_name, after_exit=after_exit)
1104
1105
1106@safely_destruct_output_when_exp('content')

Callers 4

basic_outputFunction · 0.85
mainFunction · 0.85
output_widgetsFunction · 0.85
mainFunction · 0.85

Calls 3

random_strFunction · 0.85
put_htmlFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…