def set_add_direct_input(self, mode, update_dconf=True):
'''Set the current value of the “Add direct input” mode
:param mode: Whether “Add direct input” mode is on or off
:type mode: boolean
:param update_dconf: Whether to write the change to dconf.
Set this to False if this method is
called because the dconf key changed
to avoid endless loops when the dconf
key is changed twice in a short time.
:type update_dconf: boolean
'''
imes = self.get_current_imes()
dictionary_names = self.db.hunspell_obj.get_dictionary_names()
self._add_direct_input = mode
if mode:
if 'NoIme' not in imes:
imes.append('NoIme')
if 'en_GB' not in dictionary_names:
dictionary_names.append('en_GB')
else:
imes = [x for x in imes if x != 'NoIme']
if not imes:
imes = ['NoIme']
# always keep the first dictionary, i.e. always keep
# the original one from the config file
dictionary_names = (
[dictionary_names[0]]
+ [x for x in dictionary_names[1:] if x != 'en_GB'])
self.set_dictionary_names(dictionary_names, update_dconf=True)
self.set_current_imes(imes, update_dconf=True)
if update_dconf:
self._config.set_value(
self._config_section,
'adddirectinput',
GLib.Variant.new_boolean(mode))
评论列表
文章目录