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 c7caeaf8dc3aaaf5b1d546ffb418aae52b8905a4 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Wed, 16 Jul 2014 14:57:07 +0900 Subject: [PATCH] Fixed deprecated warnings with python3-gobject 3.13.3. python3-gobject adds several warnings in gi/overrides/Gtk.py /usr/share/ibus-anthy/setup/main.py:1519: PyGTKDeprecationWarning: The "buttons" argument must be a Gtk.ButtonsType enum value. Please use the "add_buttons" method for adding buttons. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations /usr/lib64/python3.4/site-packages/gi/overrides/Gtk.py:537: PyGTKDeprecationWarning: The keyword(s) "parent" have been deprecated in favor of "transient_for" respectively. See: https://wiki.gnome.org/PyGObject/InitializerDeprecations --- setup/python2/main.py | 52 +++++++++++++++++++++++++++++++-------------------- setup/python3/main.py | 52 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/setup/python2/main.py b/setup/python2/main.py index 7c403b8..424e703 100644 --- a/setup/python2/main.py +++ b/setup/python2/main.py @@ -325,11 +325,11 @@ class AnthySetup(object): return (section, key) def __run_message_dialog(self, message, type=Gtk.MessageType.INFO): - dlg = Gtk.MessageDialog(parent=self.__builder.get_object('main'), - flags=Gtk.DialogFlags.MODAL, - message_type=type, - buttons=Gtk.ButtonsType.OK, - message_format=message) + dlg = Gtk.MessageDialog( + transient_for=self.__builder.get_object('main'), + message_type=type, + buttons=Gtk.ButtonsType.OK, + text=message) dlg.run() dlg.destroy() @@ -420,6 +420,7 @@ class AnthySetup(object): for key, value in sorted(rule.items(), \ cmp = self.__japanese_tuple_sort): ls.append(['romaji', key, value]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input Chars")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Output Chars")), @@ -455,6 +456,7 @@ class AnthySetup(object): for key, value in sorted(rule.items(), \ cmp = self.__japanese_tuple_sort): ls.append(['kana', key, value]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input Chars")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Output Chars")), @@ -502,6 +504,7 @@ class AnthySetup(object): for key, value in sorted(rule.items(), \ cmp = self.__japanese_thumb_sort): ls.append(['thumb', key, value[0], value[2], value[1]]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Single")), @@ -582,9 +585,10 @@ class AnthySetup(object): combobox.clear() combobox.disconnect_by_func(self.on_cb_custom_key_table_changed) - def __run_dialog_custom_key_table(self, mode): + def __run_dialog_custom_key_table(self, widget, mode): prefs = self.prefs dlg = self.__builder.get_object('dialog_custom_key_table') + dlg.set_transient_for(widget.get_toplevel()) label = self.__builder.get_object('label_custom_key_table') label_output = self.__builder.get_object('label_output_custom_key') list_labels = [] @@ -1134,6 +1138,7 @@ class AnthySetup(object): Gtk.main_quit() return True dlg = self.__builder.get_object('quit_check') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Confirmation")) dlg.format_secondary_text( _("You are about to close the setup dialog, is that OK?")) @@ -1150,6 +1155,7 @@ class AnthySetup(object): Gtk.main_quit() return True dlg = self.__builder.get_object('quit_check_without_save') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Notice!")) dlg.format_secondary_text( _("You are about to close the setup dialog without saving your changes, is that OK?")) @@ -1225,6 +1231,7 @@ class AnthySetup(object): for w in ['es:checkbutton_ctrl', 'es:checkbutton_alt', 'es:checkbutton_shift']: self.__builder.get_object(w).set_active(False) dlg = self.__builder.get_object('edit_shortcut') + dlg.set_transient_for(widget.get_toplevel()) id = dlg.run() dlg.hide() if id == Gtk.ResponseType.OK: @@ -1245,13 +1252,13 @@ class AnthySetup(object): self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_romaji_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('romaji') + self.__run_dialog_custom_key_table(widget, 'romaji') def on_btn_kana_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('kana') + self.__run_dialog_custom_key_table(widget, 'kana') def on_btn_thumb_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('thumb') + self.__run_dialog_custom_key_table(widget, 'thumb') def on_btn_add_custom_key(self, widget, user_data): prefs = self.prefs @@ -1380,6 +1387,7 @@ class AnthySetup(object): for w in ['es:checkbutton_ctrl', 'es:checkbutton_alt', 'es:checkbutton_shift']: self.__builder.get_object(w).set_active(False) dlg = self.__builder.get_object('edit_shortcut') + dlg.set_transient_for(widget.get_toplevel()) id = dlg.run() dlg.hide() self.__builder.get_object('es:button_add').show() @@ -1414,16 +1422,17 @@ class AnthySetup(object): if Gtk.Buildable.get_name(widget) == 'dict:btn_add': dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"), - parent=self.__builder.get_object('main'), - action=Gtk.FileChooserAction.OPEN, - buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, - _("_Open"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel(), + action=Gtk.FileChooserAction.OPEN) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_Open"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) 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=(_("_Cancel"), Gtk.ResponseType.CANCEL, - _("_OK"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel()) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_OK"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) vbox = self.__builder.get_object('dict:add_extra_vbox') if Gtk.Buildable.get_name(widget) == 'dict:btn_add': @@ -1516,9 +1525,9 @@ class AnthySetup(object): lines = unicode(lines, encoding).encode('utf-8') dlg = Gtk.Dialog(title=_("View Dictionary File"), - parent=self.__builder.get_object('main'), - flags=Gtk.DialogFlags.MODAL, - buttons=(_("_OK"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel()) + buttons=(_("_OK"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) buffer = Gtk.TextBuffer() buffer.set_text (lines) text_view = Gtk.TextView.new_with_buffer(buffer) @@ -1666,6 +1675,7 @@ class AnthySetup(object): def on_es_button_run_input_clicked(self, widget): dlg = self.__builder.get_object('key_input_dialog') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Please press a key (or a key combination)")) dlg.format_secondary_text(_("The dialog will be closed when the key is released")) id = dlg.run() @@ -1686,6 +1696,7 @@ class AnthySetup(object): s = self.__builder.get_object('es:entry').get_text() if not s or not IBus.keyval_from_name(s): dlg = self.__builder.get_object('invalid_keysym') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Invalid keysym")) dlg.format_secondary_text(_("This keysym is not valid")) dlg.run() @@ -1706,6 +1717,7 @@ class AnthySetup(object): s = self.__builder.get_object('es:entry').get_text() if not s or not IBus.keyval_from_name(s): dlg = self.__builder.get_object('invalid_keysym') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Invalid keysym")) dlg.format_secondary_text(_("This keysym is not valid")) dlg.run() diff --git a/setup/python3/main.py b/setup/python3/main.py index 2073f59..e1ca22e 100644 --- a/setup/python3/main.py +++ b/setup/python3/main.py @@ -328,11 +328,11 @@ class AnthySetup(object): return (section, key) def __run_message_dialog(self, message, type=Gtk.MessageType.INFO): - dlg = Gtk.MessageDialog(parent=self.__builder.get_object('main'), - flags=Gtk.DialogFlags.MODAL, - message_type=type, - buttons=Gtk.ButtonsType.OK, - message_format=message) + dlg = Gtk.MessageDialog( + transient_for=self.__builder.get_object('main'), + message_type=type, + buttons=Gtk.ButtonsType.OK, + text=message) dlg.run() dlg.destroy() @@ -425,6 +425,7 @@ class AnthySetup(object): for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_tuple_sort)): ls.append(['romaji', key, value]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input Chars")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Output Chars")), @@ -460,6 +461,7 @@ class AnthySetup(object): for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_tuple_sort)): ls.append(['kana', key, value]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input Chars")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Output Chars")), @@ -507,6 +509,7 @@ class AnthySetup(object): for key, value in sorted(list(rule.items()), \ key = functools.cmp_to_key(self.__japanese_thumb_sort)): ls.append(['thumb', key, value[0], value[2], value[1]]) + tv.set_model(None) tv.append_column(Gtk.TreeViewColumn(_(_("Input")), Gtk.CellRendererText(), text=1)) tv.append_column(Gtk.TreeViewColumn(_(_("Single")), @@ -587,9 +590,10 @@ class AnthySetup(object): combobox.clear() combobox.disconnect_by_func(self.on_cb_custom_key_table_changed) - def __run_dialog_custom_key_table(self, mode): + def __run_dialog_custom_key_table(self, widget, mode): prefs = self.prefs dlg = self.__builder.get_object('dialog_custom_key_table') + dlg.set_transient_for(widget.get_toplevel()) label = self.__builder.get_object('label_custom_key_table') label_output = self.__builder.get_object('label_output_custom_key') list_labels = [] @@ -1128,6 +1132,7 @@ class AnthySetup(object): Gtk.main_quit() return True dlg = self.__builder.get_object('quit_check') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Confirmation")) dlg.format_secondary_text( _("You are about to close the setup dialog, is that OK?")) @@ -1144,6 +1149,7 @@ class AnthySetup(object): Gtk.main_quit() return True dlg = self.__builder.get_object('quit_check_without_save') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Notice!")) dlg.format_secondary_text( _("You are about to close the setup dialog without saving your changes, is that OK?")) @@ -1219,6 +1225,7 @@ class AnthySetup(object): for w in ['es:checkbutton_ctrl', 'es:checkbutton_alt', 'es:checkbutton_shift']: self.__builder.get_object(w).set_active(False) dlg = self.__builder.get_object('edit_shortcut') + dlg.set_transient_for(widget.get_toplevel()) id = dlg.run() dlg.hide() if id == Gtk.ResponseType.OK: @@ -1239,13 +1246,13 @@ class AnthySetup(object): self.__builder.get_object('btn_apply').set_sensitive(True) def on_btn_romaji_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('romaji') + self.__run_dialog_custom_key_table(widget, 'romaji') def on_btn_kana_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('kana') + self.__run_dialog_custom_key_table(widget, 'kana') def on_btn_thumb_custom_table_clicked(self, widget): - self.__run_dialog_custom_key_table('thumb') + self.__run_dialog_custom_key_table(widget, 'thumb') def on_btn_add_custom_key(self, widget, user_data): prefs = self.prefs @@ -1374,6 +1381,7 @@ class AnthySetup(object): for w in ['es:checkbutton_ctrl', 'es:checkbutton_alt', 'es:checkbutton_shift']: self.__builder.get_object(w).set_active(False) dlg = self.__builder.get_object('edit_shortcut') + dlg.set_transient_for(widget.get_toplevel()) id = dlg.run() dlg.hide() self.__builder.get_object('es:button_add').show() @@ -1408,16 +1416,17 @@ class AnthySetup(object): if Gtk.Buildable.get_name(widget) == 'dict:btn_add': dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"), - parent=self.__builder.get_object('main'), - action=Gtk.FileChooserAction.OPEN, - buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, - _("_Open"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel(), + action=Gtk.FileChooserAction.OPEN) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_Open"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) 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=(_("_Cancel"), Gtk.ResponseType.CANCEL, - _("_OK"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel()) + buttons=(_("_Cancel"), Gtk.ResponseType.CANCEL, + _("_OK"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) vbox = self.__builder.get_object('dict:add_extra_vbox') if Gtk.Buildable.get_name(widget) == 'dict:btn_add': @@ -1510,9 +1519,9 @@ class AnthySetup(object): lines = str(lines, encoding) dlg = Gtk.Dialog(title=_("View Dictionary File"), - parent=self.__builder.get_object('main'), - flags=Gtk.DialogFlags.MODAL, - buttons=(_("_OK"), Gtk.ResponseType.OK)) + transient_for=widget.get_toplevel()) + buttons=(_("_OK"), Gtk.ResponseType.OK) + dlg.add_buttons(*buttons) buffer = Gtk.TextBuffer() buffer.set_text (lines) text_view = Gtk.TextView.new_with_buffer(buffer) @@ -1660,6 +1669,7 @@ class AnthySetup(object): def on_es_button_run_input_clicked(self, widget): dlg = self.__builder.get_object('key_input_dialog') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Please press a key (or a key combination)")) dlg.format_secondary_text(_("The dialog will be closed when the key is released")) id = dlg.run() @@ -1680,6 +1690,7 @@ class AnthySetup(object): s = self.__builder.get_object('es:entry').get_text() if not s or not IBus.keyval_from_name(s): dlg = self.__builder.get_object('invalid_keysym') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Invalid keysym")) dlg.format_secondary_text(_("This keysym is not valid")) dlg.run() @@ -1700,6 +1711,7 @@ class AnthySetup(object): s = self.__builder.get_object('es:entry').get_text() if not s or not IBus.keyval_from_name(s): dlg = self.__builder.get_object('invalid_keysym') + dlg.set_transient_for(widget.get_toplevel()) dlg.set_markup('%s' % _("Invalid keysym")) dlg.format_secondary_text(_("This keysym is not valid")) dlg.run() -- 1.8.5.3 From 981c40b4a8cf42ffde07dcf5925539f337461f61 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Thu, 10 Jul 2014 17:13:49 +0900 Subject: [PATCH] Set max-width-chars property in ibus-anthy-setup wrapped GtkLabel. --- setup/python2/setup.ui | 1 + setup/python3/setup.ui | 1 + 2 files changed, 2 insertions(+) diff --git a/setup/python2/setup.ui b/setup/python2/setup.ui index dc5e7e1..b6d8ef2 100644 --- a/setup/python2/setup.ui +++ b/setup/python2/setup.ui @@ -1469,6 +1469,7 @@ True 0 True + 74 You do not have to reconfigure the system keyboard layout for "Additional Key Arrangement" since this option changes input method layout only in case input method is turned on. You do not have to reconfigure XKB since this option changes IM layout only with IM on. diff --git a/setup/python3/setup.ui b/setup/python3/setup.ui index dc5e7e1..b6d8ef2 100644 --- a/setup/python3/setup.ui +++ b/setup/python3/setup.ui @@ -1469,6 +1469,7 @@ True 0 True + 74 You do not have to reconfigure the system keyboard layout for "Additional Key Arrangement" since this option changes input method layout only in case input method is turned on. You do not have to reconfigure XKB since this option changes IM layout only with IM on. -- 1.8.5.3 From a1e5f1ce7b87a37cab7ba458ad2343fc20056f47 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Fri, 11 Jul 2014 12:11:53 +0900 Subject: [PATCH] Set a parent window from 'IBUS_SETUP_XID' environment variable in setup. --- setup/python2/main.py | 25 ++++++++++++++++++++----- setup/python3/main.py | 25 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/setup/python2/main.py b/setup/python2/main.py index 5df1cdd..cdfdc4d 100644 --- a/setup/python2/main.py +++ b/setup/python2/main.py @@ -82,22 +82,37 @@ class AnthySetup(object): builder.add_from_file(builder_file) toplevel = builder.get_object('main') + parent_xid = 0 + parent_wmname = None + parent_wmclass = None try: - gnome_control_center_xid = int(environ['GNOME_CONTROL_CENTER_XID']) + parent_xid = int(environ['IBUS_SETUP_XID']) + if parent_xid != 0: + parent_wmname = 'ibus-setup' + parent_wmclass = 'Ibus-setup' except: - gnome_control_center_xid = 0 + pass + + try: + if parent_xid == 0: + parent_xid = int(environ['GNOME_CONTROL_CENTER_XID']) + if parent_xid != 0: + parent_wmname = 'gnome-conrol-center' + parent_wmclass = 'Gnome-conrol-center' + except: + pass - if gnome_control_center_xid != 0: + if parent_xid != 0: def set_transient(obj, pspec): window = toplevel.get_window() if window == None: return parent_window = GdkX11.X11Window.foreign_new_for_display(Gdk.Display.get_default(), - gnome_control_center_xid) + parent_xid) if parent_window != None: window.set_transient_for(parent_window) - toplevel.set_wmclass('gnome-control-center', 'Gnome-control-center') + toplevel.set_wmclass(parent_wmname, parent_wmclass) toplevel.set_modal(True) toplevel.set_type_hint(Gdk.WindowTypeHint.DIALOG) toplevel.connect('notify::window', set_transient) diff --git a/setup/python3/main.py b/setup/python3/main.py index 8921402..3141bb8 100644 --- a/setup/python3/main.py +++ b/setup/python3/main.py @@ -85,22 +85,37 @@ class AnthySetup(object): builder.add_from_file(builder_file) toplevel = builder.get_object('main') + parent_xid = 0 + parent_wmname = None + parent_wmclass = None try: - gnome_control_center_xid = int(environ['GNOME_CONTROL_CENTER_XID']) + parent_xid = int(environ['IBUS_SETUP_XID']) + if parent_xid != 0: + parent_wmname = 'ibus-setup' + parent_wmclass = 'Ibus-setup' except: - gnome_control_center_xid = 0 + pass + + try: + if parent_xid == 0: + parent_xid = int(environ['GNOME_CONTROL_CENTER_XID']) + if parent_xid != 0: + parent_wmname = 'gnome-conrol-center' + parent_wmclass = 'Gnome-conrol-center' + except: + pass - if gnome_control_center_xid != 0: + if parent_xid != 0: def set_transient(obj, pspec): window = toplevel.get_window() if window == None: return parent_window = GdkX11.X11Window.foreign_new_for_display(Gdk.Display.get_default(), - gnome_control_center_xid) + parent_xid) if parent_window != None: window.set_transient_for(parent_window) - toplevel.set_wmclass('gnome-control-center', 'Gnome-control-center') + toplevel.set_wmclass(parent_wmname, parent_wmclass) toplevel.set_modal(True) toplevel.set_type_hint(Gdk.WindowTypeHint.DIALOG) toplevel.connect('notify::window', set_transient) -- 1.8.5.3 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 From c13d52a823ee2b084e57bde3859ead64f94bd437 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Mon, 21 Apr 2014 17:05:19 +0900 Subject: [PATCH] Fix to unref pixbuf when propery icon is unrefed. --- engine/python2/engine.py | 1 + engine/python2/propertyicon.py | 6 ++++++ engine/python3/engine.py | 1 + engine/python3/propertyicon.py | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/engine/python2/engine.py b/engine/python2/engine.py index c7a6fb3..68a4b48 100644 --- a/engine/python2/engine.py +++ b/engine/python2/engine.py @@ -1104,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.clear() self.__input_mode_icon = None def __join_all_segments(self): diff --git a/engine/python2/propertyicon.py b/engine/python2/propertyicon.py index fa5f34f..437e94c 100644 --- a/engine/python2/propertyicon.py +++ b/engine/python2/propertyicon.py @@ -76,6 +76,12 @@ class PropertyIcon(Gtk.StatusIcon): self.__xkb_icon_pixbufs[symbol] = pixbuf return pixbuf + def clear(self): + self.set_from_icon_name('') + self.set_visible(False) + self.__xkb_icon_pixbufs = {} + self.__xkb_icon_rgba = None + def set_from_symbol(self, symbol): pixbuf = self.__create_icon_pixbuf_with_string(symbol) self.set_from_pixbuf(pixbuf) diff --git a/engine/python3/engine.py b/engine/python3/engine.py index 6563087..67370d8 100644 --- a/engine/python3/engine.py +++ b/engine/python3/engine.py @@ -1099,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.clear() self.__input_mode_icon = None def __join_all_segments(self): diff --git a/engine/python3/propertyicon.py b/engine/python3/propertyicon.py index fa5f34f..437e94c 100644 --- a/engine/python3/propertyicon.py +++ b/engine/python3/propertyicon.py @@ -76,6 +76,12 @@ class PropertyIcon(Gtk.StatusIcon): self.__xkb_icon_pixbufs[symbol] = pixbuf return pixbuf + def clear(self): + self.set_from_icon_name('') + self.set_visible(False) + self.__xkb_icon_pixbufs = {} + self.__xkb_icon_rgba = None + def set_from_symbol(self, symbol): pixbuf = self.__create_icon_pixbuf_with_string(symbol) self.set_from_pixbuf(pixbuf) -- 1.8.5.3 From b852cfb6061259e4fd7198e3a2579b4495e15ecd Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Mon, 19 May 2014 12:01:22 +0900 Subject: [PATCH] Fix None object has clear() in input mode icon. (#1097364) --- engine/python2/engine.py | 3 ++- engine/python3/engine.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/engine/python2/engine.py b/engine/python2/engine.py index 68a4b48..68e898b 100644 --- a/engine/python2/engine.py +++ b/engine/python2/engine.py @@ -1104,7 +1104,8 @@ 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.clear() + if self.__input_mode_icon != None: + self.__input_mode_icon.clear() self.__input_mode_icon = None def __join_all_segments(self): diff --git a/engine/python3/engine.py b/engine/python3/engine.py index 67370d8..517a64a 100644 --- a/engine/python3/engine.py +++ b/engine/python3/engine.py @@ -1099,7 +1099,8 @@ 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.clear() + if self.__input_mode_icon != None: + self.__input_mode_icon.clear() self.__input_mode_icon = None def __join_all_segments(self): -- 1.8.5.3