I implemented this class, also adding two extra methods to hide and show the indicator manually.
class Loading_indicator:
"""
This class defines a loading indicator.
It has methods to show and hide the loading indicator.
"""
def __call__(self, func):
# @wraps(func)
def wrapper(*args, **kw):
with self:
return func(*args, **kw)
return wrapper
def __enter__(self):
_anvil.js.call_js('setLoading', True)
return self
def __exit__(self, exc_type, exc_value, tb):
_anvil.js.call_js('setLoading', False)
def hide(self):
_anvil.js.call_js('setLoading', False)
def show(self):
_anvil.js.call_js('setLoading', True)
# Creating an instance of the loading indicator
loading_indicator = Loading_indicator()
From inside a function that shows the spinner I am trying to hide it at a certain point in time by using loading_indicator.hide(). The spinner stays visible. Is there a way to achieve this, to allow a spinner to be shown during a loop but to hide it at a certain point? I got it working using:
with loading indicator:
#code
if condition = True:
loading_indicator.hide()
But it only works once. The second time the indicator does not appear.