Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2009-08-16 21:38:07 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2009-08-16 21:38:07 (GMT)
commitc7721cce946a26dd99d945cddee26431b8d3b66a (patch)
tree2eb1c6b08b0e7c747d24f1b428c55daa3a6b744f /extensions
parent2d848947cbcb97b45de16e49153aff70cc58da2c (diff)
Implement *_set() support for model, layout and layout switching option
Diffstat (limited to 'extensions')
-rw-r--r--extensions/cpsection/keyboard/model.py26
-rw-r--r--extensions/cpsection/keyboard/view.py73
2 files changed, 92 insertions, 7 deletions
diff --git a/extensions/cpsection/keyboard/model.py b/extensions/cpsection/keyboard/model.py
index 9828963..9bc90eb 100644
--- a/extensions/cpsection/keyboard/model.py
+++ b/extensions/cpsection/keyboard/model.py
@@ -116,3 +116,29 @@ class XKB(gobject.GObject):
def get_max_layouts(self):
return self._engine.get_max_num_groups()
+
+ def set_model(self, model):
+ #XXX: Which one goes first ?
+ self._gconf_client.set_string(MODEL_KEY, model)
+ self._configrec.set_model(model)
+ self._configrec.activate(self._engine)
+
+ def set_option_grp(self, option_grp):
+ #XXX: Take a backup of existing settings first (there may be other hand set values)
+ options = [option_grp]
+ self._gconf_client.set_list(OPTIONS_KEY, gconf.VALUE_STRING, options)
+ self._configrec.set_options(options)
+ self._configrec.activate(self._engine)
+
+ def set_layouts(self, layouts):
+ self._gconf_client.set_list(LAYOUTS_KEY, gconf.VALUE_STRING, layouts)
+ layouts_list = []
+ variants_list = []
+ for layout in layouts:
+ layouts_list.append(layout.split('(')[0])
+ variants_list.append(layout.split('(')[1][:-1])
+
+ self._configrec.set_layouts(layouts_list)
+ self._configrec.set_variants(variants_list)
+ self._configrec.activate(self._engine)
+
diff --git a/extensions/cpsection/keyboard/view.py b/extensions/cpsection/keyboard/view.py
index 148cec7..2f3f1ed 100644
--- a/extensions/cpsection/keyboard/view.py
+++ b/extensions/cpsection/keyboard/view.py
@@ -29,6 +29,8 @@ CLASS = 'Language'
ICON = 'module-keyboard'
TITLE = _('Keyboard')
+_APPLY_TIMEOUT = 3000
+
class LayoutCombo(gtk.HBox):
__gsignals__ = {
'selection-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
@@ -143,13 +145,13 @@ class Keyboard(SectionView):
self._vbox = gtk.VBox()
scrollwindow.add_with_viewport(self._vbox)
- self._kmodel_sid = None
- self._layout_sid = None
- self._group_switch_option_sid = None
+ self.__kmodel_sid = None
+ self.__layout_sid = None
+ self.__group_switch_sid = None
self._setup_kmodel()
self._setup_layouts()
- self._setup_group_switch_option()
+ self._setup_group_switch_option()
self._vbox.show()
@@ -186,6 +188,27 @@ class Keyboard(SectionView):
self._vbox.pack_start(box_kmodel, expand=False)
box_kmodel.show_all()
+ self._kmodel_combo.connect('changed', self.__kmodel_changed_cb)
+
+ def __kmodel_changed_cb(self, combobox):
+ if self.__kmodel_sid is not None:
+ gobject.source_remove(self.__kmodel_sid)
+ self.__kmodel_sid = gobject.timeout_add(_APPLY_TIMEOUT,
+ self.__kmodel_timeout_cb, combobox)
+
+ def __kmodel_timeout_cb(self, combobox):
+ it = combobox.get_active_iter()
+ model = combobox.get_model()
+ kmodel = model.get(it, 0)[0]
+ if kmodel == self._xkb.get_current_model():
+ return
+ try:
+ self._xkb.set_model(kmodel)
+ except:
+ pass #TODO: Show error
+
+ return False
+
def _setup_group_switch_option(self):
separator_grp_option = gtk.HSeparator()
self._vbox.pack_start(separator_grp_option, expand=False)
@@ -216,7 +239,7 @@ class Keyboard(SectionView):
found = False
for row in self._grp_option_store:
if current_grp_option in row[0]:
- self._kmodel_combo.set_active_iter(row.iter)
+ self._grp_option_combo.set_active_iter(row.iter)
found = True
break
if not found:
@@ -226,6 +249,27 @@ class Keyboard(SectionView):
self._vbox.pack_start(box_grp_option, expand=False)
box_grp_option.show_all()
+ self._grp_option_combo.connect('changed', self.__group_switch_changed_cb)
+
+ def __group_switch_changed_cb(self, combobox):
+ if self.__group_switch_sid is not None:
+ gobject.source_remove(self.__group_switch_sid)
+ self.__group_switch_sid = gobject.timeout_add(_APPLY_TIMEOUT,
+ self.__group_switch_timeout_cb, combobox)
+
+ def __group_switch_timeout_cb(self, combobox):
+ it = combobox.get_active_iter()
+ model = combobox.get_model()
+ group_switch = model.get(it, 0)[0]
+ if group_switch == self._xkb.get_current_option_grp():
+ return
+ try:
+ self._xkb.set_option_grp(group_switch)
+ except:
+ pass #TODO: Show error
+
+ return False
+
def _setup_layouts(self):
separator_klayout = gtk.HSeparator()
self._vbox.pack_start(separator_klayout, expand=False)
@@ -266,11 +310,11 @@ class Keyboard(SectionView):
else:
box.show_all()
if i == 1:
- # First row - no need for showing remove
+ # First row - no need for showing remove btn
add, remove = box.get_children()
remove.props.visible = False
if i == self._xkb.get_max_layouts():
- # Last row - no need for showing add
+ # Last row - no need for showing add btn
add, remove = box.get_children()
add.props.visible = False
i += 1
@@ -317,3 +361,18 @@ class Keyboard(SectionView):
self.__determine_add_remove_box_visibility()
+ if self.__layout_sid is not None:
+ gobject.source_remove(self.__layout_sid)
+ self.__layout_sid = gobject.timeout_add(_APPLY_TIMEOUT,
+ self.__layout_timeout_cb)
+
+ def __layout_timeout_cb(self):
+ if self._selected_klayouts == self._xkb.get_current_layouts():
+ return
+ try:
+ self._xkb.set_layouts(self._selected_klayouts)
+ except:
+ pass #TODO: Show error
+
+ return False
+