Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Enable ibus-setup to show the frequently used languages only in IME l…

…ist.
  • Loading branch information...
commit dffb43ea267713e9ffff52bb3b19c11630df8d19 1 parent f07be51
Takao Fujiwara authored
168 data/ibus-xkb.schemas.in
@@ -88,5 +88,173 @@ se,si,sk,sy,sy(ku),th,tj,tr,ua,uz,vn
88 88 The list is used by ibus-gjs.</long>
89 89 </locale>
90 90 </schema>
  91 + <schema>
  92 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/group_list</key>
  93 + <applyto>/desktop/ibus/general/xkblayoutconfig/group_list</applyto>
  94 + <owner>ibus</owner>
  95 + <type>list</type>
  96 + <list_type>string</list_type>
  97 + <default>[west_europe,south_europe,east_europe,north_europe,west_asia,center_asia,east_asia,india,australia]</default>
  98 + <locale name="C">
  99 + <short>List of system keyboard layout groups on ibus-setup</short>
  100 + <long>The group list is used not to show all the system
  101 + keyboard layouts by default. The list item will be
  102 + appended at the end of gconf key. e.g.
  103 + .../xkblayoutconfig/item1</long>
  104 + </locale>
  105 + </schema>
  106 + <schema>
  107 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/west_europe</key>
  108 + <applyto>/desktop/ibus/general/xkblayoutconfig/west_europe</applyto>
  109 + <owner>ibus</owner>
  110 + <type>list</type>
  111 + <list_type>string</list_type>
  112 + <!--
  113 + <default>[ad,be,br,de,ca,ch,cz,es,fr,gn,hu,ie,ie(CloGaelach),it,latam,nl,pt,si,sk]</default>
  114 + -->
  115 + <default>[ca,cs,de,en,es,fr,gd,hu,it,nl,pt,sk,sl]</default>
  116 + <locale name="C">
  117 + <short>List of European languages on ibus-setup</short>
  118 + <long>ibus-setup shows the languages only in input method list
  119 + when you run ibus-setup on one of the languages.
  120 + Other languages are hidden under an extended button.</long>
  121 + </locale>
  122 + </schema>
  123 + <schema>
  124 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/south_europe</key>
  125 + <applyto>/desktop/ibus/general/xkblayoutconfig/south_europe</applyto>
  126 + <owner>ibus</owner>
  127 + <type>list</type>
  128 + <list_type>string</list_type>
  129 + <!--
  130 + <default>[al,ba,bg,gr,me,mk,mt,ro,rs]</default>
  131 + -->
  132 + <default>[bg,bs,el,mk,mt,ro,sq,sr]</default>
  133 + <locale name="C">
  134 + <short>List of European languages on ibus-setup</short>
  135 + <long>ibus-setup shows the languages only in input method list
  136 + when you run ibus-setup on one of the languages.
  137 + Other languages are hidden under an extended button.</long>
  138 + </locale>
  139 + </schema>
  140 + <schema>
  141 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/east_europe</key>
  142 + <applyto>/desktop/ibus/general/xkblayoutconfig/east_europe</applyto>
  143 + <owner>ibus</owner>
  144 + <type>list</type>
  145 + <list_type>string</list_type>
  146 + <!--
  147 + <default>[by,ee,epo,ge,ge(dsb),ge(ru),ge(os),hr,kg,kz,lt,lv,pl,pl(csb),ru,ru(cv),ru(kom),ru(sah),ru(tt),ru(xal),ua,uz]</default>
  148 + -->
  149 + <default>[be,csb,cv,et,ka,kk,ky,lt,lv,pl,ru,tt,uk,uz]</default>
  150 + <locale name="C">
  151 + <short>List of European languages on ibus-setup</short>
  152 + <long>ibus-setup shows the languages only in input method list
  153 + when you run ibus-setup on one of the languages.
  154 + Other languages are hidden under an extended button.</long>
  155 + </locale>
  156 + </schema>
  157 + <schema>
  158 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/north_europe</key>
  159 + <applyto>/desktop/ibus/general/xkblayoutconfig/north_europe</applyto>
  160 + <owner>ibus</owner>
  161 + <type>list</type>
  162 + <list_type>string</list_type>
  163 + <!--
  164 + <default>[dk,fi,fo,is,no,no(smi),se]</default>
  165 + -->
  166 + <default>[da,fi,fo,is,no,se,sv]</default>
  167 + <locale name="C">
  168 + <short>List of European languages on ibus-setup</short>
  169 + <long>ibus-setup shows the languages only in input method list
  170 + when you run ibus-setup on one of the languages.
  171 + Other languages are hidden under an extended button.</long>
  172 + </locale>
  173 + </schema>
  174 + <schema>
  175 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/west_asia</key>
  176 + <applyto>/desktop/ibus/general/xkblayoutconfig/west_asia</applyto>
  177 + <owner>ibus</owner>
  178 + <type>list</type>
  179 + <list_type>string</list_type>
  180 + <!--
  181 + <default>[am,ara,az,et,gh,gh(akan),gh(ewe),gh(fula),gh(ga),gh(hausa),il,iq,iq(ku),ir,ir(ku),ma,ma(tifinagh),ng,ng(hausa),ng,ng(igbo),ng(yoruba),sy,sy(ku),tj,tr]</default>
  182 + -->
  183 + <default>[am,ar,az,ber,fa,ha,he,hy,ig,ku,tg,tr,yo]</default>
  184 + <locale name="C">
  185 + <short>List of Asian languages on ibus-setup</short>
  186 + <long>ibus-setup shows the languages only in input method list
  187 + when you run ibus-setup on one of the languages.
  188 + Other languages are hidden under an extended button.</long>
  189 + </locale>
  190 + </schema>
  191 + <schema>
  192 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/center_asia</key>
  193 + <applyto>/desktop/ibus/general/xkblayoutconfig/center_asia</applyto>
  194 + <owner>ibus</owner>
  195 + <type>list</type>
  196 + <list_type>string</list_type>
  197 + <!--
  198 + <default>[cn(tib)]</default>
  199 + -->
  200 + <default>[bo,zh]</default>
  201 + <locale name="C">
  202 + <short>List of Asian languages on ibus-setup</short>
  203 + <long>ibus-setup shows the languages only in input method list
  204 + when you run ibus-setup on one of the languages.
  205 + Other languages are hidden under an extended button.</long>
  206 + </locale>
  207 + </schema>
  208 + <schema>
  209 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/east_asia</key>
  210 + <applyto>/desktop/ibus/general/xkblayoutconfig/east_asia</applyto>
  211 + <owner>ibus</owner>
  212 + <type>list</type>
  213 + <list_type>string</list_type>
  214 + <!--
  215 + <default>[bt,kh,la,mal,mm,th,vn]</default>
  216 + -->
  217 + <default>[dz,km,lo,my,th,vi]</default>
  218 + <locale name="C">
  219 + <short>List of Asian languages on ibus-setup</short>
  220 + <long>ibus-setup shows the languages only in input method list
  221 + when you run ibus-setup on one of the languages.
  222 + Other languages are hidden under an extended button.</long>
  223 + </locale>
  224 + </schema>
  225 + <schema>
  226 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/india</key>
  227 + <applyto>/desktop/ibus/general/xkblayoutconfig/india</applyto>
  228 + <owner>ibus</owner>
  229 + <type>list</type>
  230 + <list_type>string</list_type>
  231 + <!--
  232 + <default>[bd,in,in(ben),in(guj),in(guru),in(jhelum),in(kan),in(mal),in(ori),in(tam),in(tel),in(urd-phonetic),in(bolnagri),lk,lk(tam_unicode),mv,np,pk]</default>
  233 + -->
  234 + <default>[bn,dv,gu,hi,kn,ml,ne,or,pa,si,ta,te,ur]</default>
  235 + <locale name="C">
  236 + <short>List of Asian languages on ibus-setup</short>
  237 + <long>ibus-setup shows the languages only in input method list
  238 + when you run ibus-setup on one of the languages.
  239 + Other languages are hidden under an extended button.</long>
  240 + </locale>
  241 + </schema>
  242 + <schema>
  243 + <key>/schemas/desktop/ibus/general/xkblayoutconfig/australia</key>
  244 + <applyto>/desktop/ibus/general/xkblayoutconfig/australia</applyto>
  245 + <owner>ibus</owner>
  246 + <type>list</type>
  247 + <list_type>string</list_type>
  248 + <!--
  249 + <default>[mao]</default>
  250 + -->
  251 + <default>[mi]</default>
  252 + <locale name="C">
  253 + <short>List of Asian languages on ibus-setup</short>
  254 + <long>ibus-setup shows the languages only in input method list
  255 + when you run ibus-setup on one of the languages.
  256 + Other languages are hidden under an extended button.</long>
  257 + </locale>
  258 + </schema>
