Blame setup/engineabout.py

Packit 3ff832
# vim:set et sts=4 sw=4:
Packit 3ff832
#
Packit 3ff832
# ibus - The Input Bus
Packit 3ff832
#
Packit 3ff832
# Copyright (c) 2007-2015 Peng Huang <shawn.p.huang@gmail.com>
Packit 3ff832
# Copyright (c) 2007-2015 Red Hat, Inc.
Packit 3ff832
#
Packit 3ff832
# This library is free software; you can redistribute it and/or
Packit 3ff832
# modify it under the terms of the GNU Lesser General Public
Packit 3ff832
# License as published by the Free Software Foundation; either
Packit 3ff832
# version 2.1 of the License, or (at your option) any later version.
Packit 3ff832
#
Packit 3ff832
# This library is distributed in the hope that it will be useful,
Packit 3ff832
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff832
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 3ff832
# Lesser General Public License for more details.
Packit 3ff832
#
Packit 3ff832
# You should have received a copy of the GNU Lesser General Public
Packit 3ff832
# License along with this library; if not, write to the Free Software
Packit 3ff832
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit 3ff832
# USA
Packit 3ff832
Packit 3ff832
from gi.repository import IBus
Packit 3ff832
from gi.repository import Gdk
Packit 3ff832
from gi.repository import GdkPixbuf
Packit 3ff832
from gi.repository import Gtk
Packit 3ff832
from gi.repository import Pango
Packit 3ff832
Packit 3ff832
import i18n
Packit 3ff832
Packit 3ff832
from i18n import _, N_
Packit 3ff832
Packit 3ff832
class EngineAbout(Gtk.Dialog):
Packit 3ff832
    def __init__(self, engine, transient_for = None):
Packit 3ff832
        self.__engine_desc = engine
Packit 3ff832
        super(EngineAbout, self).__init__(
Packit 3ff832
                title = _("About"),
Packit 3ff832
                transient_for = transient_for)
Packit 3ff832
Packit 3ff832
        buttons = (_("_Close"), Gtk.ResponseType.CLOSE)
Packit 3ff832
        self.add_buttons(*buttons)
Packit 3ff832
        self.__init_ui()
Packit 3ff832
Packit 3ff832
    def __init_ui(self):
Packit 3ff832
        # set_icon_name() cannot fallback any stock ids to the real files.
Packit 3ff832
        self.set_icon_name('help-about')
Packit 3ff832
        sw = Gtk.ScrolledWindow()
Packit 3ff832
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
Packit 3ff832
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
Packit 3ff832
        sw.set_size_request(400, 400)
Packit 3ff832
        self.__text_view = Gtk.TextView()
Packit 3ff832
        self.__text_view.set_editable(False)
Packit 3ff832
        sw.add(self.__text_view)
Packit 3ff832
        sw.show_all()
Packit 3ff832
        self.vbox.pack_start(sw, True, True, 0)
Packit 3ff832
Packit 3ff832
        self.__fill_text_view()
Packit 3ff832
Packit 3ff832
    def __fill_text_view(self):
Packit 3ff832
        text_buffer = self.__text_view.get_buffer()
Packit 3ff832
        self.__create_tags(text_buffer)
Packit 3ff832
Packit 3ff832
        iter = text_buffer.get_iter_at_offset(0)
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter, "\n ",
Packit 3ff832
                                             "left_margin_16")
Packit 3ff832
        text_buffer.insert_pixbuf(iter,
Packit 3ff832
                self.__load_icon(self.__engine_desc.get_icon()))
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                "\n%s\n" % i18n.gettext_engine_longname(self.__engine_desc),
Packit 3ff832
                "heading", "left_margin_16")
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                _("Language: %s\n") % IBus.get_language_name(self.__engine_desc.get_language()),
Packit 3ff832
                "small", "bold", "left_margin_16")
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                _("Keyboard layout: %s\n") % self.__engine_desc.get_layout(),
Packit 3ff832
                "small", "bold", "left_margin_16")
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                _("Author: %s\n") % self.__engine_desc.get_author(),
Packit 3ff832
                "small", "bold", "left_margin_16")
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                _("Description:\n"), "small", "bold", "left_margin_16")
Packit 3ff832
        text_buffer.insert_with_tags_by_name(iter,
Packit 3ff832
                i18n.gettext_engine_description(self.__engine_desc),
Packit 3ff832
                "wrap_text", "left_margin_32")
Packit 3ff832
Packit 3ff832
Packit 3ff832
    def __create_tags(self, text_buffer):
Packit 3ff832
        text_buffer.create_tag("heading",
Packit 3ff832
                        weight=Pango.Weight.BOLD,
Packit 3ff832
                        size = 16 * Pango.SCALE)
Packit 3ff832
        text_buffer.create_tag("bold",
Packit 3ff832
                        weight=Pango.Weight.BOLD)
Packit 3ff832
        text_buffer.create_tag("italic",
Packit 3ff832
                        style=Pango.Style.ITALIC)
Packit 3ff832
        text_buffer.create_tag("small",
Packit 3ff832
                        scale=0.833333333333) # Pango.SCALE_SMALL ?
Packit 3ff832
        text_buffer.create_tag("gray_foreground",
Packit 3ff832
                        foreground="dark gray")
Packit 3ff832
        text_buffer.create_tag("wrap_text",
Packit 3ff832
                        wrap_mode=Gtk.WrapMode.WORD)
Packit 3ff832
        text_buffer.create_tag("left_margin_16",
Packit 3ff832
                        left_margin=16)
Packit 3ff832
        text_buffer.create_tag("left_margin_32",
Packit 3ff832
                        left_margin=32)
Packit 3ff832
Packit 3ff832
    def __load_icon(self, icon_name):
Packit 3ff832
        try:
Packit 3ff832
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(icon_name,
Packit 3ff832
                                                             48,
Packit 3ff832
                                                             48,
Packit 3ff832
                                                             True)
Packit 3ff832
        except:
Packit 3ff832
            theme = Gtk.IconTheme.get_default()
Packit 3ff832
            icon = theme.lookup_icon(icon_name, 48, 0)
Packit 3ff832
            if icon == None:
Packit 3ff832
                icon = theme.lookup_icon("ibus-engine", 48, 0)
Packit 3ff832
            if icon == None:
Packit 3ff832
                icon = theme.lookup_icon("image-missing", 48, 0)
Packit 3ff832
            pixbuf = icon.load_icon()
Packit 3ff832
        return pixbuf
Packit 3ff832
Packit 3ff832
if __name__ == "__main__":
Packit 3ff832
    desc = IBus.EngineDesc()
Packit 3ff832
    EngineAbout(desc).run()