Ticket #2140: 0001-Add-ErrorAlert-inherited-from-Alert.patch

File 0001-Add-ErrorAlert-inherited-from-Alert.patch, 2.9 KB (added by m_anish, 14 years ago)

Add ErrorAlert to graphics/alert.py

  • src/sugar/graphics/alert.py

    From c24f654a1e77cd9b6d77d42041882f2b06f4610c Mon Sep 17 00:00:00 2001
    From: anishmangal2002 <anishmangal2002@gmail.com>
    Date: Mon, 14 Jun 2010 02:21:23 +0000
    Subject: [PATCH] Add ErrorAlert inherited from Alert
    
    Adds the ErrorAlert class which is an alert inherited from
    the base Alert class. This is very similar to the
    ConfirmationAlert class with the difference being that it
    only displays an 'Ok' button in the Alert popup.
    
    Signed-off-by: anishmangal2002 <anishmangal2002@gmail.com>
    ---
     src/sugar/graphics/alert.py |   45 +++++++++++++++++++++++++++++++++++++++++++
     1 files changed, 45 insertions(+), 0 deletions(-)
    
    diff --git a/src/sugar/graphics/alert.py b/src/sugar/graphics/alert.py
    index 4441909..a4dd017 100644
    a b create a simple alert message. 
    2828STABLE.
    2929"""
    3030# Copyright (C) 2007, One Laptop Per Child
     31# Copyright (C) 2010, Anish Mangal <anishmangal2002@gmail.com>
    3132#
    3233# This library is free software; you can redistribute it and/or
    3334# modify it under the terms of the GNU Lesser General Public
    class ConfirmationAlert(Alert): 
    290291        self.add_button(gtk.RESPONSE_OK, _('Ok'), icon)
    291292        icon.show()
    292293
     294class ErrorAlert(Alert):
     295    """
     296    This is a ready-made one button (Ok) alert.
     297
     298    An error alert is a nice shortcut from a standard Alert because it
     299    comes with the 'OK' button already built-in. When clicked, the
     300    'OK' button will emit a response with a response_id of gtk.RESPONSE_OK.
     301
     302    Examples
     303    --------
     304
     305    .. code-block:: python
     306      from sugar.graphics.alert import ErrorAlert
     307      ...
     308        #### Method: _alert_error, create a Error alert (with ok
     309                     button standard)
     310        # and add it to the UI.
     311        def _alert_error(self):
     312            alert = ErrorAlert()
     313            alert.props.title=_('Title of Alert Goes Here')
     314            alert.props.msg = _('Text message of alert goes here')
     315            alert.connect('response', self._alert_response_cb)
     316            self.add_alert(alert)
     317
     318
     319        #### Method: _alert_response_cb, called when an alert object throws a
     320                     response event.
     321        def _alert_response_cb(self, alert, response_id):
     322            #remove the alert from the screen, since either a response button
     323            #was clicked or there was a timeout
     324            self.remove_alert(alert)
     325
     326            #Do any work that is specific to the response_id.
     327            if response_id is gtk.RESPONSE_OK:
     328                print 'Ok Button was clicked. Do any work upon ok here ...'
     329
     330    """
     331
     332    def __init__(self, **kwargs):
     333        Alert.__init__(self, **kwargs)
     334
     335        icon = Icon(icon_name='dialog-ok')
     336        self.add_button(gtk.RESPONSE_OK, _('Ok'), icon)
     337        icon.show()
    293338
    294339class _TimeoutIcon(hippo.CanvasText, hippo.CanvasItem):
    295340    """An icon with a round border"""