91 259 </schemalist>
92 260 </gconfschemafile>
155 setup/enginecombobox.py
@@ -46,6 +46,9 @@ def __init__(self):
46 46 self.connect("notify::active", self.__notify_active_cb)
47 47
48 48 self.__model = None
  49 + self.__all_model = None
  50 + self.__config = None
  51 + self.__show_sub_lang = False
49 52
50 53 renderer = Gtk.CellRendererPixbuf()
51 54 renderer.set_property("xalign", 0)
@@ -59,20 +62,51 @@ def __init__(self):
59 62 self.pack_start(renderer, True)
60 63 self.set_cell_data_func(renderer, self.__name_cell_data_cb, None)
61 64
62   - def set_engines(self, engines):
63   - self.__model = Gtk.TreeStore(object)
  65 + def __gconf_get_lang_list_from_locale(self):
  66 + common_list = ['en', 'Other']
  67 + if self.__config == None:
  68 + return None
  69 + loc = None
  70 + try:
  71 + loc = locale.setlocale (locale.LC_ALL)
  72 + except:
  73 + pass
  74 + if loc == None:
  75 + return common_list
  76 + current_lang = IBus.get_language_name(loc)
  77 + if current_lang == None:
  78 + return common_list
  79 + group_list = self.__config.get_value("general/xkblayoutconfig",
  80 + "group_list")
  81 + if group_list == None:
  82 + return [loc] + common_list
  83 + group_list = list(group_list)
  84 + lang_list = None
  85 + for group in group_list:
  86 + group = str(group)
  87 + langs = list(self.__config.get_value("general/xkblayoutconfig",
  88 + group))
  89 + for lang in langs:
  90 + lang = str(lang)
  91 + if current_lang == IBus.get_language_name(lang):
  92 + lang_list = langs
  93 + break
  94 + if lang_list != None:
  95 + break
  96 + if lang_list == None:
  97 + return [loc] + common_list
  98 + return lang_list + common_list
