diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2014-01-24 11:11:40 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2014-01-24 11:11:40 +0900 |
commit | 8468de2f165ca7dba45b13cec09fdcde83a88204 (patch) | |
tree | dc6650c0248088a994689f0b1dccd9bece0b94fd | |
parent | 5d94d8cc7b9a322f4639200c4a10076cb57a0294 (diff) |
Enable python3 ibus-setup.
The default uses 'python' and if the path of python 3 is 'python3',
./configure --with-python=python3
Review URL: https://codereview.appspot.com/54930043
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | setup/enginecombobox.py | 25 | ||||
-rw-r--r-- | setup/enginetreeview.py | 13 | ||||
-rw-r--r-- | setup/keyboardshortcut.py | 10 | ||||
-rw-r--r-- | setup/main.py | 21 |
5 files changed, 49 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac index b7ef1ebd..73d99ee1 100644 --- a/configure.ac +++ b/configure.ac @@ -372,6 +372,13 @@ AM_CONDITIONAL([ENABLE_PYTHON_LIBRARY], [test x"$enable_python_library" = x"yes" AM_CONDITIONAL([ENABLE_SETUP], [test x"$enable_setup" = x"yes"]) AM_CONDITIONAL([ENABLE_DAEMON], [true]) +# Define python version +AC_ARG_WITH(python, + AS_HELP_STRING([--with-python[=PATH]], + [Select python2 or python3]), + [PYTHON=$with_python], [] +) + AM_PATH_PYTHON([2.5]) PYGOBJECT_REQUIRED=3.0.0 @@ -598,6 +605,7 @@ Build options: Build shared libs $enable_shared Build static libs $enable_static CFLAGS $CFLAGS + python $PYTHON Gtk2 immodule dir $GTK2_IM_MODULEDIR Gtk3 immodule dir $GTK3_IM_MODULEDIR Build gtk2 immodule $enable_gtk2 diff --git a/setup/enginecombobox.py b/setup/enginecombobox.py index b45ad562..2a2a6777 100644 --- a/setup/enginecombobox.py +++ b/setup/enginecombobox.py @@ -2,8 +2,8 @@ # # ibus - The Input Bus # -# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> -# Copyright (c) 2007-2010 Red Hat, Inc. +# Copyright (c) 2007-2014 Peng Huang <shawn.p.huang@gmail.com> +# Copyright (c) 2007-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,8 @@ # USA import locale +import functools +import sys from gi.repository import GObject from gi.repository import Gtk @@ -72,8 +74,8 @@ class EngineComboBox(Gtk.ComboBox): langs[l] = [] langs[l].append(e) - keys = langs.keys() - keys.sort(locale.strcoll) + keys = list(langs.keys()) + keys.sort(key=functools.cmp_to_key(locale.strcoll)) loc = locale.getlocale()[0] # None on C locale if loc == None: @@ -95,7 +97,7 @@ class EngineComboBox(Gtk.ComboBox): if a.get_rank() == b.get_rank(): return locale.strcoll(a.get_longname(), b.get_longname()) return int(b.get_rank() - a.get_rank()) - langs[l].sort(cmp_engine) + langs[l].sort(key=functools.cmp_to_key(cmp_engine)) for e in langs[l]: iter2 = self.__model.append(iter1) self.__model.set(iter2, 0, e) @@ -106,7 +108,10 @@ class EngineComboBox(Gtk.ComboBox): def __icon_cell_data_cb(self, celllayout, renderer, model, iter, data): engine = self.__model.get_value(iter, 0) - if isinstance(engine, str) or isinstance (engine, unicode): + if isinstance(engine, str): + renderer.set_property("visible", False) + renderer.set_property("sensitive", False) + elif sys.version < '3' and isinstance (engine, unicode): renderer.set_property("visible", False) renderer.set_property("sensitive", False) elif isinstance(engine, int): @@ -121,7 +126,11 @@ class EngineComboBox(Gtk.ComboBox): def __name_cell_data_cb(self, celllayout, renderer, model, iter, data): engine = self.__model.get_value(iter, 0) - if isinstance (engine, str) or isinstance (engine, unicode): + if isinstance (engine, str): + renderer.set_property("sensitive", False) + renderer.set_property("text", engine) + renderer.set_property("weight", Pango.Weight.NORMAL) + elif sys.version < '3' and isinstance (engine, unicode): renderer.set_property("sensitive", False) renderer.set_property("text", engine) renderer.set_property("weight", Pango.Weight.NORMAL) @@ -146,7 +155,7 @@ class EngineComboBox(Gtk.ComboBox): iter = self.get_active_iter() return self.get_model()[iter][0] else: - raise AttributeError, 'unknown property %s' % property.name + raise AttributeError('unknown property %s' % property.name) def get_active_engine(self): return self.get_property("active-engine") diff --git a/setup/enginetreeview.py b/setup/enginetreeview.py index f8ee0920..b116c54f 100644 --- a/setup/enginetreeview.py +++ b/setup/enginetreeview.py @@ -2,8 +2,8 @@ # # ibus - The Input Bus # -# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> -# Copyright (c) 2007-2010 Red Hat, Inc. +# Copyright (c) 2007-2014 Peng Huang <shawn.p.huang@gmail.com> +# Copyright (c) 2007-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -108,7 +108,8 @@ class EngineTreeView(Gtk.TreeView): language_b = IBus.get_language_name(engine_b.get_language()) label_a = "%s - %s" % (language_a, engine_a.get_longname()) label_b = "%s - %s" % (language_b, engine_b.get_longname()) - return cmp(label_a, label_b) + # http://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons + return (label_a > label_b) - (label_a < label_b) def __selection_changed_cb(self, *args): self.notify("active-engine"); @@ -173,15 +174,15 @@ class EngineTreeView(Gtk.TreeView): engines = [ r[0] for r in self.__model if r[0] != None] return engines else: - raise AttributeError, 'unknown property %s' % prop.name + raise AttributeError('unknown property %s' % prop.name) def do_set_property(self, prop, value): if prop.name == "active-engine": - raise AttributeError, "active-engine is readonly" + raise AttributeError("active-engine is readonly") elif prop.name == "engines": set_engines(value) else: - raise AttributeError, 'unknown property %s' % prop.name + raise AttributeError('unknown property %s' % prop.name) def set_engines(self, engines): self.__model.clear() diff --git a/setup/keyboardshortcut.py b/setup/keyboardshortcut.py index 1a885250..26bd77fc 100644 --- a/setup/keyboardshortcut.py +++ b/setup/keyboardshortcut.py @@ -2,8 +2,8 @@ # # ibus - The Input Bus # -# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> -# Copyright (c) 2007-2010 Red Hat, Inc. +# Copyright (c) 2007-2014 Peng Huang <shawn.p.huang@gmail.com> +# Copyright (c) 2007-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -182,7 +182,7 @@ class KeyboardShortcutSelection(Gtk.VBox): modifiers.append(name) if keycode.startswith("_"): keycode = keycode[1:] - shortcut = "".join(map(lambda m: '<' + m + '>', modifiers)) + shortcut = "".join(['<' + m + '>' for m in modifiers]) shortcut += keycode return shortcut @@ -335,6 +335,6 @@ if __name__ == "__main__": Gtk.STOCK_OK, Gtk.ResponseType.OK)) dlg.add_shortcut("Control+Shift+space") dlg.set_shortcuts(None) - print dlg.run() - print dlg.get_shortcuts() + print((dlg.run())) + print((dlg.get_shortcuts())) diff --git a/setup/main.py b/setup/main.py index d3f44142..cac10dec 100644 --- a/setup/main.py +++ b/setup/main.py @@ -2,8 +2,8 @@ # # ibus - The Input Bus # -# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com> -# Copyright (c) 2007-2010 Red Hat, Inc. +# Copyright (c) 2007-2014 Peng Huang <shawn.p.huang@gmail.com> +# Copyright (c) 2007-2014 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,9 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # USA +# for python2 +from __future__ import print_function + import os import signal import sys @@ -45,7 +48,7 @@ from i18n import DOMAINNAME, _, N_, init as i18n_init COLUMN_VISIBLE, COLUMN_ICON, COLUMN_DATA, -) = range(6) +) = list(range(6)) ( DATA_NAME, @@ -57,7 +60,7 @@ from i18n import DOMAINNAME, _, N_, init as i18n_init DATA_EXEC, DATA_STARTED, DATA_PRELOAD -) = range(9) +) = list(range(9)) class Setup(object): def __flush_gtk_events(self): @@ -286,7 +289,7 @@ class Setup(object): obj.set_sensitive(False) if prop.name == "engines": - engine_names = map(lambda e: e.get_name(), engines) + engine_names = [e.get_name() for e in engines] self.__settings_general.set_strv('preload-engines', engine_names) def __button_engine_add_cb(self, button): @@ -306,7 +309,7 @@ class Setup(object): if len(args) == 0: return name = engine.get_name() - if name in self.__engine_setup_exec_list.keys(): + if name in list(self.__engine_setup_exec_list.keys()): try: wpid, sts = os.waitpid(self.__engine_setup_exec_list[name], os.WNOHANG) @@ -402,7 +405,7 @@ class Setup(object): if data[DATA_STARTED] == False: try: self.__bus.register_start_engine(data[DATA_LANG], data[DATA_NAME]) - except Exception, e: + except Exception as e: dlg = Gtk.MessageDialog(type = Gtk.MessageType.ERROR, buttons = Gtk.ButtonsType.CLOSE, message_format = str(e)) @@ -413,7 +416,7 @@ class Setup(object): else: try: self.__bus.register_stop_engine(data[DATA_LANG], data[DATA_NAME]) - except Exception, e: + except Exception as e: dlg = Gtk.MessageDialog(type = Gtk.MessageType.ERROR, buttons = Gtk.ButtonsType.CLOSE, message_format = str(e)) @@ -492,7 +495,7 @@ if __name__ == "__main__": try: locale.setlocale(locale.LC_ALL, '') except locale.Error: - print >> sys.stderr, "Using the fallback 'C' locale" + print("Using the fallback 'C' locale", file=sys.stderr) locale.setlocale(locale.LC_ALL, 'C') i18n_init() |