From 6c5b4f197afde5185c23ed725eecb36da43507e6 Mon Sep 17 00:00:00 2001 From: fujiwarat Date: Tue, 14 Jan 2014 15:30:54 +0900 Subject: [PATCH] Enable ibus-setup to show the frequently used languages only in IME list. --- data/ibus.schemas.in | 168 ++++++++++++++++++++++++++++++++++++++++++++++++ setup/enginecombobox.py | 148 +++++++++++++++++++++++++++++++++++------- 2 files changed, 292 insertions(+), 24 deletions(-) diff --git a/data/ibus.schemas.in b/data/ibus.schemas.in index 28d2219..0600133 100644 --- a/data/ibus.schemas.in +++ b/data/ibus.schemas.in @@ -351,6 +351,174 @@ se,si,sk,sy,sy(ku),th,tj,tr,ua,uz,vn + /schemas/desktop/ibus/general/xkblayoutconfig/group_list + /desktop/ibus/general/xkblayoutconfig/group_list + ibus + list + string + [west_europe,south_europe,east_europe,north_europe,west_asia,center_asia,east_asia,india,australia] + + List of system keyboard layout groups on ibus-setup + The group list is used not to show all the system + keyboard layouts by default. The list item will be + appended at the end of gconf key. e.g. + .../xkblayoutconfig/item1 + + + + /schemas/desktop/ibus/general/xkblayoutconfig/west_europe + /desktop/ibus/general/xkblayoutconfig/west_europe + ibus + list + string + + [ca,cs,de,en,es,fr,gd,hu,it,nl,pt,sk,sl] + + List of European languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/south_europe + /desktop/ibus/general/xkblayoutconfig/south_europe + ibus + list + string + + [bg,bs,el,mk,mt,ro,sq,sr] + + List of European languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/east_europe + /desktop/ibus/general/xkblayoutconfig/east_europe + ibus + list + string + + [be,csb,cv,et,ka,kk,ky,lt,lv,pl,ru,tt,uk,uz] + + List of European languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/north_europe + /desktop/ibus/general/xkblayoutconfig/north_europe + ibus + list + string + + [da,fi,fo,is,no,se,sv] + + List of European languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/west_asia + /desktop/ibus/general/xkblayoutconfig/west_asia + ibus + list + string + + [am,ar,az,ber,fa,ha,he,hy,ig,ku,tg,tr,yo] + + List of Asian languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/center_asia + /desktop/ibus/general/xkblayoutconfig/center_asia + ibus + list + string + + [bo,zh] + + List of Asian languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/east_asia + /desktop/ibus/general/xkblayoutconfig/east_asia + ibus + list + string + + [dz,km,lo,my,th,vi] + + List of Asian languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/india + /desktop/ibus/general/xkblayoutconfig/india + ibus + list + string + + [bn,dv,gu,hi,kn,ml,ne,or,pa,si,ta,te,ur] + + List of Asian languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + + /schemas/desktop/ibus/general/xkblayoutconfig/australia + /desktop/ibus/general/xkblayoutconfig/australia + ibus + list + string + + [mi] + + List of Asian languages on ibus-setup + ibus-setup shows the languages only in input method list + when you run ibus-setup on one of the languages. + Other languages are hidden under an extended button. + + + /schemas/desktop/ibus/panel/custom_font /desktop/ibus/panel/custom_font ibus diff --git a/setup/enginecombobox.py b/setup/enginecombobox.py index b45ad56..830f0e8 100644 --- a/setup/enginecombobox.py +++ b/setup/enginecombobox.py @@ -22,6 +22,7 @@ import locale +from gi.repository import Gio from gi.repository import GObject from gi.repository import Gtk from gi.repository import IBus @@ -45,6 +46,10 @@ class EngineComboBox(Gtk.ComboBox): self.connect("notify::active", self.__notify_active_cb) self.__model = None + self.__all_model = None + self.__show_sub_lang = False + self.__settings_xkblayoutconfig = Gio.Settings( + "org.freedesktop.ibus.general.xkblayoutconfig"); renderer = Gtk.CellRendererPixbuf() renderer.set_property("xalign", 0) @@ -58,20 +63,45 @@ class EngineComboBox(Gtk.ComboBox): self.pack_start(renderer, True) self.set_cell_data_func(renderer, self.__name_cell_data_cb, None) - def set_engines(self, engines): - self.__model = Gtk.TreeStore(object) + def __gconf_get_lang_list_from_locale(self): + common_list = ['en', 'Other'] + loc = None + try: + loc = locale.setlocale (locale.LC_ALL) + except: + pass + if loc == None: + return common_list + current_lang = IBus.get_language_name(loc) + if current_lang == None: + return common_list + group_list = self.__settings_xkblayoutconfig.get_strv('group-list') + if len(group_list) == 0: + return [loc] + common_list + lang_list = None + for group in group_list: + group = group.replace('_', '-') + langs = self.__settings_xkblayoutconfig.get_strv(group) + for lang in langs: + if current_lang == IBus.get_language_name(lang): + lang_list = langs + break + if lang_list != None: + break + if lang_list == None: + return [loc] + common_list + return lang_list + common_list - iter1 = self.__model.append(None) - self.__model.set(iter1, 0, 0) - langs = {} - for e in engines: - l = IBus.get_language_name(e.get_language()) - if l == None: - l = "" - if l not in langs: - langs[l] = [] - langs[l].append(e) + def __has_engine_in_lang_list(self, engine, lang_list): + retval = False + for lang in lang_list: + if IBus.get_language_name(lang) == \ + IBus.get_language_name(engine.props.language): + retval = True + break + return retval + def __model_append_langs(self, model, langs, visible): keys = langs.keys() keys.sort(locale.strcoll) loc = locale.getlocale()[0] @@ -89,29 +119,86 @@ class EngineComboBox(Gtk.ComboBox): keys.remove(IBus.get_language_name("Other")) keys += [IBus.get_language_name("Other")] for l in keys: - iter1 = self.__model.append(None) - self.__model.set(iter1, 0, l) + iter1 = model.append(None) + model.set(iter1, 0, l) def cmp_engine(a, b): 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) for e in langs[l]: - iter2 = self.__model.append(iter1) - self.__model.set(iter2, 0, e) + iter2 = model.append(iter1) + model.set(iter2, 0, e) + + def set_engines(self, engines): + self.__model = Gtk.TreeStore(object) - self.set_model(self.__model) + iter1 = self.__model.append(None) + self.__model.set(iter1, 0, 0) + lang_list = self.__gconf_get_lang_list_from_locale() + lang = {} + sub_lang = {} + for e in engines: + l = IBus.get_language_name(e.props.language) + if lang_list == None or \ + self.__has_engine_in_lang_list(e, lang_list): + if l not in lang: + lang[l] = [] + lang[l].append(e) + else: + if l not in sub_lang: + sub_lang[l] = [] + sub_lang[l].append(e) + + self.__model_append_langs(self.__model, lang, True) + iter1 = self.__model.append(None) + self.__model.set(iter1, 0, -1) + + self.__all_model = Gtk.TreeStore(object) + iter1 = self.__all_model.append(None) + self.__all_model.set(iter1, 0, 0) + self.__model_append_langs(self.__all_model, lang, False) + iter1 = self.__all_model.append(None) + self.__all_model.set(iter1, 0, -1) + self.__model_append_langs(self.__all_model, sub_lang, False) + + self.__toggle_sub_lang() + + def __toggle_sub_lang(self): + self.set_model(None) + if self.__show_sub_lang: + self.set_model(self.__all_model) + else: + self.set_model(self.__model) self.set_active(0) def __icon_cell_data_cb(self, celllayout, renderer, model, iter, data): - engine = self.__model.get_value(iter, 0) + model = self.get_model() + engine = model.get_value(iter, 0) if isinstance(engine, str) or isinstance (engine, unicode): renderer.set_property("visible", False) renderer.set_property("sensitive", False) elif isinstance(engine, int): - renderer.set_property("visible", False) - renderer.set_property("sensitive", False) + if engine == 0: + renderer.set_property("visible", False) + renderer.set_property("sensitive", False) + renderer.set_property("pixbuf", None) + elif engine < 0: + if not self.__show_sub_lang: + pixbuf = load_icon("go-bottom", Gtk.IconSize.LARGE_TOOLBAR) + else: + pixbuf = load_icon("go-up", Gtk.IconSize.LARGE_TOOLBAR) + if pixbuf == None: + pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE, + Gtk.IconSize.LARGE_TOOLBAR) + if pixbuf == None: + renderer.set_property("visible", False) + renderer.set_property("sensitive", False) + return + renderer.set_property("visible", True) + renderer.set_property("sensitive", True) + renderer.set_property("pixbuf", pixbuf) else: renderer.set_property("visible", True) renderer.set_property("sensitive", True) @@ -119,7 +206,8 @@ class EngineComboBox(Gtk.ComboBox): renderer.set_property("pixbuf", pixbuf) def __name_cell_data_cb(self, celllayout, renderer, model, iter, data): - engine = self.__model.get_value(iter, 0) + model = self.get_model() + engine = model.get_value(iter, 0) if isinstance (engine, str) or isinstance (engine, unicode): renderer.set_property("sensitive", False) @@ -127,8 +215,15 @@ class EngineComboBox(Gtk.ComboBox): renderer.set_property("weight", Pango.Weight.NORMAL) elif isinstance(engine, int): renderer.set_property("sensitive", True) - renderer.set_property("text", _("Select an input method")) - renderer.set_property("weight", Pango.Weight.NORMAL) + if engine == 0: + renderer.set_property("text", _("Select an input method")) + renderer.set_property("weight", Pango.Weight.NORMAL) + elif engine < 0: + if not self.__show_sub_lang: + renderer.set_property("text", _("Show all input methods")) + else: + renderer.set_property("text", _("Show only input methods for your region")) + renderer.set_property("weight", Pango.Weight.BOLD) else: renderer.set_property("sensitive", True) renderer.set_property("text", engine.get_longname()) @@ -144,7 +239,12 @@ class EngineComboBox(Gtk.ComboBox): if i == 0 or i == -1: return None iter = self.get_active_iter() - return self.get_model()[iter][0] + model = self.get_model() + if model[iter][0] == -1: + self.__show_sub_lang = not self.__show_sub_lang + self.__toggle_sub_lang() + return None + return model[iter][0] else: raise AttributeError, 'unknown property %s' % property.name -- 1.8.0