64 99
65   - iter1 = self.__model.append(None)
66   - self.__model.set(iter1, 0, 0)
67   - langs = {}
68   - for e in engines:
69   - l = IBus.get_language_name(e.get_language())
70   - if l == None:
71   - l = ""
72   - if l not in langs:
73   - langs[l] = []
74   - langs[l].append(e)
  100 + def __has_engine_in_lang_list(self, engine, lang_list):
  101 + retval = False
  102 + for lang in lang_list:
  103 + if IBus.get_language_name(lang) == \
  104 + IBus.get_language_name(engine.props.language):
  105 + retval = True
  106 + break
  107 + return retval
75 108
  109 + def __model_append_langs(self, model, langs, visible):
76 110 keys = langs.keys()
77 111 keys.sort(locale.strcoll)
78 112 loc = locale.getlocale()[0]
@@ -90,29 +124,86 @@ def set_engines(self, engines):
90 124 keys.remove(IBus.get_language_name("Other"))
91 125 keys += [IBus.get_language_name("Other")]
92 126 for l in keys:
93   - iter1 = self.__model.append(None)
94   - self.__model.set(iter1, 0, l)
  127 + iter1 = model.append(None)
  128 + model.set(iter1, 0, l)
95 129 def cmp_engine(a, b):
96 130 if a.get_rank() == b.get_rank():
97 131 return locale.strcoll(a.get_longname(), b.get_longname())
98 132 return int(b.get_rank() - a.get_rank())
99 133 langs[l].sort(cmp_engine)
100 134 for e in langs[l]:
101   - iter2 = self.__model.append(iter1)
102   - self.__model.set(iter2, 0, e)
  135 + iter2 = model.append(iter1)
  136 + model.set(iter2, 0, e)
  137 +
  138 + def set_engines(self, engines):
  139 + self.__model = Gtk.TreeStore(object)
  140 +
  141 + iter1 = self.__model.append(None)
  142 + self.__model.set(iter1, 0, 0)
  143 + lang_list = self.__gconf_get_lang_list_from_locale()
  144 + lang = {}
  145 + sub_lang = {}
  146 + for e in engines:
  147 + l = IBus.get_language_name(e.props.language)
  148 + if lang_list == None or \
  149 + self.__has_engine_in_lang_list(e, lang_list):
  150 + if l not in lang:
  151 + lang[l] = []
  152 + lang[l].append(e)
  153 + else:
  154 + if l not in sub_lang:
  155 + sub_lang[l] = []
  156 + sub_lang[l].append(e)
  157 +
  158 + self.__model_append_langs(self.__model, lang, True)
  159 + iter1 = self.__model.append(None)
  160 + self.__model.set(iter1, 0, -1)
  161 +
  162 + self.__all_model = Gtk.TreeStore(object)
  163 + iter1 = self.__all_model.append(None)
  164 + self.__all_model.set(iter1, 0, 0)
  165 + self.__model_append_langs(self.__all_model, lang, False)
  166 + iter1 = self.__all_model.append(None)
  167 + self.__all_model.set(iter1, 0, -1)
  168 + self.__model_append_langs(self.__all_model, sub_lang, False)
  169 +
  170 + self.__toggle_sub_lang()
