[Sugar-devel] [PATCH] Add NotifyRedAlert inherited from NotifyAlert

Anish Mangal anishmangal2002 at gmail.com
Mon Jun 14 01:07:09 EDT 2010


Hi Michael,

> Is this alert really about being red or about notifying the user about
> errors
> in a more eyecatching fashion?

I guess the latter.

> The value of the color variable can be more concisely calculated like so:
>
>   color = "#%02x0000" % self.saturation

Thanks, made the change.

Cheers,
Anish



On Mon, Jun 14, 2010 at 6:11 AM, Michael Stone <michael at laptop.org> wrote:
> On Mon, Jun 14, 2010 at 02:51:23AM +0530, anishmangal2002 at gmail.com wrote:
>
> Hi Anish,
>
> Thanks for the patches. Here are one small question and one comment for
> you...
>
>> From: anishmangal2002 <anishmangal2002 at gmail.com>
>>
>> Adds the NotifyRedAlert class which is an alert inherited from
>> NotifyAlert. When the alert message is displayed, it glows the
>> alert bar Red before slowly fading out to black, thus resulting
>> in a more visible notification.
>>
>> Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
>> ---
>> src/sugar/graphics/alert.py |   46
>> +++++++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 46 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/sugar/graphics/alert.py b/src/sugar/graphics/alert.py
>> index 4441909..b4dfee1 100644
>> --- a/src/sugar/graphics/alert.py
>> +++ b/src/sugar/graphics/alert.py
>> @@ -432,3 +432,49 @@ class NotifyAlert(Alert):
>>            self._response(gtk.RESPONSE_OK)
>>            return False
>>        return True
>> +
>> +class NotifyRedAlert(NotifyAlert):
>
> Is this alert really about being red or about notifying the user about
> errors
> in a more eyecatching fashion?
>
>
>> +    """
>> +    Timeout alert with only an "OK" button and a glowing Red border- just
>> for notifications
>> +
>> +    Examples
>> +    --------
>> +
>> +    .. code-block:: python
>> +      from sugar.graphics.alert import NotifyRedAlert
>> +      ...
>> +        #### Method: _alert_notify, create a NotifyRed alert (with only
>> an 'OK'
>> +                     button)
>> +        # and add it to the UI.
>> +        def _alert_notify(self):
>> +            #Notice that for a NotifyRedAlert, you pass the number of
>> seconds in
>> +            #which to notify. By default, this is 5.
>> +            alert = NotifyRedAlert(10)
>> +            alert.props.title=_('Title of Alert Goes Here')
>> +            alert.props.msg = _('Text message of notify alert goes here')
>> +            alert.connect('response', self._alert_response_cb)
>> +            self.add_alert(alert)
>> +
>> +    """
>> +
>> +    def __init__(self, timeout=5, **kwargs):
>> +        NotifyAlert.__init__(self, timeout, **kwargs)
>> +        self.saturation = 255
>> +
>> +        gobject.timeout_add(20, self.__modify_color_timeout)
>> +
>> +    def __modify_color_timeout(self):
>> +        if self.saturation:
>> +            self.saturation -= 1
>> +
>> +            # Form the hex color representation
>> +            if self.saturation <= 15:
>> +                color = '#0%s0000' % hex(self.saturation)[2:]
>> +            else:
>> +                color = '#%s0000' % hex(self.saturation)[2:]
>
> The value of the color variable can be more concisely calculated like so:
>
>   color = "#%02x0000" % self.saturation
>
> Regards,
>
> Michael
>


More information about the Sugar-devel mailing list