Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/sweetener/alerts.py
blob: 9609a829b2f8332853cb5499bcea93c44728422b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

from gettext import gettext as _
import gtk
from sugar.graphics import style
from sugar.graphics.alert import Alert as SugarAlert
from sugar.graphics.alert import NotifyAlert as SugarNotify

from icon import Icon


class Alert(SugarAlert):
    def __init__(self, parent, title, content, mtype):
        SugarAlert.__init__(self)
        self._parent = parent
        if mtype == gtk.MESSAGE_INFO:
            icon = Icon(icon_name='emblem-notification')
            icon.show()
            self.props.icon = icon
            icon.props.pixel_size = style.SMALL_ICON_SIZE * 2
        self.props.title = title
        self.props.msg = content
        ok_icon = Icon(icon_name='dialog-ok')
        self.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon)
        ok_icon.show()
        self.connect('response', self.remove_myself)

    def remove_myself(self, widget=None, response=None):
        self._parent.remove_alert(self)


class NotifyAlert(SugarNotify):
    def __init__(self, parent, title, content, icon, timeout):
        SugarNotify.__init__(self, timeout)
        self._parent = parent
        self.props.title = title
        self.props.msg = content
        if icon is not None:
            icon = Icon(icon_name=icon)
            icon.show()
            self.props.icon = icon
            icon.props.pixel_size = style.SMALL_ICON_SIZE * 2
        self.connect('response', self.remove_myself)

    def remove_myself(self, widget=None, response=None):
        self._parent.remove_alert(self)