Debian Codegraph @

setup/engineabout.py

raw
1 # vim:set et sts=4 sw=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2015 Peng Huang <[email protected]>
6 # Copyright (c) 2007-2015 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 from gi.repository import IBus
24 from gi.repository import Gdk
25 from gi.repository import GdkPixbuf
26 from gi.repository import Gtk
27 from gi.repository import Pango
28
29 import i18n
30
31 from i18n import _, N_
32
33 class EngineAbout(Gtk.Dialog):
34 def __init__(self, engine, transient_for = None):
35 self.__engine_desc = engine
36 super(EngineAbout, self).__init__(
37 title = _("About"),
38 transient_for = transient_for)
39
40 buttons = (_("_Close"), Gtk.ResponseType.CLOSE)
41 self.add_buttons(*buttons)
42 self.__init_ui()
43
44 def __init_ui(self):
45 # set_icon_name() cannot fallback any stock ids to the real files.
46 self.set_icon_name('help-about')
47 sw = Gtk.ScrolledWindow()
48 sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
49 sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
50 sw.set_size_request(400, 400)
51 self.__text_view = Gtk.TextView()
52 self.__text_view.set_editable(False)
53 sw.add(self.__text_view)
54 sw.show_all()
55 self.vbox.pack_start(sw, True, True, 0)
56
57 self.__fill_text_view()
58
59 def __fill_text_view(self):
60 text_buffer = self.__text_view.get_buffer()
61 self.__create_tags(text_buffer)
62
63 iter = text_buffer.get_iter_at_offset(0)
64 text_buffer.insert_with_tags_by_name(iter, "\n ",
65 "left_margin_16")
66 text_buffer.insert_pixbuf(iter,
67 self.__load_icon(self.__engine_desc.get_icon()))
68 text_buffer.insert_with_tags_by_name(iter,
69 "\n%s\n" % i18n.gettext_engine_longname(self.__engine_desc),
70 "heading", "left_margin_16")
71 text_buffer.insert_with_tags_by_name(iter,
72 _("Language: %s\n") % IBus.get_language_name(self.__engine_desc.get_language()),
73 "small", "bold", "left_margin_16")
74 text_buffer.insert_with_tags_by_name(iter,
75 _("Keyboard layout: %s\n") % self.__engine_desc.get_layout(),
76 "small", "bold", "left_margin_16")
77 text_buffer.insert_with_tags_by_name(iter,
78 _("Author: %s\n") % self.__engine_desc.get_author(),
79 "small", "bold", "left_margin_16")
80 text_buffer.insert_with_tags_by_name(iter,
81 _("Description:\n"), "small", "bold", "left_margin_16")
82 text_buffer.insert_with_tags_by_name(iter,
83 i18n.gettext_engine_description(self.__engine_desc),
84 "wrap_text", "left_margin_32")
85
86
87 def __create_tags(self, text_buffer):
88 text_buffer.create_tag("heading",
89 weight=Pango.Weight.BOLD,
90 size = 16 * Pango.SCALE)
91 text_buffer.create_tag("bold",
92 weight=Pango.Weight.BOLD)
93 text_buffer.create_tag("italic",
94 style=Pango.Style.ITALIC)
95 text_buffer.create_tag("small",
96 scale=0.833333333333) # Pango.SCALE_SMALL ?
97 text_buffer.create_tag("gray_foreground",
98 foreground="dark gray")
99 text_buffer.create_tag("wrap_text",
100 wrap_mode=Gtk.WrapMode.WORD)
101 text_buffer.create_tag("left_margin_16",
102 left_margin=16)
103 text_buffer.create_tag("left_margin_32",
104 left_margin=32)
105
106 def __load_icon(self, icon_name):
107 try:
108 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(icon_name,
109 48,
110 48,
111 True)
112 except:
113 theme = Gtk.IconTheme.get_default()
114 icon = theme.lookup_icon(icon_name, 48, 0)
115 if icon == None:
116 icon = theme.lookup_icon("ibus-engine", 48, 0)
117 if icon == None:
118 icon = theme.lookup_icon("image-missing", 48, 0)
119 pixbuf = icon.load_icon()
120 return pixbuf
121
122 if __name__ == "__main__":
123 desc = IBus.EngineDesc()
124 EngineAbout(desc).run()