diff options
Diffstat (limited to 'extensions/cpsection/keyboard/view.py')
-rw-r--r-- | extensions/cpsection/keyboard/view.py | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/extensions/cpsection/keyboard/view.py b/extensions/cpsection/keyboard/view.py index dd62a85..e349255 100644 --- a/extensions/cpsection/keyboard/view.py +++ b/extensions/cpsection/keyboard/view.py @@ -26,6 +26,7 @@ from sugar.graphics.icon import Icon from jarabe.controlpanel.sectionview import SectionView + CLASS = 'Language' ICON = 'module-keyboard' TITLE = _('Keyboard') @@ -37,6 +38,7 @@ _APPLY_TIMEOUT = 500 # once python-xklavier has been packaged for all major distributions # For more information, see: http://dev.sugarlabs.org/ticket/407 + class LayoutCombo(gtk.HBox): """ @@ -45,8 +47,8 @@ class LayoutCombo(gtk.HBox): """ __gsignals__ = { - 'selection-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_INT)) + 'selection-changed': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING, gobject.TYPE_INT)), } def __init__(self, keyboard_manager, n): @@ -57,7 +59,7 @@ class LayoutCombo(gtk.HBox): self.set_border_width(style.DEFAULT_SPACING) self.set_spacing(style.DEFAULT_SPACING) - label = gtk.Label(' <b>%s</b> ' % str(n+1)) + label = gtk.Label(' <b>%s</b> ' % str(n + 1)) label.set_use_markup(True) label.modify_fg(gtk.STATE_NORMAL, style.COLOR_SELECTION_GREY.get_gdk_color()) @@ -69,7 +71,7 @@ class LayoutCombo(gtk.HBox): for description, name in self._keyboard_manager.get_languages(): self._klang_store.append([name, description]) - self._klang_combo = gtk.ComboBox(model = self._klang_store) + self._klang_combo = gtk.ComboBox(model=self._klang_store) self._klang_combo_changed_id = \ self._klang_combo.connect('changed', self._klang_combo_changed_cb) cell = gtk.CellRendererText() @@ -77,10 +79,10 @@ class LayoutCombo(gtk.HBox): cell.props.ellipsize_set = True self._klang_combo.pack_start(cell) self._klang_combo.add_attribute(cell, 'text', 1) - self.pack_start(self._klang_combo, expand=True, fill = True) + self.pack_start(self._klang_combo, expand=True, fill=True) self._kvariant_store = None - self._kvariant_combo = gtk.ComboBox(model = None) + self._kvariant_combo = gtk.ComboBox(model=None) self._kvariant_combo_changed_id = \ self._kvariant_combo.connect('changed', \ self._kvariant_combo_changed_cb) @@ -89,7 +91,7 @@ class LayoutCombo(gtk.HBox): cell.props.ellipsize_set = True self._kvariant_combo.pack_start(cell) self._kvariant_combo.add_attribute(cell, 'text', 1) - self.pack_start(self._kvariant_combo, expand=True, fill = True) + self.pack_start(self._kvariant_combo, expand=True, fill=True) self._klang_combo.set_active(self._index) @@ -129,7 +131,7 @@ class LayoutCombo(gtk.HBox): model = combobox.get_model() lang = model.get(it, 0)[0] self._set_kvariant_store(lang) - + def _kvariant_combo_changed_cb(self, combobox): it = combobox.get_active_iter() model = combobox.get_model() @@ -145,18 +147,17 @@ class Keyboard(SectionView): self._kmodel = None self._selected_kmodel = None - + self._klayouts = [] self._selected_klayouts = [] - + self._group_switch_option = None self._selected_group_switch_option = None self.set_border_width(style.DEFAULT_SPACING * 2) self.set_spacing(style.DEFAULT_SPACING) - - self._layout_table = gtk.Table(rows = 4, columns = 2, \ - homogeneous = False) + + self._layout_table = gtk.Table(rows=4, columns=2, homogeneous=False) self._keyboard_manager = model.KeyboardManager(self.get_display()) self._layout_combo_list = [] @@ -169,7 +170,7 @@ class Keyboard(SectionView): self._vbox = gtk.VBox() scrollwindow.add_with_viewport(self._vbox) - + self.__kmodel_sid = None self.__layout_sid = None self.__group_switch_sid = None @@ -177,7 +178,7 @@ class Keyboard(SectionView): self._setup_kmodel() self._setup_layouts() self._setup_group_switch_option() - + self._vbox.show() def _setup_kmodel(self): @@ -200,7 +201,7 @@ class Keyboard(SectionView): for description, name in self._keyboard_manager.get_models(): kmodel_store.append([name, description]) - kmodel_combo = gtk.ComboBox(model = kmodel_store) + kmodel_combo = gtk.ComboBox(model=kmodel_store) cell = gtk.CellRendererText() cell.props.ellipsize = pango.ELLIPSIZE_MIDDLE cell.props.ellipsize_set = True @@ -214,7 +215,7 @@ class Keyboard(SectionView): kmodel_combo.set_active_iter(row.iter) break - box_kmodel.pack_start(kmodel_combo, expand = False) + box_kmodel.pack_start(kmodel_combo, expand=False) self._vbox.pack_start(box_kmodel, expand=False) box_kmodel.show_all() @@ -223,7 +224,7 @@ class Keyboard(SectionView): 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_sid = gobject.timeout_add(_APPLY_TIMEOUT, self.__kmodel_timeout_cb, combobox) def __kmodel_timeout_cb(self, combobox): @@ -240,7 +241,8 @@ class Keyboard(SectionView): return False def _setup_group_switch_option(self): - """Adds the controls for changing the group switch option of keyboard""" + """Adds the controls for changing the group switch option of keyboard + """ separator_group_option = gtk.HSeparator() self._vbox.pack_start(separator_group_option, expand=False) separator_group_option.show_all() @@ -259,7 +261,7 @@ class Keyboard(SectionView): for description, name in self._keyboard_manager.get_options_group(): group_option_store.append([name, description]) - group_option_combo = gtk.ComboBox(model = group_option_store) + group_option_combo = gtk.ComboBox(model=group_option_store) cell = gtk.CellRendererText() cell.props.ellipsize = pango.ELLIPSIZE_MIDDLE cell.props.ellipsize_set = True @@ -280,7 +282,7 @@ class Keyboard(SectionView): if not found: group_option_combo.set_active(0) - box_group_option.pack_start(group_option_combo, expand = False) + box_group_option.pack_start(group_option_combo, expand=False) self._vbox.pack_start(box_group_option, expand=False) box_group_option.show_all() @@ -290,7 +292,7 @@ class Keyboard(SectionView): 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_sid = gobject.timeout_add(_APPLY_TIMEOUT, self.__group_switch_timeout_cb, combobox) def __group_switch_timeout_cb(self, combobox): @@ -306,7 +308,6 @@ class Keyboard(SectionView): except Exception: logging.exception('Could not set new keyboard group switch option') - return False def _setup_layouts(self): @@ -324,18 +325,18 @@ class Keyboard(SectionView): for i in range(0, self._keyboard_manager.get_max_layouts()): add_remove_box = self.__create_add_remove_box() self._layout_addremovebox_list.append(add_remove_box) - self._layout_table.attach(add_remove_box, 1, 2, i, i+1) + self._layout_table.attach(add_remove_box, 1, 2, i, i + 1) layout_combo = LayoutCombo(self._keyboard_manager, i) layout_combo.connect('selection-changed', \ self.__layout_combo_selection_changed_cb) self._layout_combo_list.append(layout_combo) - self._layout_table.attach(layout_combo, 0, 1, i, i+1) + self._layout_table.attach(layout_combo, 0, 1, i, i + 1) if i < len(self._klayouts): layout_combo.show_all() layout_combo.select_layout(self._klayouts[i]) - + self._vbox.pack_start(self._layout_table, expand=False) self._layout_table.set_size_request(self._vbox.size_request()[0], -1) self._layout_table.show() @@ -359,15 +360,15 @@ class Keyboard(SectionView): i += 1 def __create_add_remove_box(self): - '''Creates gtk.Hbox with add/remove buttons''' - add_icon = Icon(icon_name='list-add') + """Creates gtk.Hbox with add/remove buttons""" + add_icon = Icon(icon_name='list-add') add_button = gtk.Button() add_button.set_image(add_icon) add_button.connect('clicked', self.__add_button_clicked_cb) - remove_icon = Icon(icon_name='list-remove') + remove_icon = Icon(icon_name='list-remove') remove_button = gtk.Button() remove_button.set_image(remove_icon) remove_button.connect('clicked', @@ -387,7 +388,7 @@ class Keyboard(SectionView): def __add_button_clicked_cb(self, button): self._layout_combo_list[len(self._selected_klayouts)].show_all() self._update_klayouts() - + def __remove_button_clicked_cb(self, button): self._layout_combo_list[len(self._selected_klayouts) - 1].hide() self._update_klayouts() @@ -403,7 +404,7 @@ class Keyboard(SectionView): if self.__layout_sid is not None: gobject.source_remove(self.__layout_sid) - self.__layout_sid = gobject.timeout_add(_APPLY_TIMEOUT, + self.__layout_sid = gobject.timeout_add(_APPLY_TIMEOUT, self.__layout_timeout_cb) def __layout_timeout_cb(self): @@ -417,10 +418,8 @@ class Keyboard(SectionView): return False - def undo(self): """Reverts back to the original keyboard configuration""" self._keyboard_manager.set_model(self._kmodel) self._keyboard_manager.set_layouts(self._klayouts) self._keyboard_manager.set_option_group(self._group_switch_option) - |