0b6cd2dbe500203b8fc5569f267b2e85cfc09666
[platform/upstream/ibus.git] / ui / gtk2 / engineabout.py
1 # vim:set et sts=4 sw=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
6 # Copyright (c) 2007-2010 Red Hat, Inc.
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
21 # USA
22
23 import gtk
24 from gtk import gdk
25 import pango
26 import ibus
27
28 from i18n import _, N_
29
30 class EngineAbout(gtk.Dialog):
31     def __init__(self, enginedesc):
32         self.__engine_desc = enginedesc
33         super(EngineAbout, self).__init__(_("About"), None, gtk.DIALOG_MODAL, (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
34
35         self.__init_ui()
36
37     def __init_ui(self):
38         self.set_icon_name("gtk-about")
39         sw = gtk.ScrolledWindow()
40         sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
41         sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
42         self.__text_view = gtk.TextView()
43         self.__text_view.set_size_request(400, 400)
44         self.__text_view.set_editable(False)
45         sw.add(self.__text_view)
46         sw.show_all()
47         self.vbox.pack_start(sw)
48
49         self.__fill_text_view()
50
51     def __fill_text_view(self):
52         text_buffer = self.__text_view.get_buffer()
53         self.__create_tags(text_buffer)
54         
55         iter = text_buffer.get_iter_at_offset(0)
56         text_buffer.insert_with_tags_by_name(iter, "\n ",
57                                              "left_margin_16")
58         text_buffer.insert_pixbuf(iter, self.__load_icon(self.__engine_desc.icon))
59         text_buffer.insert_with_tags_by_name(iter, "\n%s\n" % self.__engine_desc.longname,
60                                              "heading", "left_margin_16")
61         text_buffer.insert_with_tags_by_name(iter, _("Language: %s\n") % ibus.get_language_name(self.__engine_desc.language),
62                                             "small", "bold", "left_margin_16")
63         text_buffer.insert_with_tags_by_name(iter, _("Keyboard layout: %s\n") % self.__engine_desc.layout,
64                                             "small", "bold", "left_margin_16")
65         text_buffer.insert_with_tags_by_name(iter, _("Author: %s\n") % self.__engine_desc.author,
66                                             "small", "bold", "left_margin_16")
67         text_buffer.insert_with_tags_by_name(iter, _("Description:\n"),
68                                             "small", "bold", "left_margin_16")
69         text_buffer.insert_with_tags_by_name(iter, self.__engine_desc.description,
70                                             "wrap_text", "left_margin_32")
71
72
73     def __create_tags(self, text_buffer):
74         text_buffer.create_tag("heading",
75                         weight=pango.WEIGHT_BOLD,
76                         size = 16 * pango.SCALE)
77         text_buffer.create_tag("bold",
78                         weight=pango.WEIGHT_BOLD)
79         text_buffer.create_tag("italic",
80                         style=pango.STYLE_ITALIC)
81         text_buffer.create_tag("small",
82                         scale=pango.SCALE_SMALL)
83         text_buffer.create_tag("gray_foreground",
84                         foreground="dark gray")
85         text_buffer.create_tag("wrap_text",
86                         wrap_mode=gtk.WRAP_WORD)
87         text_buffer.create_tag("left_margin_16",
88                         left_margin=16)
89         text_buffer.create_tag("left_margin_32",
90                         left_margin=32)
91
92     def __load_icon(self, icon):
93         try:
94             pixbuf = gdk.pixbuf_new_from_file_at_scale(icon, 48, 48, True)
95         except:
96             theme = gtk.icon_theme_get_default()
97             icon = theme.lookup_icon("ibus-engine", 48, 0)
98             if icon == None:
99                 icon = theme.lookup_icon("gtk-missing-image", 48, 0)
100             pixbuf = icon.load_icon()
101         return pixbuf