From ffd69683443c56910e6db6d4526992a92c222275 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Tue, 18 Feb 2014 17:36:45 +0900 Subject: [PATCH] Fixed deprecated GtkHBox, GtkVBox and GtkStock since GTK+ 3.10. --- po/ibus-anthy.pot | 154 +++++++++++++++++++++----------- setup/python2/main.py | 14 +-- setup/python2/setup.ui | 237 +++++++++++++++++++++++++------------------------ setup/python3/main.py | 10 +-- setup/python3/setup.ui | 237 +++++++++++++++++++++++++------------------------ 5 files changed, 361 insertions(+), 291 deletions(-) diff --git a/setup/python2/main.py b/setup/python2/main.py index 98486ad..7c403b8 100644 --- a/setup/python2/main.py +++ b/setup/python2/main.py @@ -4,8 +4,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -1416,14 +1416,14 @@ class AnthySetup(object): dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"), parent=self.__builder.get_object('main'), action=Gtk.FileChooserAction.OPEN, - buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_Open"), Gtk.ResponseType.OK)) if Gtk.Buildable.get_name(widget) == 'dict:btn_edit': dlg = Gtk.Dialog(title=_("Edit Dictionary File"), parent=self.__builder.get_object('main'), flags=Gtk.DialogFlags.MODAL, - buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OK, Gtk.ResponseType.OK)) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_OK"), Gtk.ResponseType.OK)) vbox = self.__builder.get_object('dict:add_extra_vbox') if Gtk.Buildable.get_name(widget) == 'dict:btn_add': @@ -1518,7 +1518,7 @@ class AnthySetup(object): dlg = Gtk.Dialog(title=_("View Dictionary File"), parent=self.__builder.get_object('main'), flags=Gtk.DialogFlags.MODAL, - buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK)) + buttons=(_("_OK"), Gtk.ResponseType.OK)) buffer = Gtk.TextBuffer() buffer.set_text (lines) text_view = Gtk.TextView.new_with_buffer(buffer) diff --git a/setup/python2/setup.ui b/setup/python2/setup.ui index d9ec626..dc5e7e1 100644 --- a/setup/python2/setup.ui +++ b/setup/python2/setup.ui @@ -195,16 +195,18 @@ dialog - + True + vertical True True 6 - + True + vertical 8 @@ -355,8 +357,9 @@ 8 12 - + True + vertical 4 4 @@ -409,8 +412,9 @@ - + True + vertical 8 @@ -637,8 +641,9 @@ 8 4 - + True + horizontal 8 @@ -773,13 +778,15 @@ - + True + vertical 4 4 - + True + horizontal 8 @@ -828,6 +835,7 @@ automatic automatic in + 300 True @@ -843,53 +851,20 @@ - + True + horizontal 4 end + De_fault + True True True True False - - - True - 0 - 0 - - - True - 2 - - - True - gtk-undo - - - False - False - 0 - - - - - True - De_fault - True - - - False - False - 1 - - - - - - False @@ -899,12 +874,12 @@ - gtk-edit + _Edit + True True True True False - True @@ -1352,8 +1327,9 @@ - + True + horizontal 8 @@ -1393,13 +1369,14 @@ - + True + horizontal 8 True - gtk-dialog-info + dialog-information False @@ -1429,8 +1406,9 @@ - + True + horizontal 8 @@ -1471,13 +1449,14 @@ - + True + horizontal 8 True - gtk-dialog-info + dialog-information False @@ -1605,8 +1584,9 @@ - + True + vertical 8 4 @@ -1620,8 +1600,9 @@ 4 0 - + True + vertical 4 4 @@ -1777,8 +1758,9 @@ 4 0 - + True + vertical 4 4 @@ -1801,8 +1783,9 @@ - + True + horizontal 4 end @@ -1823,12 +1806,12 @@ - gtk-add + _Add + True True True True False - True @@ -1839,12 +1822,12 @@ - gtk-edit + _Edit + True True True True False - True @@ -1855,12 +1838,12 @@ - gtk-delete + _Delete + True True True True False - True @@ -1877,19 +1860,20 @@ - + True + horizontal 4 end - gtk-go-up + _Up + True You can change the order on language bar True True True False - True @@ -1900,13 +1884,13 @@ - gtk-go-down + _Down + True You can change the order on language bar True True True False - True @@ -1953,7 +1937,7 @@ - + True vertical 10 @@ -1979,18 +1963,19 @@ - + True + horizontal end - gtk-apply + _Apply + True True False True True False - True @@ -2001,12 +1986,12 @@ - gtk-cancel + _Cancel + True True True True False - True @@ -2017,12 +2002,12 @@ - gtk-ok + _OK + True True True True False - True @@ -2053,11 +2038,13 @@ True dialog - + True + vertical - + True + vertical 5 6 @@ -2068,6 +2055,7 @@ automatic automatic in + 150 True @@ -2081,8 +2069,9 @@ - + True + horizontal 8 @@ -2128,8 +2117,9 @@ - + True + horizontal 8 @@ -2143,8 +2133,9 @@ - + True + horizontal A_lternate @@ -2197,19 +2188,20 @@ - + True + horizontal 6 end - gtk-add + _Add + True True False True True False - True @@ -2220,12 +2212,12 @@ - gtk-refresh + _Refresh + True False True True False - True @@ -2236,13 +2228,13 @@ - gtk-delete + _Delete + True True False True True False - True @@ -2264,17 +2256,18 @@ - + True + horizontal end - gtk-cancel + _Cancel + True True True True False - True False @@ -2284,12 +2277,12 @@ - gtk-ok + _OK + True True True True False - True False @@ -2318,13 +2311,15 @@ True dialog - + True + vertical 5 6 - + True + horizontal 5 6 @@ -2359,8 +2354,9 @@ - + True + horizontal 5 6 @@ -2371,6 +2367,8 @@ automatic automatic in + 250 + 300 True @@ -2383,8 +2381,9 @@ - + True + vertical start 6 @@ -2470,12 +2469,12 @@ True - gtk-add + _Add + True True True True False - True 8 @@ -2484,12 +2483,12 @@ True - gtk-remove + _Remove + True True True True False - True 9 @@ -2508,16 +2507,17 @@ - + True + horizontal end True - gtk-close + _Close + True True True - True True @@ -2551,12 +2551,14 @@ Confirmation You are about to close the setup dialog, is that OK? - + True + vertical 2 - + True + horizontal end @@ -2586,12 +2588,14 @@ Notice! You are about to close the setup dialog without saving your changes, is that OK? - + True + vertical 2 - + True + horizontal end @@ -2622,12 +2626,14 @@ - + True + vertical 2 - + True + horizontal end @@ -2657,12 +2663,14 @@ Invalid keysym This keysym is not valid - + True + vertical 2 - + True + horizontal end @@ -2680,8 +2688,9 @@ - + True + vertical True 10 @@ -2800,8 +2809,8 @@ IBus-Anthy Copyright © 2007–2008 Peng Huang Copyright © 2009 Hideaki ABE -Copyright © 2009–2013 Takao Fujiwara -Copyright © 2007–2013 Red Hat, Inc. +Copyright © 2009–2014 Takao Fujiwara +Copyright © 2007–2014 Red Hat, Inc. The Anthy engine for the IBus input platform GPL http://code.google.com/p/ibus/ diff --git a/setup/python3/main.py b/setup/python3/main.py index fec03a6..2073f59 100644 --- a/setup/python3/main.py +++ b/setup/python3/main.py @@ -1410,14 +1410,14 @@ class AnthySetup(object): dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"), parent=self.__builder.get_object('main'), action=Gtk.FileChooserAction.OPEN, - buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_Open"), Gtk.ResponseType.OK)) if Gtk.Buildable.get_name(widget) == 'dict:btn_edit': dlg = Gtk.Dialog(title=_("Edit Dictionary File"), parent=self.__builder.get_object('main'), flags=Gtk.DialogFlags.MODAL, - buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OK, Gtk.ResponseType.OK)) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_OK"), Gtk.ResponseType.OK)) vbox = self.__builder.get_object('dict:add_extra_vbox') if Gtk.Buildable.get_name(widget) == 'dict:btn_add': @@ -1512,7 +1512,7 @@ class AnthySetup(object): dlg = Gtk.Dialog(title=_("View Dictionary File"), parent=self.__builder.get_object('main'), flags=Gtk.DialogFlags.MODAL, - buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK)) + buttons=(_("_OK"), Gtk.ResponseType.OK)) buffer = Gtk.TextBuffer() buffer.set_text (lines) text_view = Gtk.TextView.new_with_buffer(buffer) diff --git a/setup/python3/setup.ui b/setup/python3/setup.ui index d9ec626..dc5e7e1 100644 --- a/setup/python3/setup.ui +++ b/setup/python3/setup.ui @@ -195,16 +195,18 @@ dialog - + True + vertical True True 6 - + True + vertical 8 @@ -355,8 +357,9 @@ 8 12 - + True + vertical 4 4 @@ -409,8 +412,9 @@ - + True + vertical 8 @@ -637,8 +641,9 @@ 8 4 - + True + horizontal 8 @@ -773,13 +778,15 @@ - + True + vertical 4 4 - + True + horizontal 8 @@ -828,6 +835,7 @@ automatic automatic in + 300 True @@ -843,53 +851,20 @@ - + True + horizontal 4 end + De_fault + True True True True False - - - True - 0 - 0 - - - True - 2 - - - True - gtk-undo - - - False - False - 0 - - - - - True - De_fault - True - - - False - False - 1 - - - - - - False @@ -899,12 +874,12 @@ - gtk-edit + _Edit + True True True True False - True @@ -1352,8 +1327,9 @@ - + True + horizontal 8 @@ -1393,13 +1369,14 @@ - + True + horizontal 8 True - gtk-dialog-info + dialog-information False @@ -1429,8 +1406,9 @@ - + True + horizontal 8 @@ -1471,13 +1449,14 @@ - + True + horizontal 8 True - gtk-dialog-info + dialog-information False @@ -1605,8 +1584,9 @@ - + True + vertical 8 4 @@ -1620,8 +1600,9 @@ 4 0 - + True + vertical 4 4 @@ -1777,8 +1758,9 @@ 4 0 - + True + vertical 4 4 @@ -1801,8 +1783,9 @@ - + True + horizontal 4 end @@ -1823,12 +1806,12 @@ - gtk-add + _Add + True True True True False - True @@ -1839,12 +1822,12 @@ - gtk-edit + _Edit + True True True True False - True @@ -1855,12 +1838,12 @@ - gtk-delete + _Delete + True True True True False - True @@ -1877,19 +1860,20 @@ - + True + horizontal 4 end - gtk-go-up + _Up + True You can change the order on language bar True True True False - True @@ -1900,13 +1884,13 @@ - gtk-go-down + _Down + True You can change the order on language bar True True True False - True @@ -1953,7 +1937,7 @@ - + True vertical 10 @@ -1979,18 +1963,19 @@ - + True + horizontal end - gtk-apply + _Apply + True True False True True False - True @@ -2001,12 +1986,12 @@ - gtk-cancel + _Cancel + True True True True False - True @@ -2017,12 +2002,12 @@ - gtk-ok + _OK + True True True True False - True @@ -2053,11 +2038,13 @@ True dialog - + True + vertical - + True + vertical 5 6 @@ -2068,6 +2055,7 @@ automatic automatic in + 150 True @@ -2081,8 +2069,9 @@ - + True + horizontal 8 @@ -2128,8 +2117,9 @@ - + True + horizontal 8 @@ -2143,8 +2133,9 @@ - + True + horizontal A_lternate @@ -2197,19 +2188,20 @@ - + True + horizontal 6 end - gtk-add + _Add + True True False True True False - True @@ -2220,12 +2212,12 @@ - gtk-refresh + _Refresh + True False True True False - True @@ -2236,13 +2228,13 @@ - gtk-delete + _Delete + True True False True True False - True @@ -2264,17 +2256,18 @@ - + True + horizontal end - gtk-cancel + _Cancel + True True True True False - True False @@ -2284,12 +2277,12 @@ - gtk-ok + _OK + True True True True False - True False @@ -2318,13 +2311,15 @@ True dialog - + True + vertical 5 6 - + True + horizontal 5 6 @@ -2359,8 +2354,9 @@ - + True + horizontal 5 6 @@ -2371,6 +2367,8 @@ automatic automatic in + 250 + 300 True @@ -2383,8 +2381,9 @@ - + True + vertical start 6 @@ -2470,12 +2469,12 @@ True - gtk-add + _Add + True True True True False - True 8 @@ -2484,12 +2483,12 @@ True - gtk-remove + _Remove + True True True True False - True 9 @@ -2508,16 +2507,17 @@ - + True + horizontal end True - gtk-close + _Close + True True True - True True @@ -2551,12 +2551,14 @@ Confirmation You are about to close the setup dialog, is that OK? - + True + vertical 2 - + True + horizontal end @@ -2586,12 +2588,14 @@ Notice! You are about to close the setup dialog without saving your changes, is that OK? - + True + vertical 2 - + True + horizontal end @@ -2622,12 +2626,14 @@ - + True + vertical 2 - + True + horizontal end @@ -2657,12 +2663,14 @@ Invalid keysym This keysym is not valid - + True + vertical 2 - + True + horizontal end @@ -2680,8 +2688,9 @@ - + True + vertical True 10 @@ -2800,8 +2809,8 @@ IBus-Anthy Copyright © 2007–2008 Peng Huang Copyright © 2009 Hideaki ABE -Copyright © 2009–2013 Takao Fujiwara -Copyright © 2007–2013 Red Hat, Inc. +Copyright © 2009–2014 Takao Fujiwara +Copyright © 2007–2014 Red Hat, Inc. The Anthy engine for the IBus input platform GPL http://code.google.com/p/ibus/ -- 1.8.0 From 4d605b873bf4b0af2a337cd076175c8d0a703346 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Thu, 27 Feb 2014 18:32:01 +0900 Subject: [PATCH] Added another status icon for input mode. --- engine/python2/Makefile.am | 5 +- engine/python2/engine.py | 94 ++++++++- engine/python2/propertyicon.py | 81 ++++++++ engine/python3/Makefile.am | 5 +- engine/python3/engine.py | 92 ++++++++- engine/python3/propertyicon.py | 81 ++++++++ po/ibus-anthy.pot | 426 +++++++++++++++++++++-------------------- setup/python2/anthyprefs.py.in | 6 +- setup/python2/main.py | 6 +- setup/python2/prefs.py | 32 +++- setup/python2/setup.ui | 19 +- setup/python3/anthyprefs.py.in | 2 + setup/python3/main.py | 6 +- setup/python3/prefs.py | 28 ++- setup/python3/setup.ui | 19 +- 15 files changed, 658 insertions(+), 244 deletions(-) create mode 100644 engine/python2/propertyicon.py create mode 100644 engine/python3/propertyicon.py diff --git a/engine/python2/Makefile.am b/engine/python2/Makefile.am index a96f831..965d534 100644 --- a/engine/python2/Makefile.am +++ b/engine/python2/Makefile.am @@ -3,8 +3,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ engine_anthy_PYTHON = \ jastring.py \ kana.py \ main.py \ + propertyicon.py \ romaji.py \ segment.py \ tables.py \ diff --git a/engine/python2/engine.py b/engine/python2/engine.py index 90a5750..c7a6fb3 100644 --- a/engine/python2/engine.py +++ b/engine/python2/engine.py @@ -4,8 +4,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ try: except: pass +from gi.repository import Gio from gi.repository import GLib from gi.repository import IBus @@ -117,6 +118,7 @@ class Engine(IBus.EngineSimple): __keybind = {} __thumb = None __latin_with_shift = True + __input_mode_icon = None def __init__(self, bus, object_path): super(Engine, self).__init__(engine_name="anthy", @@ -170,6 +172,8 @@ class Engine(IBus.EngineSimple): ibus_config.connect('value-changed', self.__config_value_changed_cb) + self.__run_input_mode_icon() + def __get_ibus_version(self): if self.__ibus_version == 0.0: self.__ibus_version = \ @@ -258,6 +262,73 @@ class Engine(IBus.EngineSimple): signal.signal(signum, signal.SIG_DFL) os.kill(os.getpid(), signum) + def __is_gnome_shell_running(self): + connection = None + variant = None + + try: + connection = Gio.bus_get_sync(Gio.BusType.SESSION, None) + variant = connection.call_sync('org.gnome.Shell', + '/org/gnome/Shell', + 'org.freedesktop.DBus.Peer', + 'Ping', + None, + None, + Gio.DBusCallFlags.NONE, + -1, + None) + except GLib.GError as e: + pass + + if connection != None: + try: + connection.flush_sync(None) + except GLib.GError as e: + printerr('GDBusConnection flush failed: ' + str(e)) + + if variant == None: + return False + return True + + def __run_input_mode_icon(self): + self.__input_mode_icon = None + + if self.__is_gnome_shell_running(): + return + try: + from gi.repository import Gdk + if Gdk.Display.get_default() == None: + return + except Exception as e: + printerr('import Gdk failed: ' + str(e)) + return + + if not self.__prefs.get_value('common', 'show-input-mode-icon'): + return + + rgba = Gdk.RGBA(red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0) + spec = self.__prefs.get_value('common', 'icon-str-rgba') + if not rgba.parse(spec): + printerr('invalid icon-str-rgba: %s' % spec) + rgba = Gdk.RGBA(red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0) + + modes = { + INPUT_MODE_HIRAGANA : 'あ', + INPUT_MODE_KATAKANA : 'ア', + INPUT_MODE_HALF_WIDTH_KATAKANA : '_ア', + INPUT_MODE_LATIN : '_A', + INPUT_MODE_WIDE_LATIN : 'A', + } + + try: + import propertyicon + self.__input_mode_icon = propertyicon.PropertyIcon(rgba) + self.__input_mode_icon.set_visible(True) + self.__input_mode_icon.set_from_symbol(modes[self.__input_mode]) + except Exception as e: + printerr('import PropertyIcon failed: ' + str(e)) + return + def __set_input_mode_props(self, anthy_props): # The class method is kept even if the engine is switched. if Engine.__input_mode == None: @@ -847,6 +918,9 @@ class Engine(IBus.EngineSimple): prop.set_label(IBus.Text.new_from_string(label)) self.update_property(prop) + if self.__input_mode_icon != None: + self.__input_mode_icon.set_from_symbol(symbol) + self.__reset() self.__invalidate() @@ -1030,6 +1104,7 @@ class Engine(IBus.EngineSimple): # It seems do_destroy() is called when launch_engine() is called. #self.__remove_dict_files() # It seems super.destroy() does not unref the engine. + self.__input_mode_icon = None def __join_all_segments(self): while True: @@ -1109,7 +1184,7 @@ class Engine(IBus.EngineSimple): # fill lookup_table self.__lookup_table.clear() - for i in xrange(0, seg_stat.nr_predictions): + for i in xrange(0, nr_predictions): buf = self.__context.get_prediction(i) candidate = UN(buf) self.__lookup_table.append_candidate(IBus.Text.new_from_string(candidate)) @@ -1220,6 +1295,12 @@ class Engine(IBus.EngineSimple): def __update_anthy_convert_chars(self): self.__convert_chars = u'' pos = 0 + + (seg_index, text) = self.__segments[self.__cursor_pos] + # prediction lookup window + BackSpace will return None + if text == None: + return + for i, (seg_index, text) in enumerate(self.__segments): self.__convert_chars += text if i < self.__cursor_pos: @@ -2110,6 +2191,13 @@ class Engine(IBus.EngineSimple): self.__fetch_dict_values(base_sec) self.__prefs.set_value(base_sec, name, value) self.__set_dict_mode_props(self.__prop_list, True) + elif base_sec == 'common': + if name == 'show_input_mode_icon': + name = 'show-input-mode-icon' + self.__prefs.set_value(base_sec, name, value) + self.__run_input_mode_icon() + else: + self.__prefs.set_value(base_sec, name, value) elif base_sec: self.__prefs.set_value(base_sec, name, value) else: diff --git a/engine/python2/propertyicon.py b/engine/python2/propertyicon.py new file mode 100644 index 0000000..fa5f34f --- /dev/null +++ b/engine/python2/propertyicon.py @@ -0,0 +1,81 @@ +# vim:set et sts=4 sw=4: +# -*- coding: utf-8 -*- +# +# ibus-anthy - The Anthy engine for IBus +# +# Copyright (c) 2014 Takao Fujiwara +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# for python2 +from __future__ import print_function + +import cairo +import sys + +from gi.repository import Gdk +from gi.repository import Gio +from gi.repository import GLib +from gi.repository import Gtk +from gi.repository import Pango +from gi.repository import PangoCairo + +class PropertyIcon(Gtk.StatusIcon): + __xkb_icon_pixbufs = {} + __xkb_icon_rgba = None + + def __init__(self, rgba): + super(Gtk.StatusIcon, self).__init__() + self.__xkb_icon_rgba = rgba + + def __context_render_string(self, cr, symbol, image_width, image_height): + lwidth = 0 + lheight = 0 + desc = Pango.FontDescription.from_string('Monospace Bold 22') + layout = PangoCairo.create_layout(cr) + + layout.set_font_description(desc) + layout.set_text(symbol, -1) + (lwidth, lheight) = layout.get_size() + cr.move_to((image_width - lwidth / Pango.SCALE) / 2, + (image_height - lheight / Pango.SCALE) / 2) + cr.set_source_rgba(self.__xkb_icon_rgba.red, + self.__xkb_icon_rgba.green, + self.__xkb_icon_rgba.blue, + self.__xkb_icon_rgba.alpha) + PangoCairo.show_layout(cr, layout) + + def __create_icon_pixbuf_with_string(self, symbol): + if symbol in self.__xkb_icon_pixbufs: + return self.__xkb_icon_pixbufs[symbol] + + image = cairo.ImageSurface(cairo.FORMAT_ARGB32, 48, 48) + cr = cairo.Context(image) + width = image.get_width() + height = image.get_height() + + cr.set_source_rgba(0.0, 0.0, 0.0, 0.0) + cr.set_operator(cairo.OPERATOR_SOURCE) + cr.paint() + cr.set_operator(cairo.OPERATOR_OVER) + self.__context_render_string(cr, symbol, width, height) + pixbuf = Gdk.pixbuf_get_from_surface(image, 0, 0, width, height) + self.__xkb_icon_pixbufs[symbol] = pixbuf + return pixbuf + + def set_from_symbol(self, symbol): + pixbuf = self.__create_icon_pixbuf_with_string(symbol) + self.set_from_pixbuf(pixbuf) diff --git a/engine/python3/Makefile.am b/engine/python3/Makefile.am index a96f831..965d534 100644 --- a/engine/python3/Makefile.am +++ b/engine/python3/Makefile.am @@ -3,8 +3,8 @@ # ibus-anthy - The Anthy engine for IBus # # Copyright (c) 2007-2008 Peng Huang -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ engine_anthy_PYTHON = \ jastring.py \ kana.py \ main.py \ + propertyicon.py \ romaji.py \ segment.py \ tables.py \ diff --git a/engine/python3/engine.py b/engine/python3/engine.py index 7eadf23..6563087 100644 --- a/engine/python3/engine.py +++ b/engine/python3/engine.py @@ -36,6 +36,7 @@ try: except: pass +from gi.repository import Gio from gi.repository import GLib from gi.repository import IBus @@ -118,6 +119,7 @@ class Engine(IBus.EngineSimple): __keybind = {} __thumb = None __latin_with_shift = True + __input_mode_icon = None def __init__(self, bus, object_path): super(Engine, self).__init__(engine_name="anthy", @@ -171,6 +173,8 @@ class Engine(IBus.EngineSimple): ibus_config.connect('value-changed', self.__config_value_changed_cb) + self.__run_input_mode_icon() + def __get_ibus_version(self): if self.__ibus_version == 0.0: self.__ibus_version = \ @@ -259,6 +263,73 @@ class Engine(IBus.EngineSimple): signal.signal(signum, signal.SIG_DFL) os.kill(os.getpid(), signum) + def __is_gnome_shell_running(self): + connection = None + variant = None + + try: + connection = Gio.bus_get_sync(Gio.BusType.SESSION, None) + variant = connection.call_sync('org.gnome.Shell', + '/org/gnome/Shell', + 'org.freedesktop.DBus.Peer', + 'Ping', + None, + None, + Gio.DBusCallFlags.NONE, + -1, + None) + except GLib.GError as e: + pass + + if connection != None: + try: + connection.flush_sync(None) + except GLib.GError as e: + printerr('GDBusConnection flush failed: ' + str(e)) + + if variant == None: + return False + return True + + def __run_input_mode_icon(self): + self.__input_mode_icon = None + + if self.__is_gnome_shell_running(): + return + try: + from gi.repository import Gdk + if Gdk.Display.get_default() == None: + return + except Exception as e: + printerr('import Gdk failed: ' + str(e)) + return + + if not self.__prefs.get_value('common', 'show-input-mode-icon'): + return + + rgba = Gdk.RGBA(red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0) + spec = self.__prefs.get_value('common', 'icon-str-rgba') + if not rgba.parse(spec): + printerr('invalid icon-str-rgba: %s' % spec) + rgba = Gdk.RGBA(red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0) + + modes = { + INPUT_MODE_HIRAGANA : 'あ', + INPUT_MODE_KATAKANA : 'ア', + INPUT_MODE_HALF_WIDTH_KATAKANA : '_ア', + INPUT_MODE_LATIN : '_A', + INPUT_MODE_WIDE_LATIN : 'A', + } + + try: + import propertyicon + self.__input_mode_icon = propertyicon.PropertyIcon(rgba) + self.__input_mode_icon.set_visible(True) + self.__input_mode_icon.set_from_symbol(modes[self.__input_mode]) + except Exception as e: + printerr('import PropertyIcon failed: ' + str(e)) + return + def __set_input_mode_props(self, anthy_props): # The class method is kept even if the engine is switched. if Engine.__input_mode == None: @@ -842,6 +913,9 @@ class Engine(IBus.EngineSimple): prop.set_label(IBus.Text.new_from_string(label)) self.update_property(prop) + if self.__input_mode_icon != None: + self.__input_mode_icon.set_from_symbol(symbol) + self.__reset() self.__invalidate() @@ -1025,6 +1099,7 @@ class Engine(IBus.EngineSimple): # It seems do_destroy() is called when launch_engine() is called. #self.__remove_dict_files() # It seems super.destroy() does not unref the engine. + self.__input_mode_icon = None def __join_all_segments(self): while True: @@ -1104,7 +1179,7 @@ class Engine(IBus.EngineSimple): # fill lookup_table self.__lookup_table.clear() - for i in range(0, seg_stat.nr_predictions): + for i in range(0, nr_predictions): buf = self.__context.get_prediction(i) candidate = buf self.__lookup_table.append_candidate(IBus.Text.new_from_string(candidate)) @@ -1215,6 +1290,12 @@ class Engine(IBus.EngineSimple): def __update_anthy_convert_chars(self): self.__convert_chars = '' pos = 0 + + (seg_index, text) = self.__segments[self.__cursor_pos] + # prediction lookup window + BackSpace will return None + if text == None: + return + for i, (seg_index, text) in enumerate(self.__segments): self.__convert_chars += text if i < self.__cursor_pos: @@ -2104,6 +2185,13 @@ class Engine(IBus.EngineSimple): self.__fetch_dict_values(base_sec) self.__prefs.set_value(base_sec, name, value) self.__set_dict_mode_props(self.__prop_list, True) + elif base_sec == 'common': + if name == 'show_input_mode_icon': + name = 'show-input-mode-icon' + self.__prefs.set_value(base_sec, name, value) + self.__run_input_mode_icon() + else: + self.__prefs.set_value(base_sec, name, value) elif base_sec: self.__prefs.set_value(base_sec, name, value) else: @@ -2312,7 +2400,7 @@ class Engine(IBus.EngineSimple): nr_predictions = self.__context.get_nr_predictions() # for i in range(nr_predictions): -# print self.__context.get_prediction(i) +# print(self.__context.get_prediction(i)) buf = self.__context.get_prediction(0) if not buf: diff --git a/engine/python3/propertyicon.py b/engine/python3/propertyicon.py new file mode 100644 index 0000000..fa5f34f --- /dev/null +++ b/engine/python3/propertyicon.py @@ -0,0 +1,81 @@ +# vim:set et sts=4 sw=4: +# -*- coding: utf-8 -*- +# +# ibus-anthy - The Anthy engine for IBus +# +# Copyright (c) 2014 Takao Fujiwara +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# for python2 +from __future__ import print_function + +import cairo +import sys + +from gi.repository import Gdk +from gi.repository import Gio +from gi.repository import GLib +from gi.repository import Gtk +from gi.repository import Pango +from gi.repository import PangoCairo + +class PropertyIcon(Gtk.StatusIcon): + __xkb_icon_pixbufs = {} + __xkb_icon_rgba = None + + def __init__(self, rgba): + super(Gtk.StatusIcon, self).__init__() + self.__xkb_icon_rgba = rgba + + def __context_render_string(self, cr, symbol, image_width, image_height): + lwidth = 0 + lheight = 0 + desc = Pango.FontDescription.from_string('Monospace Bold 22') + layout = PangoCairo.create_layout(cr) + + layout.set_font_description(desc) + layout.set_text(symbol, -1) + (lwidth, lheight) = layout.get_size() + cr.move_to((image_width - lwidth / Pango.SCALE) / 2, + (image_height - lheight / Pango.SCALE) / 2) + cr.set_source_rgba(self.__xkb_icon_rgba.red, + self.__xkb_icon_rgba.green, + self.__xkb_icon_rgba.blue, + self.__xkb_icon_rgba.alpha) + PangoCairo.show_layout(cr, layout) + + def __create_icon_pixbuf_with_string(self, symbol): + if symbol in self.__xkb_icon_pixbufs: + return self.__xkb_icon_pixbufs[symbol] + + image = cairo.ImageSurface(cairo.FORMAT_ARGB32, 48, 48) + cr = cairo.Context(image) + width = image.get_width() + height = image.get_height() + + cr.set_source_rgba(0.0, 0.0, 0.0, 0.0) + cr.set_operator(cairo.OPERATOR_SOURCE) + cr.paint() + cr.set_operator(cairo.OPERATOR_OVER) + self.__context_render_string(cr, symbol, width, height) + pixbuf = Gdk.pixbuf_get_from_surface(image, 0, 0, width, height) + self.__xkb_icon_pixbufs[symbol] = pixbuf + return pixbuf + + def set_from_symbol(self, symbol): + pixbuf = self.__create_icon_pixbuf_with_string(symbol) + self.set_from_pixbuf(pixbuf) diff --git a/setup/python2/anthyprefs.py.in b/setup/python2/anthyprefs.py.in index a685da1..883fb23 100644 --- a/setup/python2/anthyprefs.py.in +++ b/setup/python2/anthyprefs.py.in @@ -5,8 +5,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -362,6 +362,8 @@ _config = { 'show-dict-mode': True, 'show-dict-config': False, 'show-preferences': True, + 'show-input-mode-icon': True, + 'icon-str-rgba': '#41507a', 'period_style': 0, 'symbol_style': 1, diff --git a/setup/python2/main.py b/setup/python2/main.py index 7c403b8..0e7c62e 100644 --- a/setup/python2/main.py +++ b/setup/python2/main.py @@ -144,7 +144,8 @@ class AnthySetup(object): 'half_width_symbol', 'half_width_number', 'half_width_space', 'latin_with_shift', 'thumb:keyboard_layout_mode', 'thumb:keyboard_layout', - 'thumb:fmv_extension', 'thumb:handakuten']: + 'thumb:fmv_extension', 'thumb:handakuten', + 'show_input_mode_icon']: section, key = self.__get_section_key(name) builder.get_object(name).set_active(prefs.get_value(section, key)) @@ -322,6 +323,9 @@ class AnthySetup(object): else: section = 'common' key = name + if section == 'common': + if name == 'show_input_mode_icon': + key = 'show-input-mode-icon' return (section, key) def __run_message_dialog(self, message, type=Gtk.MessageType.INFO): diff --git a/setup/python2/prefs.py b/setup/python2/prefs.py index 1b88908..9a147ee 100644 --- a/setup/python2/prefs.py +++ b/setup/python2/prefs.py @@ -4,8 +4,8 @@ # # Copyright (c) 2007-2008 Peng Huang # Copyright (c) 2009 Hideaki ABE -# Copyright (c) 2010-2013 Takao Fujiwara -# Copyright (c) 2007-2013 Red Hat, Inc. +# Copyright (c) 2010-2014 Takao Fujiwara +# Copyright (c) 2007-2014 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -145,15 +145,27 @@ class Prefs(object): variant = self._config.get_values(s) for key in variant.keys(): v = variant[key] + # FIXME: ibus-dconf converts the keys. + #if key.find('_') >= 0: + # key = key.replace('_', '-') + if section == 'common': + if key == 'show_input_mode': + key = 'show-input-mode' + elif key == 'show_typing_method': + key = 'show-typing-method' + elif key == 'show_segment_mode': + key = 'show-segment-mode' + elif key == 'show_dict_mode': + key = 'show-dict-mode' + elif key == 'show_dict_config': + key = 'show-dict-config' + elif key == 'show_preferences': + key = 'show-preferences' + elif key == 'show_input_mode_icon': + key = 'show-input-mode-icon' + elif key == 'icon_str_rgba': + key = 'icon-str-rgba' self.modified.setdefault(section, {})[key] = v if v != [''] else [] - # FIXME: ibus-dconf converts the keys. - if section == 'common': - self.fetch_item(section, 'show-input-mode') - self.fetch_item(section, 'show-typing-method') - self.fetch_item(section, 'show-segment-mode') - self.fetch_item(section, 'show-dict-mode') - self.fetch_item(section, 'show-dict-config') - self.fetch_item(section, 'show-preferences') def fetch_item(self, section, key, readonly=False): if self._config == None: diff --git a/setup/python2/setup.ui b/setup/python2/setup.ui index dc5e7e1..edd6cfa 100644 --- a/setup/python2/setup.ui +++ b/setup/python2/setup.ui @@ -346,6 +346,23 @@ + + _Show input mode icon + True + True + False + True + True + + + + + False + False + 1 + + + True 0 @@ -396,7 +413,7 @@ False False - 1 + 2 diff --git a/setup/python3/anthyprefs.py.in b/setup/python3/anthyprefs.py.in index 53c9d1d..b9032f2 100644 --- a/setup/python3/anthyprefs.py.in +++ b/setup/python3/anthyprefs.py.in @@ -355,6 +355,8 @@ _config = { 'show-dict-mode': True, 'show-dict-config': False, 'show-preferences': True, + 'show-input-mode-icon': True, + 'icon-str-rgba': '#41507a', 'period_style': 0, 'symbol_style': 1, diff --git a/setup/python3/main.py b/setup/python3/main.py index 2073f59..f70bc1f 100644 --- a/setup/python3/main.py +++ b/setup/python3/main.py @@ -147,7 +147,8 @@ class AnthySetup(object): 'half_width_symbol', 'half_width_number', 'half_width_space', 'latin_with_shift', 'thumb:keyboard_layout_mode', 'thumb:keyboard_layout', - 'thumb:fmv_extension', 'thumb:handakuten']: + 'thumb:fmv_extension', 'thumb:handakuten', + 'show_input_mode_icon']: section, key = self.__get_section_key(name) builder.get_object(name).set_active(prefs.get_value(section, key)) @@ -325,6 +326,9 @@ class AnthySetup(object): else: section = 'common' key = name + if section == 'common': + if name == 'show_input_mode_icon': + key = 'show-input-mode-icon' return (section, key) def __run_message_dialog(self, message, type=Gtk.MessageType.INFO): diff --git a/setup/python3/prefs.py b/setup/python3/prefs.py index a4af88d..2b3f4ea 100644 --- a/setup/python3/prefs.py +++ b/setup/python3/prefs.py @@ -145,15 +145,27 @@ class Prefs(object): variant = self._config.get_values(s) for key in list(variant.keys()): v = variant[key] + # FIXME: ibus-dconf converts the keys. + #if key.find('_') >= 0: + # key = key.replace('_', '-') + if section == 'common': + if key == 'show_input_mode': + key = 'show-input-mode' + elif key == 'show_typing_method': + key = 'show-typing-method' + elif key == 'show_segment_mode': + key = 'show-segment-mode' + elif key == 'show_dict_mode': + key = 'show-dict-mode' + elif key == 'show_dict_config': + key = 'show-dict-config' + elif key == 'show_preferences': + key = 'show-preferences' + elif key == 'show_input_mode_icon': + key = 'show-input-mode-icon' + elif key == 'icon_str_rgba': + key = 'icon-str-rgba' self.modified.setdefault(section, {})[key] = v if v != [''] else [] - # FIXME: ibus-dconf converts the keys. - if section == 'common': - self.fetch_item(section, 'show-input-mode') - self.fetch_item(section, 'show-typing-method') - self.fetch_item(section, 'show-segment-mode') - self.fetch_item(section, 'show-dict-mode') - self.fetch_item(section, 'show-dict-config') - self.fetch_item(section, 'show-preferences') def fetch_item(self, section, key, readonly=False): if self._config == None: diff --git a/setup/python3/setup.ui b/setup/python3/setup.ui index dc5e7e1..edd6cfa 100644 --- a/setup/python3/setup.ui +++ b/setup/python3/setup.ui @@ -346,6 +346,23 @@ + + _Show input mode icon + True + True + False + True + True + + + + + False + False + 1 + + + True 0 @@ -396,7 +413,7 @@ False False - 1 + 2 -- 1.8.0