Sugar.graphics.alert: Difference between revisions

From OLPC
Jump to navigation Jump to search
Line 4: Line 4:


[[Image:sugar-simple-alert.jpg]]
[[Image:sugar-simple-alert.jpg]]


=== How do I create a simple alert message? ===

You can create the most basic alert message by first creating a new instance of the Alert class and then calling the add_alert() method for your activity.

<pre>
# Create a new simple alert
alert = Alert()
# Populate the title and text body of the alert.
alert.props.title=_('Title of Alert Goes Here')
alert.props.msg = _('Text message of alert goes here')
# Call the add_alert() method (inherited via the sugar.graphics.Window superclass of Activity)
# to add this alert to the activity window.
self.add_alert(alert)
alert.show()
</pre>

Revision as of 14:43, 26 June 2008

Class: Alert

Alerts appear at the top of the body of your activity, just below the toolbox if it is visible. The image below shows what a simple alert without a button looks like.

Sugar-simple-alert.jpg


How do I create a simple alert message?

You can create the most basic alert message by first creating a new instance of the Alert class and then calling the add_alert() method for your activity.

       # Create a new simple alert
        alert = Alert()
        # Populate the title and text body of the alert. 
        alert.props.title=_('Title of Alert Goes Here')
        alert.props.msg = _('Text message of alert goes here')
        # Call the add_alert() method (inherited via the sugar.graphics.Window superclass of Activity)
        # to add this alert to the activity window. 
        self.add_alert(alert)
        alert.show()