Alert#

Overview#

Alert is a a custom Alert widget. It is used as the output of all processes in the framework. In the voila interfaces, print statement will not be displayed. Instead use the sw.Alert method to provide information to the user. It’s hidden by default and the visibility change every time you create a message. It inherits from the SepalWidget class. Any argument from the original Alert ipyvuetify class can be used to complement it.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert().show()
output

Methods#

Alert object embed several methods that will be displayed in this section.

Note

More information on the methods and their options can be found in the full documentation here

update_progress#

Update the Alert message with a progress bar

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

add_msg#

Add a message in the alert by replacing all the existing one.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

msg1 = 'lorem'

output.add_msg(msg1)

add_live_msg#

Add a message in the alert by replacing all the existing one and add a timestamp.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

msg1 = 'lorem'

output.add_live_msg(msg1)

append_msg#

Append a message in a new parragraph, with or without Divider.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

msg1 = 'lorem'
msg2 = 'ipsum'

output.add_msg(msg1)
output.append_msg(msg2)

remove_last_msg#

Remove the last msg printed in the Alert widget.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

msg1 = 'lorem'
msg2 = 'ipsum'

output.add_msg(msg1)
output.append_msg(msg2)
output.remove_last_msg()

check_input#

Check if the inpupt value is initialized. If not return False and display an error message else return True.

from sepal_ui import sepalwidgets as sw

# correct colors for the documentation
# set to dark in SEPAL by default
import ipyvuetify as v
v.theme.dark = False

output = sw.Alert()

input = None

output.check_input(input)
/tmp/ipykernel_1174/2059771192.py:12: DeprecationWarning: Call to deprecated method check_input. (This method is now part of the utils module) -- Deprecated since version 3.0.
  output.check_input(input)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 12
      8 output = sw.Alert()
     10 input = None
---> 12 output.check_input(input)

File ~/checkouts/readthedocs.org/user_builds/sepal-ui/envs/latest/lib/python3.10/site-packages/deprecated/classic.py:285, in deprecated.<locals>.wrapper_function(wrapped_, instance_, args_, kwargs_)
    283 else:
    284     warnings.warn(msg, category=category, stacklevel=_routine_stacklevel)
--> 285 return wrapped_(*args_, **kwargs_)

File ~/checkouts/readthedocs.org/user_builds/sepal-ui/checkouts/latest/sepal_ui/sepalwidgets/alert.py:251, in Alert.check_input(self, input_, msg)
    238 r"""Check if the inpupt value is initialized.
    239 
    240 If not return false and display an error message else return True.
   (...)
    247     check if the value is initialized
    248 """
    249 msg = msg or ms.utils.check_input.error
--> 251 return su.check_input(input_, msg)

File ~/checkouts/readthedocs.org/user_builds/sepal-ui/checkouts/latest/sepal_ui/scripts/utils.py:375, in check_input(input_, msg)
    372     init = False if input_ is None else init
    374 if init is False:
--> 375     raise ValueError(msg)
    377 return init

ValueError: The value has not been initialized

Note

The Alert component is a key component of the tile component as it can test variable initialization, bind variable to widget, and display processes in voila dashboard. More information can be found here.