@@ -1034,35 +1034,36 @@ def put_loading(shape: str = 'border', color: str = 'dark', scope: str = None, p
10341034
10351035 ## ----
10361036 import time # ..demo-only
1037- # Use as context manager, the loading prompt will disappear automatically when the context block exits.
1037+ # The loading prompt and the output inside the context will disappear
1038+ # automatically when the context block exits.
10381039 with put_loading():
1040+ put_text("Start waiting...")
10391041 time.sleep(3) # Some time-consuming operations
1040- put_text("The answer of the universe is 42")
1042+ put_text("The answer of the universe is 42")
10411043
10421044 ## ----
10431045 # using style() to set the size of the loading prompt
10441046 put_loading().style('width:4rem; height:4rem')
1047+
1048+ .. versionchanged:: 1.8
1049+ when use `put_loading()` as context manager, the output inside the context will also been removed
1050+ after the context block exits.
10451051 """
10461052 assert shape in ('border' , 'grow' ), "shape must in ('border', 'grow')"
10471053 assert color in {'primary' , 'secondary' , 'success' , 'danger' , 'warning' , 'info' , 'light' , 'dark' }
10481054
1049- html = """<div class="spinner-{shape} text-{color}" role="status">
1055+ html = """<div><div class="spinner-{shape} text-{color}" role="status">
10501056 <span class="sr-only">Loading...</span>
1051- </div>""" .format (shape = shape , color = color )
1057+ </div></div> """ .format (shape = shape , color = color )
10521058
10531059 scope_name = random_str (10 )
10541060
1055- def enter (self ):
1056- self .spec ['container_dom_id' ] = scope2dom (scope_name , no_css_selector = True )
1057- self .send ()
1058- return scope_name
1059-
1060- def exit_ (self , exc_type , exc_val , exc_tb ):
1061+ def after_exit ():
10611062 remove (scope_name )
10621063 return False # Propagate Exception
10631064
10641065 return put_html (html , sanitize = False , scope = scope , position = position ). \
1065- enable_context_manager (custom_enter = enter , custom_exit = exit_ )
1066+ enable_context_manager (container_dom_id = scope_name , after_exit = after_exit )
10661067
10671068
10681069@safely_destruct_output_when_exp ('content' )
0 commit comments