Trigger toast messages in drag&bot¶
Toast messages are a possibility in drag&bot to give the user quick information or some feedback about a recent performed action. This can e.g. a feedback message, which informs that a triggered operation did or did not succeed.
Interface¶
Usually, toast messages are triggered internally by the web application, but they can also be triggered from a ROS interface. The messages are shown for a fixed amount of time before they disappear and are placed in the notifications log. The type of the message, indicated by the color, can be configured as well as an ID for the sender. The ID is only shown in the notifications log. The message can be specified in several languages, where the message in the language of the user profile is shown in the browser (if available).
A toast message can be triggered via ROS by publishing a message of type dnb_msgs/ToastMessage to the topic /frontend_toast_message.
The interface of the message dnb_msgs/ToastMessage is defined as follows:
uint8 type
# Available type values are:
# ToastMessage.INFO=0 (blue)
# ToastMessage.SUCCESS=1 (green)
# ToastMessage.WARNING=2 (yellow)
# ToastMessage.ERROR=3 (red)
string sender_id
# Optional, can be left empty.
ToastTranslation[] message
# A list of the same message in several languages.
The interface of the message dnb_msgs/ToastMessage is defined as follows:
string language_code
# Currently these language codes are available:
# en for English
# de for German
string value
# The text of the message.
Example¶
The example shows a toast info message with English and German translations.
#!/usr/bin/python3
import rospy
from dnb_msgs.msg import ToastMessage, ToastTranslation
if __name__ == "__main__":
rospy.init_node('toast_publish_example_node')
pub = rospy.Publisher('/frontend_toast_message', ToastMessage, queue_size=10)
# after creating the publisher, ROS needs a moment before messages can be sent
rospy.sleep(1)
toast_message = ToastMessage()
# available type values are:
# ToastMessage.INFO=0 (blue)
# ToastMessage.SUCCESS=1 (green)
# ToastMessage.WARNING=2 (yellow)
# ToastMessage.ERROR=3 (red)
toast_message.type = ToastMessage.INFO
toast_message.sender_id = "Example Node" # optional, can be left empty
translation = ToastTranslation()
# available languages are: en (English), de (German)
translation.language_code = "en"
translation.value = "This is an example message."
toast_message.message.append(translation)
translation = ToastTranslation()
translation.language_code = "de"
translation.value = "Dies ist eine Beispiel-Nachricht."
toast_message.message.append(translation)
pub.publish(toast_message)