We need to store layouts as their names because that is the way how they are identified in kickstarts, libxklavier and libgnomekbd. On the other hand, we need to display layouts in a more user-friendly way. --- pyanaconda/ui/gui/spokes/keyboard.py | 40 +++++++++++++++++++++++---------- pyanaconda/ui/gui/spokes/keyboard.ui | 6 ++-- pyanaconda/xklavier.py | 13 +++++------ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py index 0230203..f2d471c 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.py +++ b/pyanaconda/ui/gui/spokes/keyboard.py @@ -34,6 +34,10 @@ from pyanaconda import xklavier __all__ = ["KeyboardSpoke"] +def _show_layout(column, renderer, model, itr, wrapper): + value = wrapper.name_to_show_str[model[itr][0]] + renderer.set_property("text", value) + class AddLayoutDialog(UIObject): builderObjects = ["addLayoutDialog", "newLayoutStore", "newLayoutStoreFilter"] mainWidgetName = "addLayoutDialog" @@ -44,7 +48,8 @@ class AddLayoutDialog(UIObject): UIObject.__init__(self, *args) def matches_entry(self, model, itr, user_data=None): - value = model.get_value(itr, 0) + value = model[itr][0] + value = self._xkl_wrapper.name_to_show_str[value] entry_text = self._entry.get_text() if entry_text is not None: entry_text = entry_text.lower() @@ -68,6 +73,13 @@ class AddLayoutDialog(UIObject): self._entry.grab_focus() def initialize(self): + # We want to store layouts' names but show layouts as + # 'language (description)'. + layoutColumn = self.builder.get_object("newLayoutColumn") + layoutRenderer = self.builder.get_object("newLayoutRenderer") + layoutColumn.set_cell_data_func(layoutRenderer, _show_layout, + self._xkl_wrapper) + self._store = self.builder.get_object("newLayoutStore") for layout in self._xkl_wrapper.get_available_layouts(): self._addLayout(self._store, layout) @@ -131,15 +143,22 @@ class KeyboardSpoke(NormalSpoke): @property def status(self): # We don't need to check that self._store is empty, because that isn't allowed. - return self._store[0][0] + return self._xkl_wrapper.name_to_show_str[self._store[0][0]] def initialize(self): NormalSpoke.initialize(self) + # We want to store layouts' names but show layouts as + # 'language (description)'. + layoutColumn = self.builder.get_object("layoutColumn") + layoutRenderer = self.builder.get_object("layoutRenderer") + layoutColumn.set_cell_data_func(layoutRenderer, _show_layout, + self._xkl_wrapper) + self._store = self.builder.get_object("addedLayoutStore") - self._addLayout(self._store, "English (US)") - self._addLayout(self._store, "Irish") - self._addLayout(self._store, "English (US, with some other stuff)") + self._addLayout(self._store, "us") + self._addLayout(self._store, "ie") + self._addLayout(self._store, "cz (qwerty)") def refresh(self): NormalSpoke.refresh(self) @@ -245,17 +264,13 @@ class KeyboardSpoke(NormalSpoke): def on_preview_clicked(self, button): selection = self.builder.get_object("layoutSelection") (store, cur) = selection.get_selected() - layout_description = store[cur] - if not layout_description: - return - - layout_name = self._xkl_wrapper.description_to_name.get(layout_description[0], None) - if not layout_name: + layout_row = store[cur] + if not layout_row: return dialog = Gkbd.KeyboardDrawing.dialog_new() Gkbd.KeyboardDrawing.dialog_set_layout(dialog, self._xkl_wrapper.configreg, - layout_name) + layout_row[0]) with enlightbox(self.window, dialog): dialog.show_all() dialog.run() @@ -290,3 +305,4 @@ class KeyboardSpoke(NormalSpoke): else: self._upButton.set_sensitive(True) self._downButton.set_sensitive(True) + diff --git a/pyanaconda/ui/gui/spokes/keyboard.ui b/pyanaconda/ui/gui/spokes/keyboard.ui index 7b8382b..ce732a5 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.ui +++ b/pyanaconda/ui/gui/spokes/keyboard.ui @@ -116,7 +116,7 @@ </object> </child> <child> - <object class="GtkTreeViewColumn" id="name"> + <object class="GtkTreeViewColumn" id="newLayoutColumn"> <property name="title" translatable="yes">Name</property> <property name="expand">True</property> <property name="sort_column_id">0</property> @@ -257,13 +257,13 @@ any layout to the top of the list to select it as the default.</property> </object> </child> <child> - <object class="GtkTreeViewColumn" id="name1"> + <object class="GtkTreeViewColumn" id="layoutColumn"> <property name="title" translatable="yes">name</property> <property name="expand">True</property> <property name="clickable">True</property> <property name="sort_column_id">0</property> <child> - <object class="GtkCellRendererText" id="nameRenderer"/> + <object class="GtkCellRendererText" id="layoutRenderer"/> <attributes> <attribute name="text">0</attribute> </attributes> diff --git a/pyanaconda/xklavier.py b/pyanaconda/xklavier.py index d461705..0e4af17 100755 --- a/pyanaconda/xklavier.py +++ b/pyanaconda/xklavier.py @@ -65,14 +65,13 @@ class XklWrapper(object): self._language_keyboard_variants = dict() self._country_keyboard_variants = dict() - #we want to display layouts' descriptions, but - #Gkbd.KeyboardDrawingDialog.set_layout needs a layout's name - self.description_to_name = dict() + #we want to display layouts as 'language (description)' + self.name_to_show_str = dict() #this might take quite a long time self.configreg.foreach_language(self._get_language_variants, None) - def _get_variant(self, c_reg, item, subitem, user_data=None): + def _get_variant(self, c_reg, item, subitem, dest): if subitem: name = item_str(item.name) + " (" + item_str(subitem.name) + ")" description = item_str(subitem.description) @@ -80,7 +79,7 @@ class XklWrapper(object): name = item_str(item.name) description = item_str(item.description) - self.description_to_name[description] = name + self.name_to_show_str[name] = "%s (%s)" % (dest.encode("utf-8"), description.encode("utf-8")) self._variants_list.append(_Layout(name, description)) def _get_language_variants(self, c_reg, item, user_data=None): @@ -88,7 +87,7 @@ class XklWrapper(object): self._variants_list = list() lang_name, lang_desc = item_str(item.name), item_str(item.description) - c_reg.foreach_language_variant(lang_name, self._get_variant, None) + c_reg.foreach_language_variant(lang_name, self._get_variant, lang_desc) self._language_keyboard_variants[(lang_name, lang_desc)] = self._variants_list @@ -106,5 +105,5 @@ class XklWrapper(object): for (lang_name, lang_desc), variants in sorted(self._language_keyboard_variants.items()): for layout in variants: - yield "%s (%s)" % (lang_desc.encode("utf-8"), layout.description.encode("utf-8")) + yield layout.name -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list