Spinner control

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.

@carles please try not to revive very old threads with new questions. I’ve moved it to the Q and A section where it will get more attention.

Thanks, sorry, I was not sure how it worked.

1 Like

What about using the context-manager shown here?