| 1 | # Copyright (C) 2013, One Laptop Per Child |
| 2 | # |
| 3 | # This library is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU Lesser General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This library is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # Lesser General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU Lesser General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | |
| 18 | from gi.repository import Gtk |
| 19 | from gi.repository import GLib |
| 20 | |
| 21 | from sugar3.graphics import style |
| 22 | |
| 23 | |
| 24 | class MessageBox(Gtk.EventBox): |
| 25 | """Widget to display informative messages. |
| 26 | |
| 27 | A title is required. And it can have an icon, and |
| 28 | buttons. |
| 29 | |
| 30 | """ |
| 31 | def __init__(self, title, icon=None, description=None): |
| 32 | Gtk.EventBox.__init__(self) |
| 33 | |
| 34 | self.icon = icon |
| 35 | |
| 36 | self.modify_bg(Gtk.StateType.NORMAL, |
| 37 | style.COLOR_WHITE.get_gdk_color()) |
| 38 | |
| 39 | alignment = Gtk.Alignment.new(0.5, 0.5, 0.1, 0.1) |
| 40 | self.add(alignment) |
| 41 | alignment.show() |
| 42 | |
| 43 | box = Gtk.VBox() |
| 44 | alignment.add(box) |
| 45 | box.show() |
| 46 | |
| 47 | if icon is not None: |
| 48 | box.pack_start(icon, expand=True, fill=False, padding=0) |
| 49 | icon.show() |
| 50 | |
| 51 | title_label = Gtk.Label() |
| 52 | title_color = style.COLOR_BUTTON_GREY.get_html() |
| 53 | title_label.set_markup('<span weight="bold" color="%s">%s</span>' % ( |
| 54 | title_color, GLib.markup_escape_text(title))) |
| 55 | box.pack_start(title_label, expand=True, fill=False, padding=0) |
| 56 | title_label.show() |
| 57 | |
| 58 | self.button_box = Gtk.HButtonBox() |
| 59 | self.button_box.set_layout(Gtk.ButtonBoxStyle.CENTER) |
| 60 | box.pack_start(self.button_box, False, True, 0) |
| 61 | self.button_box.show() |
| 62 | |
| 63 | def add_button(self, button): |
| 64 | self.button_box.pack_start(button, expand=True, fill=False, padding=0) |