Created
December 12, 2013 14:16
-
-
Save yangyingchao/7928574 to your computer and use it in GitHub Desktop.
Patch to make ibus-sunpinyin work on gnome-3.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/wrapper/ibus/SConstruct b/wrapper/ibus/SConstruct | |
index bff27fb..41ca8d4 100644 | |
--- a/wrapper/ibus/SConstruct | |
+++ b/wrapper/ibus/SConstruct | |
@@ -40,9 +40,10 @@ def PassVariables(envvar, env): | |
env[y] = os.environ[x] | |
env = Environment(ENV=os.environ, | |
- CFLAGS=cflags, CXXFLAGS=cflags, | |
+ CFLAGS=cflags, CXXFLAGS=cflags, | |
CPPPATH=['.'], | |
tools=['default', 'textfile']) | |
+env['PYTHON']=os.environ.get('EPYTHON') | |
opts.Update(env) | |
if GetOption('prefix') is not None: | |
@@ -51,6 +52,7 @@ if GetOption('prefix') is not None: | |
env['LIBEXECDIR'] = env['PREFIX'] + '/lib/' | |
env['DATADIR'] = env['PREFIX'] + '/share/' | |
+ | |
if GetOption('libdir') is not None: | |
env['LIBDIR'] = GetOption('libdir') | |
@@ -129,6 +131,7 @@ sub = {'@LIBEXEC_DIR@': bin_dir, | |
'@DATA_DIR@' : data_dir, | |
'@ICON_DIR@': icons_dir, | |
'@VERSION@' : version, | |
+ '@PYTHON@' : env['PYTHON'], | |
'@INSTALL_PREFIX@': env['PREFIX']} | |
env.Substfile('data/sunpinyin.xml.in', SUBST_DICT=sub) | |
env.Substfile('setup/config.py.in', SUBST_DICT=sub) | |
@@ -138,11 +141,11 @@ env.Substfile('setup/ibus-setup-sunpinyin.in', SUBST_DICT=sub) | |
#==============================install================================ | |
# | |
def DoInstall(): | |
- libexec_target = env.Install(bin_dir, ['ibus-engine-sunpinyin', | |
+ libexec_target = env.Install(bin_dir, ['ibus-engine-sunpinyin', | |
'setup/ibus-setup-sunpinyin']) | |
for exec_bin in libexec_target: | |
env.AddPostAction(exec_bin, Chmod(str(exec_bin), 0755)) | |
- | |
+ | |
setup_target = env.Install(data_dir + '/setup', | |
['setup/setup.xml', | |
'setup/main.py', | |
diff --git a/wrapper/ibus/setup/ibus-setup-sunpinyin.in b/wrapper/ibus/setup/ibus-setup-sunpinyin.in | |
old mode 100644 | |
new mode 100755 | |
index 2d32738..023d196 | |
--- a/wrapper/ibus/setup/ibus-setup-sunpinyin.in | |
+++ b/wrapper/ibus/setup/ibus-setup-sunpinyin.in | |
@@ -4,4 +4,4 @@ prefix=@INSTALL_PREFIX@ | |
exec_prefix=${prefix} | |
export IBUS_PREFIX=${prefix} | |
export IBUS_LOCALEDIR=${prefix}/share/locale | |
-exec python @DATA_DIR@/setup/main.py $@ | |
+exec @PYTHON@ @DATA_DIR@/setup/main.py $@ | |
diff --git a/wrapper/ibus/setup/main.py b/wrapper/ibus/setup/main.py | |
index 4179a91..78e9e92 100644 | |
--- a/wrapper/ibus/setup/main.py | |
+++ b/wrapper/ibus/setup/main.py | |
@@ -1,5 +1,5 @@ | |
# -*- coding: utf-8 -*- | |
-# | |
+# | |
# Copyright (c) 2009 Leo Zheng <zym361@gmail.com>, Kov Chai <tchaikov@gmail.com> | |
# * | |
# The contents of this file are subject to the terms of either the GNU Lesser | |
@@ -7,12 +7,12 @@ | |
# Distribution License ("CDDL")(collectively, the "License"). You may not use this | |
# file except in compliance with the License. You can obtain a copy of the CDDL at | |
# http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at | |
-# http://www.opensource.org/licenses/lgpl-license.php. See the License for the | |
+# http://www.opensource.org/licenses/lgpl-license.php. See the License for the | |
# specific language governing permissions and limitations under the License. When | |
# distributing the software, include this License Header Notice in each file and | |
# include the full text of the License in the License file as well as the | |
# following notice: | |
-# | |
+# | |
# NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE | |
# (CDDL) | |
# For Covered Software in this distribution, this License shall be governed by the | |
@@ -20,9 +20,9 @@ | |
# Any litigation relating to this License shall be subject to the jurisdiction of | |
# the Federal Courts of the Northern District of California and the state courts | |
# of the State of California, with venue lying in Santa Clara County, California. | |
-# | |
+# | |
# Contributor(s): | |
-# | |
+# | |
# If you wish your version of this file to be governed by only the CDDL or only | |
# the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to | |
# include this software in this distribution under the [CDDL or LGPL Version 2.1] | |
@@ -31,14 +31,15 @@ | |
# Version 2.1, or to extend the choice of license to its licensees as provided | |
# above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL | |
# Version 2 license, then the option applies only if the new code is made subject | |
-# to such option by the copyright holder. | |
+# to such option by the copyright holder. | |
# | |
import sys | |
import os | |
+from gi.repository import GLib | |
+from gi.repository import Gtk as gtk | |
+from gi.repository import IBus as ibus | |
from os import path | |
-import gtk | |
-import ibus | |
import gettext | |
import locale | |
@@ -52,27 +53,34 @@ class Logger: | |
@staticmethod | |
def pr(message): | |
print >> sys.stderr, message | |
- | |
+ | |
class Option(object): | |
"""Option serves as an interface of ibus.config | |
it is used to synchronize the configuration with setting on user interface | |
""" | |
config = ibus.Bus().get_config() | |
- | |
+ | |
def __init__(self, name, default): | |
self.name = name | |
self.default = default | |
- | |
+ | |
def read(self): | |
section, key = self.__get_config_name() | |
return self.config.get_value(section, key, self.default) | |
def write(self, v): | |
section, key = self.__get_config_name() | |
- return self.config.set_value(section, key, type(self.default)(v)) | |
+ if isinstance(self.default, int): | |
+ va = GLib.Variant.new_int32(v) | |
+ elif isinstance(self.default, str): | |
+ va = GLib.Variant.new_string(v); | |
+ else: | |
+ va = None | |
+ return self.config.set_value(section, key, va) | |
+ | |
+ | |
- | |
def __get_config_name(self): | |
keys = self.name.rsplit(SEPARATOR ,1) | |
if len(keys) == 2: | |
@@ -96,7 +104,7 @@ class TrivalOption(Option): | |
def init(self): | |
pass | |
- | |
+ | |
def read_config(self): | |
"""update user inferface with ibus.config | |
""" | |
@@ -106,13 +114,13 @@ class TrivalOption(Option): | |
def write_config(self): | |
v = self.save_ui_setting() | |
self.write(v) | |
- | |
+ | |
def save_ui_setting(self): | |
"""save user interface settings into self.v | |
""" | |
self.v = self.__get_value() | |
return self.v | |
- | |
+ | |
def is_changed(self): | |
return self.v != self.__get_value() | |
@@ -124,10 +132,10 @@ class TrivalOption(Option): | |
def __set_value(self, v): | |
try: | |
- self.widget.set_value(v) | |
+ self.widget.set_value(v.get_int32()) | |
except: | |
- self.widget.set_active(v) | |
- | |
+ self.widget.set_active(v.get_int32()) | |
+ | |
class CheckBoxOption(TrivalOption): | |
def __init__(self, name, default, owner): | |
super(CheckBoxOption, self).__init__(name, default, owner) | |
@@ -140,7 +148,7 @@ class ComboBoxOption(TrivalOption): | |
default = options.index(default) | |
super(ComboBoxOption, self).__init__(name, default, owner) | |
self.options = options | |
- | |
+ | |
def init(self): | |
model = gtk.ListStore(str) | |
for v in self.options: | |
@@ -156,7 +164,7 @@ class ComboBoxOption(TrivalOption): | |
except ValueError: | |
# otherwise save its index | |
return active | |
- | |
+ | |
def __set_value(self, v): | |
try: | |
# if the options are just numbers, we treat 'self.v' as the literal | |
@@ -166,7 +174,7 @@ class ComboBoxOption(TrivalOption): | |
except ValueError: | |
active = v | |
self.widget.set_active(active) | |
- | |
+ | |
class RadioOption(Option): | |
"""option represented using multiple Raidio buttons | |
""" | |
@@ -177,10 +185,10 @@ class RadioOption(Option): | |
def init_ui(self): | |
self.read_config() | |
- | |
+ | |
def read_config(self): | |
self.v = self.read() | |
- name = SEPARATOR.join([self.name, self.v]) | |
+ name = SEPARATOR.join([self.name, "".join(self.v.get_string())]) | |
button = self.xml.get_object(name) | |
assert button is not None, "button: %r not found" % name | |
button.set_active(True) | |
@@ -200,7 +208,7 @@ class MappingInfo: | |
def __init__(self, name, mapping): | |
self.name = name | |
self.mapping = mapping | |
- | |
+ | |
class MappingOption(object): | |
"""an option which presents some sort of mapping, e.g. fuzzy pinyin mapping | |
@@ -211,7 +219,7 @@ class MappingOption(object): | |
self.name = name | |
self.widget = owner.get_object(name) | |
self.mappings = mappings | |
- | |
+ | |
def get_mappings(self): | |
if self.widget.get_active(): | |
return [':'.join(self.mappings)] | |
@@ -223,18 +231,18 @@ class MappingOption(object): | |
def get_active(self): | |
return self.widget.get_active() | |
- | |
+ | |
is_enabled = property(get_active, set_active) | |
def key(self): | |
return self.mappings[0] | |
- | |
+ | |
class MultiMappingOption(Option): | |
def __init__(self, name, options, default=[]): | |
Option.__init__(self, name, default) | |
self.options = options | |
self.saved_pairs = default | |
- | |
+ | |
def read_config(self): | |
if not self.saved_pairs: | |
self.saved_pairs = self.read() | |
@@ -242,24 +250,24 @@ class MultiMappingOption(Option): | |
for opt in self.options: | |
opt.is_enabled = (opt.key() in keys) | |
# throw away unknown pair | |
- | |
+ | |
def write_config(self): | |
# ignore empty settings | |
if self.saved_pairs: | |
self.write(self.saved_pairs) | |
- | |
+ | |
def save_ui_setting(self): | |
self.saved_pairs = sum([opt.get_mappings() for opt in self.options | |
if opt.is_enabled], []) | |
return self.saved_pairs | |
- | |
+ | |
def set_active_all(self, enabled): | |
for opt in self.options: | |
opt.is_enabled = enabled | |
- | |
+ | |
class MultiCheckDialog (object): | |
""" a modal dialog box with 'choose all' and 'choose none' button | |
- | |
+ | |
TODO: another option is to use radio button | |
""" | |
def __init__ (self, ui_name, config_name, mappings, option_klass=MappingOption): | |
@@ -269,12 +277,12 @@ class MultiCheckDialog (object): | |
self.option_klass = option_klass | |
self.saved_settings = [] | |
self.mapping_options = None | |
- | |
+ | |
def get_setup_name(self): | |
"""assuming the name of dialog looks like 'dlg_fuzzy_setup' | |
""" | |
return '_'.join(['dlg', self.ui_name, 'setup']) | |
- | |
+ | |
def __init_ui(self): | |
dlg_name = self.get_setup_name() | |
self.__xml = gtk.Builder() | |
@@ -287,7 +295,7 @@ class MultiCheckDialog (object): | |
'_'.join(["on", self.ui_name, "cancel_clicked"]) : self.on_button_cancel_clicked} | |
self.__xml.connect_signals(handlers) | |
- options = [self.option_klass(m.name, m.mapping, self.__xml) | |
+ options = [self.option_klass(m.name, m.mapping, self.__xml) | |
for m in self.mappings] | |
self.mapping_options = MultiMappingOption(self.config_name, options, self.saved_settings) | |
@@ -298,15 +306,15 @@ class MultiCheckDialog (object): | |
pass | |
init_ui = read_config = dummy | |
- | |
+ | |
def run(self): | |
self.__init_ui() | |
self.__read_config() | |
self.__dlg.run() | |
- | |
+ | |
def __read_config(self): | |
self.mapping_options.read_config() | |
- | |
+ | |
def __save_ui_settings(self): | |
"""save to in-memory storage, will flush to config if not canceled in main_window | |
""" | |
@@ -315,20 +323,20 @@ class MultiCheckDialog (object): | |
def write_config(self): | |
if self.mapping_options is not None: | |
self.mapping_options.write_config() | |
- | |
+ | |
def on_button_check_all_clicked(self, button): | |
self.mapping_options.set_active_all(True) | |
- | |
+ | |
def on_button_uncheck_all_clicked(self, button): | |
self.mapping_options.set_active_all(False) | |
- | |
+ | |
def on_button_ok_clicked(self, button): | |
"""update given options with settings in UI, these settings will be | |
written to config if user push 'OK' or 'Apply' in the main window | |
""" | |
self.__save_ui_settings() | |
self.__dlg.destroy() | |
- | |
+ | |
def on_button_cancel_clicked(self, button): | |
self.__dlg.destroy() | |
@@ -353,7 +361,7 @@ class FuzzySetupDialog (MultiCheckDialog): | |
ui_name = 'fuzzy', | |
config_name = 'QuanPin/Fuzzy/Pinyins', | |
mappings = mappings) | |
- | |
+ | |
class CorrectionSetupDialog (MultiCheckDialog): | |
def __init__(self): | |
mappings = [MappingInfo('QuanPin/AutoCorrection/GnNg', ('gn','ng')), | |
@@ -374,7 +382,7 @@ class PunctMapping(MappingOption): | |
self.init_keys_values(mappings) | |
else: | |
self.widget.set_sensitive(False) | |
- | |
+ | |
def init_keys_values(self, mappings): | |
self.keys = [m[0] for m in mappings] | |
values_with_closing = [v or k for k, v in mappings] | |
@@ -412,7 +420,7 @@ class PunctMapping(MappingOption): | |
self.widget.set_active(enabled) | |
is_enabled = property(MappingOption.get_active, set_active) | |
- | |
+ | |
def key(self): | |
for k, v in self.mappings: | |
if v is not None: | |
@@ -460,13 +468,13 @@ class MainWindow(): | |
def __init__ (self): | |
self.__bus = ibus.Bus() | |
self.__config = self.__bus.get_config() | |
- | |
- | |
+ | |
+ | |
def run(self): | |
self.__init_ui("main_window") | |
self.__read_config() | |
gtk.main() | |
- | |
+ | |
def __init_ui(self, name): | |
self.__init_gettext() | |
xml_file = path.join(path.dirname(__file__), XML_FILE) | |
@@ -488,19 +496,19 @@ class MainWindow(): | |
self.__fuzzy_setup = FuzzySetupDialog() | |
self.__correction_setup = CorrectionSetupDialog() | |
self.__punctmapping_setup = PunctMappingSetupDialog() | |
- | |
+ | |
self.__options = [ | |
TrivalOption("General/MemoryPower", 3, self.__xml), | |
TrivalOption("General/PageSize", 10, self.__xml), | |
TrivalOption("General/MaxBest", 1, self.__xml), | |
TrivalOption("General/MaxTailCandidate", 0, self.__xml), | |
- | |
+ | |
RadioOption("General/InitialStatus/Mode", 'Chinese', ['Chinese', 'English'], self.__xml), | |
RadioOption("General/InitialStatus/Punct", 'Full', ['Full', 'Half'], self.__xml), | |
RadioOption("General/InitialStatus/Letter", 'Half', ['Full', 'Half'], self.__xml), | |
RadioOption("General/Charset", 'GBK', ['GB2312', 'GBK', 'GB18030'], self.__xml), | |
CheckBoxOption("General/PunctMapping/Enabled", False, self.__xml), | |
- | |
+ | |
RadioOption("Keyboard/ModeSwitch", 'Shift', ['Shift', 'Control'], self.__xml), | |
RadioOption("Keyboard/PunctSwitch", 'None', ['ControlComma', | |
'ControlPeriod', | |
@@ -510,7 +518,7 @@ class MainWindow(): | |
CheckBoxOption("Keyboard/Page/CommaPeriod", False, self.__xml), | |
CheckBoxOption("Keyboard/CancelBackspace", True, self.__xml), | |
CheckBoxOption("Keyboard/SmartPunct", True, self.__xml), | |
- | |
+ | |
RadioOption("Pinyin/Scheme", 'QuanPin', ['QuanPin', 'ShuangPin'], self.__xml), | |
ComboBoxOption("Pinyin/ShuangPinType", 'MS2003', ['MS2003', | |
'ABC', | |
@@ -522,7 +530,7 @@ class MainWindow(): | |
CheckBoxOption("QuanPin/AutoCorrection/Enabled", False, self.__xml), | |
CheckBoxOption("QuanPin/FuzzySegs/Enabled", False, self.__xml), | |
CheckBoxOption("QuanPin/InnerFuzzy/Enabled", False, self.__xml), | |
- | |
+ | |
self.__fuzzy_setup, | |
self.__correction_setup, | |
self.__punctmapping_setup, | |
@@ -534,7 +542,7 @@ class MainWindow(): | |
return opt | |
else: | |
return None | |
- | |
+ | |
def __read_config(self): | |
for opt in self.__options: | |
opt.init_ui() | |
@@ -543,7 +551,7 @@ class MainWindow(): | |
self.on_chk_correction_enabled_toggled(None) | |
self.on_chk_punctmapping_enabled_toggled(None) | |
self.on_radio_shuangpin_toggled(None) | |
- | |
+ | |
def __write_config(self): | |
for opt in self.__options: | |
opt.write_config() | |
@@ -563,14 +571,14 @@ class MainWindow(): | |
enabled = radio.get_active() | |
combo = self.__xml.get_object("Pinyin/ShuangPinType") | |
combo.set_sensitive(enabled) | |
- | |
+ | |
def on_chk_fuzzy_enabled_toggled(self, button): | |
self.__update_enabling_button("QuanPin/Fuzzy/Enabled", | |
"button_fuzzy_setup") | |
- | |
+ | |
def on_button_fuzzy_setup_clicked(self, button): | |
self.__fuzzy_setup.run() | |
- | |
+ | |
def on_chk_correction_enabled_toggled(self, button): | |
self.__update_enabling_button("QuanPin/AutoCorrection/Enabled", | |
"button_correction_setup") | |
@@ -581,18 +589,18 @@ class MainWindow(): | |
def on_button_correction_setup_clicked(self, button): | |
self.__correction_setup.run() | |
- | |
+ | |
def on_chk_punctmapping_enabled_toggled(self, button): | |
self.__update_enabling_button("General/PunctMapping/Enabled", | |
"button_punctmapping_setup") | |
- | |
+ | |
def on_button_punctmapping_setup_clicked(self, button): | |
self.__punctmapping_setup.run() | |
- | |
+ | |
def on_main_ok_clicked(self, button): | |
self.__write_config() | |
self.__quit() | |
- | |
+ | |
def on_main_apply_clicked(self, button): | |
self.__write_config() | |
@@ -601,7 +609,7 @@ class MainWindow(): | |
def __quit(self): | |
gtk.main_quit() | |
- | |
+ | |
if __name__ == "__main__": | |
MainWindow().run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment