From: Peng Huang Date: Sun, 7 Jun 2009 02:58:57 +0000 (+0800) Subject: Move engineabout dialog into a new python file. X-Git-Tag: 1.1.0.20090609~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d58c734d7d2f649786078f3158ee2999c5347a2;p=platform%2Fupstream%2Fibus.git Move engineabout dialog into a new python file. --- diff --git a/setup/Makefile.am b/setup/Makefile.am index 83f1ae8..122eaad 100644 --- a/setup/Makefile.am +++ b/setup/Makefile.am @@ -24,6 +24,7 @@ ibussetup_PYTHON = \ icon.py \ enginecombobox.py \ enginetreeview.py \ + engineabout.py \ keyboardshortcut.py \ $(NULL) diff --git a/setup/engineabout.py b/setup/engineabout.py new file mode 120000 index 0000000..433caa8 --- /dev/null +++ b/setup/engineabout.py @@ -0,0 +1 @@ +../ui/gtk/engineabout.py \ No newline at end of file diff --git a/setup/main.py b/setup/main.py index 15a95fd..a00644c 100644 --- a/setup/main.py +++ b/setup/main.py @@ -36,7 +36,7 @@ from gtk import gdk from gtk import glade from enginecombobox import EngineComboBox from enginetreeview import EngineTreeView -from icon import load_icon +from engineabout import EngineAbout _ = lambda a : gettext.dgettext("ibus", a) N_ = lambda a : a @@ -190,68 +190,11 @@ class Setup(object): button = self.__xml.get_widget("button_engine_about") button.connect("clicked", self.__button_engine_about_cb) - def __create_tags(self, text_buffer): - text_buffer.create_tag("heading", - weight=pango.WEIGHT_BOLD, - size = 16 * pango.SCALE) - text_buffer.create_tag("bold", - weight=pango.WEIGHT_BOLD) - text_buffer.create_tag("italic", - style=pango.STYLE_ITALIC) - text_buffer.create_tag("small", - scale=pango.SCALE_SMALL) - text_buffer.create_tag("gray_foreground", - foreground="dark gray") - text_buffer.create_tag("wrap_text", - wrap_mode=gtk.WRAP_WORD) - text_buffer.create_tag("left_margin_16", - left_margin=16) - text_buffer.create_tag("left_margin_32", - left_margin=32) - def __button_engine_about_cb(self, button): engine = self.__treeview.get_select_engine() - title = _("About") - dlg = gtk.Dialog(title, None, gtk.DIALOG_MODAL, (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) - dlg.set_icon_name("gtk-about") - - # init ui - vbox = dlg.get_content_area() - sw = gtk.ScrolledWindow() - sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - view = gtk.TextView() - view.set_size_request(400, 400) - view.set_editable(False) - sw.add(view) - sw.show_all() - vbox.pack_start(sw) - - text_buffer = view.get_buffer() - self.__create_tags(text_buffer) - - iter = text_buffer.get_iter_at_offset(0) - text_buffer.insert_with_tags_by_name(iter, "\n ", - "left_margin_16") - text_buffer.insert_pixbuf(iter, load_icon(engine.icon, gtk.ICON_SIZE_DIALOG)) - text_buffer.insert_with_tags_by_name(iter, "\n%s\n" % engine.longname, - "heading", "left_margin_16") - text_buffer.insert_with_tags_by_name(iter, _("Language: %s\n") % ibus.get_language_name(engine.language), - "small", "bold", "left_margin_16") - text_buffer.insert_with_tags_by_name(iter, _("Author: %s\n") % engine.author, - "small", "bold", "left_margin_16") - text_buffer.insert_with_tags_by_name(iter, _("License: %s\n") % engine.license, - "small", "bold", "left_margin_16") - text_buffer.insert_with_tags_by_name(iter, _("Description:\n"), - "small", "bold", "left_margin_16") - text_buffer.insert_with_tags_by_name(iter, engine.description, - "wrap_text", "left_margin_32") - - # text_buffer.insert_with_tags_by_name(iter, "\n\n\n Intiliggent Input Bus\n Peng Huang ", - # "small", "left_margin_16", "italic") - - dlg.run() - dlg.destroy() + about = EngineAbout(engine) + about.run() + about.destroy() def __treeview_changed_cb(self, treeview): engines = self.__treeview.get_engines() diff --git a/ui/gtk/Makefile.am b/ui/gtk/Makefile.am index edaf4ec..ee988c7 100644 --- a/ui/gtk/Makefile.am +++ b/ui/gtk/Makefile.am @@ -30,6 +30,7 @@ ui_gtk_PYTHON = \ panel.py \ propitem.py \ toolitem.py \ + engineabout.py \ $(NULL) ui_gtkdir = $(pkgdatadir)/ui/gtk diff --git a/ui/gtk/engineabout.py b/ui/gtk/engineabout.py new file mode 100644 index 0000000..72d05a1 --- /dev/null +++ b/ui/gtk/engineabout.py @@ -0,0 +1,101 @@ +# vim:set et sts=4 sw=4: +# +# ibus - The Input Bus +# +# Copyright (c) 2007-2008 Huang Peng +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + +import gtk +from gtk import gdk +import pango +import ibus + +from gettext import dgettext +_ = lambda a : dgettext("ibus", a) +N_ = lambda a : a + +class EngineAbout(gtk.Dialog): + def __init__(self, enginedesc): + self.__engine_desc = enginedesc + super(EngineAbout, self).__init__(_("About"), None, gtk.DIALOG_MODAL, (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) + + self.__init_ui() + + def __init_ui(self): + self.set_icon_name("gtk-about") + sw = gtk.ScrolledWindow() + sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) + sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + self.__text_view = gtk.TextView() + self.__text_view.set_size_request(400, 400) + self.__text_view.set_editable(False) + sw.add(self.__text_view) + sw.show_all() + self.vbox.pack_start(sw) + + self.__fill_text_view() + + def __fill_text_view(self): + text_buffer = self.__text_view.get_buffer() + self.__create_tags(text_buffer) + + iter = text_buffer.get_iter_at_offset(0) + text_buffer.insert_with_tags_by_name(iter, "\n ", + "left_margin_16") + text_buffer.insert_pixbuf(iter, self.__load_icon(self.__engine_desc.icon)) + text_buffer.insert_with_tags_by_name(iter, "\n%s\n" % self.__engine_desc.longname, + "heading", "left_margin_16") + text_buffer.insert_with_tags_by_name(iter, _("Language: %s\n") % ibus.get_language_name(self.__engine_desc.language), + "small", "bold", "left_margin_16") + text_buffer.insert_with_tags_by_name(iter, _("Author: %s\n") % self.__engine_desc.author, + "small", "bold", "left_margin_16") + text_buffer.insert_with_tags_by_name(iter, _("Description:\n"), + "small", "bold", "left_margin_16") + text_buffer.insert_with_tags_by_name(iter, self.__engine_desc.description, + "wrap_text", "left_margin_32") + + + def __create_tags(self, text_buffer): + text_buffer.create_tag("heading", + weight=pango.WEIGHT_BOLD, + size = 16 * pango.SCALE) + text_buffer.create_tag("bold", + weight=pango.WEIGHT_BOLD) + text_buffer.create_tag("italic", + style=pango.STYLE_ITALIC) + text_buffer.create_tag("small", + scale=pango.SCALE_SMALL) + text_buffer.create_tag("gray_foreground", + foreground="dark gray") + text_buffer.create_tag("wrap_text", + wrap_mode=gtk.WRAP_WORD) + text_buffer.create_tag("left_margin_16", + left_margin=16) + text_buffer.create_tag("left_margin_32", + left_margin=32) + + def __load_icon(self, icon): + pixbuf = gdk.pixbuf_new_from_file(icon) + w, h = pixbuf.get_width(), pixbuf.get_height() + rate = max(w, h) / float(48) + w = int(w / rate) + h = int(h / rate) + pixbuf = pixbuf.scale_simple(w, h, gdk.INTERP_BILINEAR) + return pixbuf + + +