103 171
104   - self.set_model(self.__model)
  172 + def __toggle_sub_lang(self):
  173 + self.set_model(None)
  174 + if self.__show_sub_lang:
  175 + self.set_model(self.__all_model)
  176 + else:
  177 + self.set_model(self.__model)
105 178 self.set_active(0)
106 179
107 180 def __icon_cell_data_cb(self, celllayout, renderer, model, iter, data):
108   - engine = self.__model.get_value(iter, 0)
  181 + model = self.get_model()
  182 + engine = model.get_value(iter, 0)
109 183
110 184 if isinstance(engine, str) or isinstance (engine, unicode):
111 185 renderer.set_property("visible", False)
112 186 renderer.set_property("sensitive", False)
113 187 elif isinstance(engine, int):
114   - renderer.set_property("visible", False)
115   - renderer.set_property("sensitive", False)
  188 + if engine == 0:
  189 + renderer.set_property("visible", False)
  190 + renderer.set_property("sensitive", False)
  191 + renderer.set_property("pixbuf", None)
  192 + elif engine < 0:
  193 + if not self.__show_sub_lang:
  194 + pixbuf = load_icon("go-bottom", Gtk.IconSize.LARGE_TOOLBAR)
  195 + else:
  196 + pixbuf = load_icon("go-up", Gtk.IconSize.LARGE_TOOLBAR)
  197 + if pixbuf == None:
  198 + pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE,
  199 + Gtk.IconSize.LARGE_TOOLBAR)
  200 + if pixbuf == None:
  201 + renderer.set_property("visible", False)
  202 + renderer.set_property("sensitive", False)
  203 + return
  204 + renderer.set_property("visible", True)
  205 + renderer.set_property("sensitive", True)
  206 + renderer.set_property("pixbuf", pixbuf)
116 207 else:
117 208 renderer.set_property("visible", True)
118 209 renderer.set_property("sensitive", True)
@@ -120,7 +211,8 @@ def __icon_cell_data_cb(self, celllayout, renderer, model, iter, data):
120 211 renderer.set_property("pixbuf", pixbuf)
121 212
122 213 def __name_cell_data_cb(self, celllayout, renderer, model, iter, data):
123   - engine = self.__model.get_value(iter, 0)
  214 + model = self.get_model()
  215 + engine = model.get_value(iter, 0)
124 216
125 217 if isinstance (engine, str) or isinstance (engine, unicode):
126 218 renderer.set_property("sensitive", False)
@@ -128,8 +220,15 @@ def __name_cell_data_cb(self, celllayout, renderer, model, iter, data):
128 220 renderer.set_property("weight", Pango.Weight.NORMAL)
129 221 elif isinstance(engine, int):
130 222 renderer.set_property("sensitive", True)
131   - renderer.set_property("text", _("Select an input method"))
132   - renderer.set_property("weight", Pango.Weight.NORMAL)
  223 + if engine == 0:
  224 + renderer.set_property("text", _("Select an input method"))
  225 + renderer.set_property("weight", Pango.Weight.NORMAL)
  226 + elif engine < 0:
  227 + if not self.__show_sub_lang:
  228 + renderer.set_property("text", _("Show all input methods"))
  229 + else:
  230 + renderer.set_property("text", _("Show only input methods for your region"))
  231 + renderer.set_property("weight", Pango.Weight.BOLD)
133 232 else:
134 233 renderer.set_property("sensitive", True)
135 234 renderer.set_property("text", engine.get_longname())
@@ -145,10 +244,18 @@ def do_get_property(self, property):
145 244 if i == 0 or i == -1:
146 245 return None
147 246 iter = self.get_active_iter()
148   - return self.get_model()[iter][0]
  247 + model = self.get_model()
  248 + if model[iter][0] == -1:
  249 + self.__show_sub_lang = not self.__show_sub_lang
  250 + self.__toggle_sub_lang()
  251 + return None
  252 + return model[iter][0]
149 253 else:
150 254 raise AttributeError, 'unknown property %s' % property.name
151 255
  256 + def set_config(self, config):
  257 + self.__config = config
  258 +
152 259 def get_active_engine(self):
153 260 return self.get_property("active-engine")
154 261
1  setup/main.py
@@ -209,6 +209,7 @@ def __init_general(self):
209 209 # init engine page
210 210 self.__engines = self.__bus.list_engines()
211 211 self.__combobox = self.__builder.get_object("combobox_engines")
  212 + self.__combobox.set_config(self.__config)
212 213 self.__combobox.set_engines(self.__engines)
213 214
214 215 engine_names = values.get("preload_engines", [])

0 comments on commit dffb43e

Please sign in to comment.
Something went wrong with that request. Please try again.